Improve greedy search memory usage#32895
Merged
gante merged 1 commit intohuggingface:mainfrom Aug 22, 2024
Merged
Conversation
|
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. |
Contributor
Contributor
Author
|
CI failed but it doesn't seem to be related to this PR |
zucchini-nlp
approved these changes
Aug 21, 2024
Member
zucchini-nlp
left a comment
There was a problem hiding this comment.
Wow, interesting finding! Thanks for handling
gante
approved these changes
Aug 21, 2024
Contributor
gante
left a comment
There was a problem hiding this comment.
Thank you for the fix 🙏
(CI is failing for reasons of our knowledge, will take care of rebasing and merging when the root cause is fixed cc @amyeroberts )
amyeroberts
approved these changes
Aug 22, 2024
Contributor
amyeroberts
left a comment
There was a problem hiding this comment.
Thanks to adding this improvement!
c0169a1 to
77d8384
Compare
77d8384 to
23f74a1
Compare
BernardZach
pushed a commit
to BernardZach/transformers
that referenced
this pull request
Dec 5, 2024
Do not call torch.repeat_interleave if expand_size is 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
When doing greedy search, inputs go through
_expand_inputs_for_generationhere where they are expanded (see here). As the expand size is always 1 in the case of greedy search,torch.repeat_interleavedo not modify the inputs. However, it does increase the memory usage as the input totorch.repeat_interleaveis cloned.Here is a code snippet to check this behaviour:
which returns
Thus, if the expand size is 1, we can return the model inputs before calling
torch.repeat_interleave. That's the change introduced in this PR.More context in this Slack thread: https://huggingface.slack.com/archives/C01N44FJDHT/p1723827436938589
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.