-
Notifications
You must be signed in to change notification settings - Fork 27.7k
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
Generate: remove near-duplicate sample/greedy copy #30773
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. |
logger.warning_once( | ||
"Calling `._greedy_search()` directly is deprecated and will be removed in v4.42. Use `._sample()` " | ||
"instead, passing the same arguments." | ||
) | ||
return self._sample( | ||
input_ids=input_ids, | ||
logits_processor=logits_processor, | ||
stopping_criteria=stopping_criteria, | ||
generation_config=generation_config, | ||
synced_gpus=synced_gpus, | ||
streamer=streamer, | ||
**model_kwargs, | ||
) |
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.
There is no hard need for deprecations (these are private fns), but I know they are used in other internal libraries -- this should make the transition smoother!
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.
great cleanup!
next_token_scores, max(2, 1 + n_eos_tokens) * num_beams, dim=1, largest=True, sorted=True | ||
) | ||
n_tokens_to_keep = max(2, 1 + n_eos_tokens) * num_beams | ||
if do_sample: |
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.
very nice thaat all the do_sample flag expose the real changed / diff between the two!
What does this PR do?
We have two pairs of functions that are near copy of each other. These pairs are exactly the same, except for the token selection part (argmax vs multinomial sampling):
_greedy_search
/_sample
_beam_search
/_beam_sample
This PR keeps the most popular version of each pair (
_sample
and_beam_search
), making the appropriate changes to preserve all functionality.