Repository navigation
Qwen3 decode: size the RoPE read by the explicit position, not only the KV length - #14156
Merged
Merged
Conversation
…he KV length The RoPE cache builds only the rows a forward asks for, so after a prefill without position_ids a decode step at a position past those rows indexed out of range (CUDA device assert). Use the rotary_seq_len the shared decode loop already computes once per step, as the Llama decode path does; no extra host sync.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
Summary
#13855 made the RoPE cache lazy: it only builds the rows that are asked for.
Qwen3Attention_fast_forward_inferencesized the cache read by the KV length only. A decode step at an explicit position past the KV length therefore indexed past the built rows and hit a CUDA device-side assert. For example: a prefill withoutposition_ids, then a hand-made decode at position >= 32768. Base (before #13855) returned finite logits. Normalgenerateis not affected.The model-level decode loop already computes
rotary_seq_len = max(kv_seq_len, position_ids.max() + 1)once per step and passes it to every layer. Qwen3 attention now sizes the RoPE extension and read from it, so this adds no host sync. Withoutrotary_seq_lenthe previous sizing is used.Tests
tests/test_qwen3_decode_offset_rope.py(tiny Qwen3, GPU): decode at an explicit position past the lazily built rows. It fails on main with the device-side assert and passes here.Not fixed here: Gemma2, Cohere, Granite and FalconH1 read the cache the same way. Their model-level loops do not compute
rotary_seq_len, so a fix there needs one host sync per decode step. Those are left for a follow-up.