Skip to content

Align EOS token ID between tokenizer and generation config #663

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

Merged
merged 2 commits into from
May 27, 2025
Merged

Conversation

lewtun
Copy link
Member

@lewtun lewtun commented May 27, 2025

This PR addresses a nasty footgun in transformers, where a change to the base model's tokenizer must ALSO be propagated to the model's generation config. Without this change, the pipeline() function produces unbounded generations because it relies on the base model's EOS token (e.g. <|endoftext|>) instead of the one we set in the tokenizer config (e.g. <|im_end|>)

Note that this has no impact on vllm since there the EOS token is inferred from the tokenizer_config.json file.

cc @qgallouedec @kashif for viz as this might be necessary to include on the SFT script of TRL too.

I also took the opportunity to clean up some of the "demo" recipes as I think it's better to have a single source of truth for well-tested recipes.

@lewtun lewtun requested a review from edbeeching May 27, 2025 09:54
- `grpo.py`: trains a model with GRPO on a given dataset.
- `sft.py`: performs a simple SFT of a model on a dataset.
- `evaluate.py`: evaluates a model on the R1 benchmarks.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer exists since we migrated the evals to lighteval natively

@@ -140,6 +140,9 @@ def make_conversation(example, prompt_column: str = script_args.dataset_prompt_c
# Save model and create model card
##################################
logger.info("*** Save model ***")
# Align the model's generation config with the tokenizer's eos token
# to avoid unbounded generation in the transformers `pipeline()` function
trainer.model.generation_config.eos_token_id = tokenizer.eos_token_id
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the key change to avoid the generation footgun

@kashif
Copy link
Collaborator

kashif commented May 27, 2025

ok checking

@lewtun lewtun merged commit 33f84de into main May 27, 2025
1 check passed
@lewtun lewtun deleted the fix-eos branch May 27, 2025 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants