-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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: assisted decoding with sample #22862
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,8 +54,10 @@ class GenerationConfig(PushToHubMixin): | |
`num_beams>1` and `num_beam_groups>1` | ||
- *constrained beam-search decoding* by calling [`~generation.GenerationMixin.constrained_beam_search`], if | ||
`constraints!=None` or `force_words_ids!=None` | ||
- *assisted decoding* by calling [`~generation.GenerationMixin.assisted_decoding`], if | ||
`assistant_model` is passed to `.generate()` | ||
|
||
You do not need to call any of the above methods directly. Pass custom parameter values to 'generate'. To learn | ||
You do not need to call any of the above methods directly. Pass custom parameter values to '.generate()'. To learn | ||
more about decoding strategies refer to the [text generation strategies guide](../generation_strategies). | ||
|
||
Arg: | ||
|
@@ -179,6 +181,11 @@ class GenerationConfig(PushToHubMixin): | |
A list of pairs of integers which indicates a mapping from generation indices to token indices that will be | ||
forced before sampling. For example, `[[1, 123]]` means the second generated token will always be a token | ||
of index 123. | ||
assisted_keep_proba (`float`, *optional*): | ||
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. Default value should be mentioned here |
||
Used with assisted decoding. When `do_sample` is true, this controls the threshold at which the model will | ||
resample candidate tokens. When the model's predicted probability for a candidate token is below this | ||
threshold, the candidate token is invalidated and a sampling step. Decreasing this value will aproximate | ||
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. and a sampling step is performed? |
||
the decoding process to greedy search, but it will be faster. | ||
|
||
> Parameters that define the output variables of `generate` | ||
|
||
|
@@ -258,6 +265,7 @@ def __init__(self, **kwargs): | |
self.suppress_tokens = kwargs.pop("suppress_tokens", None) | ||
self.begin_suppress_tokens = kwargs.pop("begin_suppress_tokens", None) | ||
self.forced_decoder_ids = kwargs.pop("forced_decoder_ids", None) | ||
self.assisted_keep_proba = kwargs.pop("assisted_keep_proba", 0.3) | ||
|
||
# Parameters that define the output variables of `generate` | ||
self.num_return_sequences = kwargs.pop("num_return_sequences", 1) | ||
|
@@ -319,6 +327,8 @@ def validate(self): | |
""" | ||
if self.early_stopping not in {True, False, "never"}: | ||
raise ValueError(f"`early_stopping` must be a boolean or 'never', but is {self.early_stopping}.") | ||
if self.assisted_keep_proba < 0.0 or self.assisted_keep_proba > 1.0: | ||
raise ValueError(f"`assisted_keep_proba` must be between 0.0 and 1.0, but is {self.assisted_keep_proba}.") | ||
|
||
def save_pretrained( | ||
self, | ||
|
Oops, something went wrong.
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.
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 do not like this name, and I'm not completely understanding what this argument does from the doc so I can't suggest a new one😅
assisted_threshold
maybe?