Repository navigation
Conversation
The generator stopped every sequence at the longest prompt length plus max_gen_len, so a sequence with a shorter prompt in a padded batch could generate up to (longest prompt - its prompt) extra tokens. Force EOS per sequence once it has generated max_gen_len tokens. Fixes facebookresearch#1078
kevin9327
requested review from
MartinGleize,
cbalioglu and
zyaoj
as code owners
October 17, 2026 16:34
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Fixes #1078.
_AbstractSamplingSequenceGeneratorOpsets_max_seq_lento the longest prompt length plusmax_gen_lenand forces EOS only at that step. In a padded batch, a sequence whose prompt is shorter than the longest one could therefore generatemax_gen_len + (longest prompt - its prompt)tokens.This change forces EOS per sequence once it has generated
max_gen_lentokens, using the per-sequence prompt lengths that are already tracked (and reordered) in_prompt_lens. Unpadded batches and the longest prompt behave exactly as before.Tests
Added
tests/unit/generation/test_sampling_generator.py, which runs the generator on a padded batch with prompt lengths 1 and 6 andmax_gen_len=10, using a stub model that never predicts EOS.assert 15 == 10).pytest tests/unit/generation,black,isort,flake8andmypypass on the changed files.Check list
AI assistance: this change was prepared with the help of an AI coding assistant. I reviewed the change and ran the tests above locally.