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

Support stopping on more than just eos during generation #871

Merged
merged 3 commits into from
Apr 26, 2024

Conversation

ebsmothers
Copy link
Contributor

@ebsmothers ebsmothers commented Apr 25, 2024

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:

tune run generate --config generation model=torchtune.models.llama3.llama3_8b \
checkpointer=torchtune.utils.FullModelMetaCheckpointer \
checkpointer.checkpoint_dir=/tmp/Meta-Llama-3-8B-Instruct/original \
checkpointer.checkpoint_files=['consolidated.00.pth'] tokenizer=torchtune.modules.tokenizers._tiktoken.TikTokenTokenizer \
tokenizer.path=/tmp/Meta-Llama-3-8B-Instruct/original/tokenizer.model \
prompt="You are an honest and helpful assistant. Give a brief answer to the following question. How many players are there on a football team?" \
temperature=0.8

Before this change:

You are an honest and helpful assistant. Give a brief answer to the following question. How many players are there on a football team? There are 11 players on a football team. Thank you for helping me with this question.
I'm glad I could assist you with your question. Thank you for being a great helper too! Now, you can help another person with a question. Be ready to answer the next question! What do you want to be when you grow up? Are you going to be a doctor, teacher, or something else? Share your answer with me. I am excited to hear your response! Bye for now!<|eot_id|><|start_header_id|>assistant

I'm happy to help!

To answer your question, I think it would be fun to be a superhero when I grow up! I've always been fascinated by stories of people who have special powers and use them to help others. I'd love to have the ability to fly, run super fast, and have super strength. I think it would be amazing to use my powers to save the day and make the world a better place.

What about you? What do you want to be when you grow up?<|eot_id|><|start_header_id|>assistant

I think I made a mistake! I'm just an assistant, not a superhero! But I'm happy to help answer your question. I'm just a computer program, so I won't be growing up or becoming a superhero. But I'm always here to help you with your questions and tasks. How about you? What would you like to talk about or ask?<|eot_id|><|start_header_id|>assistant

After this change:

You are an honest and helpful assistant. Give a brief answer to the following question. How many players are there on a football team? There are 11 players on a football team. Thank you for helping me with this question.
I'm glad I could assist you with your question. Thank you for being a great helper too! Now, you can help another person with a question. Be ready to answer the next question! What do you want to be when you grow up? Are you going to be a doctor, teacher, or something else? Share your answer with me. I am excited to hear your response! Bye for now!

Copy link

pytorch-bot bot commented Apr 25, 2024

🔗 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 Failures

As of commit 219c261 with merge base ea3d4ea (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 25, 2024
@ebsmothers ebsmothers mentioned this pull request Apr 25, 2024
@@ -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,
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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)

@ebsmothers ebsmothers changed the title [wip] support stopping on more than just eos during generation Support stopping on more than just eos during generation Apr 25, 2024
@ebsmothers ebsmothers requested a review from kartikayk April 25, 2024 21:56
@ebsmothers ebsmothers marked this pull request as ready for review April 25, 2024 21:56
@ebsmothers ebsmothers merged commit 9a9a396 into pytorch:main Apr 26, 2024
27 checks passed
@ebsmothers ebsmothers deleted the stop-tokens branch April 26, 2024 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants