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

Terminator strings for generate() #28932

Merged
merged 68 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
262537f
stash commit (will discard all of this)
Rocketknight1 Feb 6, 2024
cfa538b
stash commit
Rocketknight1 Feb 8, 2024
127182a
First commit - needs a lot of testing!
Rocketknight1 Feb 8, 2024
8cd6059
Add a test
Rocketknight1 Feb 8, 2024
5fde7ae
Fix imports and make the tests actually test something
Rocketknight1 Feb 8, 2024
ff02b0c
Tests pass!
Rocketknight1 Feb 8, 2024
4ce1aba
Rearrange test
Rocketknight1 Feb 8, 2024
1742b68
Add comments (but it's still a bit confusing)
Rocketknight1 Feb 8, 2024
9fb77e3
Stop storing the tokenizer
Rocketknight1 Feb 8, 2024
667d6d8
Comment fixup
Rocketknight1 Feb 8, 2024
070a76e
Fix for input_ids with a single sequence
Rocketknight1 Feb 9, 2024
4c436f2
Update tests to test single sequences
Rocketknight1 Feb 9, 2024
78b0f24
make fixup
Rocketknight1 Feb 9, 2024
8ee5762
Fix incorrect use of isin()
Rocketknight1 Feb 12, 2024
9f43a2a
Expand tests to catch more cases
Rocketknight1 Feb 12, 2024
f0fa707
Expand tests to catch more cases
Rocketknight1 Feb 12, 2024
5bcf5e4
make fixup
Rocketknight1 Feb 12, 2024
8cca9a4
Fix length calculation and update tests
Rocketknight1 Feb 13, 2024
ec6f726
Handle Ġ as a space replacement too
Rocketknight1 Feb 14, 2024
0e632c2
Update src/transformers/generation/stopping_criteria.py
Rocketknight1 Feb 15, 2024
ac1135c
Add optimizations from Joao's suggestion
Rocketknight1 Feb 15, 2024
2731827
Remove TODO
Rocketknight1 Feb 15, 2024
9213298
Update src/transformers/generation/stopping_criteria.py
Rocketknight1 Feb 15, 2024
f48522e
Update tests/generation/test_stopping_criteria.py
Rocketknight1 Feb 15, 2024
7a772b8
make fixup
Rocketknight1 Feb 15, 2024
c604a2b
Rename some variables and remove some debugging clauses for clarity
Rocketknight1 Feb 16, 2024
7dd346a
Add tests for the sub-methods
Rocketknight1 Feb 16, 2024
641ba72
Clarify one test slightly
Rocketknight1 Feb 16, 2024
f6721a5
Add stop_strings to GenerationConfig
Rocketknight1 Feb 16, 2024
8772bcb
generate() supports stop_string arg, asks for tokenizer if not provided
Rocketknight1 Feb 16, 2024
e423417
make fixup
Rocketknight1 Feb 16, 2024
398a799
Cleanup code and rename variables for clarity
Rocketknight1 Feb 19, 2024
e3140a6
Update tokenizer error
Rocketknight1 Feb 19, 2024
0008722
Update tokenizer passing, handle generation on GPU
Rocketknight1 Feb 19, 2024
a29c131
Slightly more explanation cleanup
Rocketknight1 Feb 19, 2024
9c359ff
More comment cleanup
Rocketknight1 Feb 19, 2024
602222d
Factor out the token cleanup so it's more obvious what we're doing, a…
Rocketknight1 Feb 19, 2024
4c7a777
Careful with that cleanup!
Rocketknight1 Feb 19, 2024
b6e0163
Cleanup + optimizations to _get_matching_positions
Rocketknight1 Feb 23, 2024
43d9e08
More minor performance tweaks
Rocketknight1 Feb 23, 2024
60eb576
Implement caching and eliminate some expensive ops (startup time: 200…
Rocketknight1 Feb 23, 2024
ff42211
Remove the pin_memory call
Rocketknight1 Feb 23, 2024
ae800a6
Parallelize across all stop strings!
Rocketknight1 Feb 23, 2024
46c0a9c
Quick fix for tensor devices
Rocketknight1 Feb 23, 2024
b9a066d
Update embeddings test for the new format
Rocketknight1 Feb 23, 2024
692523c
Fix test imports
Rocketknight1 Feb 23, 2024
2ba7f8e
Manual patching for BERT-like tokenizers
Rocketknight1 Feb 26, 2024
8b95ec1
Return a bool vector instead of a single True/False
Rocketknight1 Feb 26, 2024
1b46b20
Better comment
Rocketknight1 Feb 26, 2024
350a850
Better comment
Rocketknight1 Feb 26, 2024
0b85c6c
Add tests from @zucchini-nlp
Rocketknight1 Feb 27, 2024
e8c769d
Amy's list creation nit
Rocketknight1 Mar 12, 2024
14de1c3
tok_list -> token_list
Rocketknight1 Mar 12, 2024
b8961e8
Push a big expanded docstring (should we put it somewhere else?)
Rocketknight1 Mar 13, 2024
7ed55ad
Expand docstrings
Rocketknight1 Mar 13, 2024
cbb9d14
Docstring fixups
Rocketknight1 Mar 13, 2024
7db95c1
Rebase
Rocketknight1 Mar 21, 2024
49b0f21
make fixup
Rocketknight1 Mar 21, 2024
c9aefe6
Make a properly general method for figuring out token strings
Rocketknight1 Mar 21, 2024
443cd5d
Fix naming throughout the functions
Rocketknight1 Mar 21, 2024
e1c9c0e
Move cache, refactor, fix tests
Rocketknight1 Mar 21, 2024
f49ec00
Add comment
Rocketknight1 Mar 21, 2024
e90aaba
Remove finished TODO
Rocketknight1 Mar 21, 2024
bb27d82
Remove finished TODO
Rocketknight1 Mar 22, 2024
4317019
make fixup
Rocketknight1 Apr 2, 2024
19df6a8
Update src/transformers/generation/stopping_criteria.py
Rocketknight1 Apr 11, 2024
8b52039
Update and shorten docstring
Rocketknight1 Apr 11, 2024
0aa201c
Update tests to be shorter/clearer and test specific cases
Rocketknight1 Apr 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/transformers/generation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"StoppingCriteria",
"StoppingCriteriaList",
"validate_stopping_criteria",
"StopStringCriteria",
]
_import_structure["utils"] = [
"GenerationMixin",
Expand Down Expand Up @@ -224,6 +225,7 @@
MaxTimeCriteria,
StoppingCriteria,
StoppingCriteriaList,
StopStringCriteria,
validate_stopping_criteria,
)
from .utils import (
Expand Down
3 changes: 3 additions & 0 deletions src/transformers/generation/configuration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class GenerationConfig(PushToHubMixin):
max_time(`float`, *optional*):
The maximum amount of time you allow the computation to run for in seconds. generation will still finish
the current pass after allocated time has been passed.
stop_strings(`str or List[str]`, *optional*):
A string or a list of strings that should terminate generation if the model outputs them.

> Parameters that control the generation strategy used

Expand Down Expand Up @@ -306,6 +308,7 @@ def __init__(self, **kwargs):
self.min_new_tokens = kwargs.pop("min_new_tokens", None)
self.early_stopping = kwargs.pop("early_stopping", False)
self.max_time = kwargs.pop("max_time", None)
self.stop_strings = kwargs.pop("stop_strings", None)

# Parameters that control the generation strategy used
self.do_sample = kwargs.pop("do_sample", False)
Expand Down
Loading
Loading