Repository navigation
Conversation
Prefill samples one token, but the static-cache and graph-capture paths called the model without logits_to_keep, so the lm_head produced [batch, prompt_len, vocab] logits. Pass logits_to_keep=1 when the model's forward declares it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
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.
Related to #8197.
Summary
Rollout prefill only needs the last position's logits to pick the first token. Two prefill call sites in
HybridEngineRolloutcalled the model withoutlogits_to_keep, so the lm_head produced full[batch, prompt_len, vocab]logits:_generate_graph(graph-capture path)_continuous_prefill_cache, explicit static-cache branch (models that still expose_supports_cache_class)This PR passes
logits_to_keep=1when the model'sforwarddeclares the argument, mirroring how Transformers'generate()decides. Models without it are unchanged: their**kwargsmay be forwarded to submodules, so the argument is not passed blindly. Themodule.generate()branch already does this internally and is untouched.Scope
_supports_cache_classand supportlogits_to_keep(>= 4.50). On Transformers 5.x this path goes throughmodule.generate(), which already keeps only the last logits, so behavior is unchanged there.Measurements
Prefill forward with
StaticCache. Random-weight Llama with vocab 151936, hidden 1024, 4 layers, bf16. 1× Intel Arc Pro B70.logits_to_keep=1The selected first token is identical in all cases, and it matches the argmax of a plain HF forward. Small models gain the most because the lm_head dominates; for larger models the time saving shrinks, but the full-vocab activation is still avoided.
Tests
test_continuous_prefill_requests_last_logits_only: a model following the Transformerslogits_to_keepcontract getslogits_to_keep=1at prefill, and the generated tokens are unchanged. The test fails without the change.tests/unit/runtime/rollout/: 63 passed, 1 skipped (CPU).