# Question about greedy\_search

**URL:** <https://discuss.huggingface.co/t/question-about-greedy-search/5749>\
**Category:** 🤗Transformers\
**Created:** [April 25, 2021, 2:29pm UTC](https://discuss.huggingface.co/t/question-about-greedy-search/5749 "2021-04-25T14:29:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![seongmin](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@seongmin](https://discuss.huggingface.co/u/seongmin)\
**Post date:** [April 25, 2021, 2:29pm UTC](https://discuss.huggingface.co/t/question-about-greedy-search/5749/1 "2021-04-25T14:29:32Z")

</div>

Hello. I am trying to `greedy_search` with `T5ModelForConditionalGeneration`.

However, it seems I have to provide `input_ids` as both the `input_ids` parameter and as part of `model_kwargs` parameter of the `greedy_search`.

The `input_ids` argument of `greedy_search` acts as the initial decoded state, while `input_ids` that is supposed to appear in `model_kwargs` is passed to `self` (T5) for inference.

I do not see a way to pass two `input_ids` argument to the `greedy_search` function. Right now the function complains that I don’t pass `input_ids` to its internal T5.

How would I go about using the `greedy_search` function fot `T5`?

---

<div class="post-metadata">

**Author:** ![seongmin](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@seongmin](https://discuss.huggingface.co/u/seongmin)\
**Post date:** [April 26, 2021, 1:17am UTC](https://discuss.huggingface.co/t/question-about-greedy-search/5749/2 "2021-04-26T01:17:04Z")

</div>

Solved by passing `encoder_outputs` to `greedy_seach`.

---

<div class="post-metadata">

**Author:** ![reubenwong97](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@reubenwong97](https://discuss.huggingface.co/u/reubenwong97)\
**Post date:** [June 18, 2021, 4:11am UTC](https://discuss.huggingface.co/t/question-about-greedy-search/5749/3 "2021-06-18T04:11:47Z")

</div>

Hi seongmin, I am facing the same issue currently but I am not sure what to do. Would you have a code sample to share on how you managed to pass the `encoder_outputs` to `greedy_search`? Thank you.

---

<div class="post-metadata">

**Author:** ![seongmin](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@seongmin](https://discuss.huggingface.co/u/seongmin)\
**Post date:** [June 18, 2021, 4:31am UTC](https://discuss.huggingface.co/t/question-about-greedy-search/5749/4 "2021-06-18T04:31:41Z")

</div>

Hi Reuben.

While I can’t share the exact code because I don’t own it, here’s the gist of what I did:

```auto
model = T5ForConditionalGeneration(...)
encoder_outputs = model.encoder(encoder_input_ids, return_dict=True, output_hidden_states=True)
decoder_input_ids = torch.tensor([t5config.starter_token_id])
generated = model.greedy_search(decoder_input_ids, encoder_outputs=encoder_outputs)

```

---

<div class="post-metadata">

**Author:** ![reubenwong97](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@reubenwong97](https://discuss.huggingface.co/u/reubenwong97)\
**Post date:** [June 18, 2021, 5:14am UTC](https://discuss.huggingface.co/t/question-about-greedy-search/5749/5 "2021-06-18T05:14:03Z")

</div>

Hi @seongmin ,

That was immensely helpful thank you so much! Have a great day 😃
