-
Notifications
You must be signed in to change notification settings - Fork 530
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
Support stopping on more than just eos during generation #871
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/871
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 219c261 with merge base ea3d4ea ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
torchtune/utils/_generation.py
Outdated
@@ -67,7 +67,7 @@ def generate( | |||
max_generated_tokens: int, | |||
temperature: float = 1.0, | |||
top_k: Optional[int] = None, | |||
eos_id: Optional[int] = None, | |||
stop_tokens: Optional[List[int]] = None, |
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.
Make it a set for faster lookup
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.
oooooooh leetcode coming in clutch
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.
Just did the math and O(2) is in fact slower than O(1)
Based on https://github.com/meta-llama/llama3/blob/main/llama/tokenizer.py#L91-L94 and https://github.com/meta-llama/llama3/blob/main/llama/generation.py#L197 we should support stopping on more than one token during generation. This PR adds this field to our tokenizers and integrates it into the generation recipe.
Run the following command:
Before this change:
After this change: