-
Notifications
You must be signed in to change notification settings - Fork 27.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add inputs embeds in generation #30269
Changes from 5 commits
9d7baad
2cb27f9
9403e62
7205edc
3b03b8c
258ddc2
6ff5f4d
06014c6
8b1046d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1658,7 +1658,7 @@ def forward( | |
) | ||
|
||
def prepare_inputs_for_generation( | ||
self, input_ids, past_key_values=None, attention_mask=None, use_cache=None, **kwargs | ||
self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, use_cache=None, **kwargs | ||
): | ||
# if model is used as a decoder in encoder-decoder model, the decoder attention mask is created on the fly | ||
if attention_mask is None: | ||
|
@@ -1676,12 +1676,19 @@ def prepare_inputs_for_generation( | |
|
||
input_ids = input_ids[:, remove_prefix_length:] | ||
# first step, decoder_cached_states are empty | ||
return { | ||
"input_ids": input_ids, # encoder_outputs is defined. input_ids not needed | ||
"attention_mask": attention_mask, | ||
"past_key_values": past_key_values, | ||
"use_cache": use_cache, | ||
} | ||
if inputs_embeds is not None and past_key_values is None: | ||
model_inputs = {"inputs_embeds": inputs_embeds} | ||
else: | ||
model_inputs = {"input_ids": input_ids.contiguous()} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting - what's the reason for needing to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not much of a reason right now, as it is part of |
||
|
||
model_inputs.update( | ||
{ | ||
"attention_mask": attention_mask, | ||
"past_key_values": past_key_values, | ||
"use_cache": use_cache, | ||
} | ||
) | ||
return model_inputs | ||
|
||
@staticmethod | ||
def _reorder_cache(past_key_values, beam_idx): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we change this -- it is a breaking change; the same
inputs_embeds
input will yield a different output after this PR on a well-established model.Does it solve any problem from the VLM side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, afaik these models are not used as backbones in VLMs, so prob no real benefit for now.
Close the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zucchini-nlp We can keep the PR, it's useful! Not a priority, but since it's done let's add it :D
Let's just revert this line 🤗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm that will make fail tests for equivalence between
input_ids
andinput_embeds
. Then the better decision if to disable totally inputs embeds for these models. Okay, will do