Skip to content
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

Merged
merged 9 commits into from
Apr 23, 2024

Conversation

zucchini-nlp
Copy link
Member

What does this PR do?

Not all decoder-only language models support passing "inputs_embeds" currently. I believe for consistency we can add a possibility. However this PR does not do anything for multimodal LLMs, as those are much more complicated sometimes and there may be no reasons for passing "inputs_embeds" manually.

@zucchini-nlp zucchini-nlp requested a review from gante April 16, 2024 13:04
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@gante gante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General question: does this aid the VLM side of the lib? If so, nice :D If not, then I would recommend to not spend time here, and let users add PRs as they need it :)

Comment on lines 1372 to 1373
inputs_embeds = self.embed_tokens(input)
inputs_embeds = inputs_embeds * self.embed_scale
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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 🤗

Copy link
Member Author

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 and input_embeds. Then the better decision if to disable totally inputs embeds for these models. Okay, will do

@gante
Copy link
Member

gante commented Apr 22, 2024

(CI failing due to hub timeouts, I consider it to be equivalent to all green)

@gante gante requested a review from amyeroberts April 22, 2024 09:56
Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding!

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()}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting - what's the reason for needing to add .contiguous here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much of a reason right now, as it is part of compile compatibilty. Decided to leave in case these models will be reworked for compile also

@zucchini-nlp
Copy link
Member Author

Comments are addressed and test passing, so merging now

@zucchini-nlp zucchini-nlp merged commit 408453b into huggingface:main Apr 23, 2024
19 checks passed
itazap pushed a commit that referenced this pull request May 14, 2024
* Add inputs embeds in generation

* always scale embeds

* fix-copies

* fix failing test

* fix copies once more

* remove embeds for models with scaling

* second try to revert

* codestyle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants