Repository navigation
Decode: cover explicit positions past the lazy RoPE cache in Gemma2, Cohere, Granite and FalconH1 - #14199
Merged
Conversation
…ohere, Granite, FalconH1 The RoPE cache only builds the rows a forward asks for, so after a prefill without position_ids on a model whose max_position_embeddings exceeds the 32768-row starting cache, a decode step at a later explicit position indexed past the built rows and hit a CUDA device-side assert. Each model decode loop now computes rotary_seq_len once per step (as LlamaModel_fast_forward_inference does) and passes it to every layer, which extends and reads the cache only when it runs past the KV length. The host sync is skipped when the eager cache already holds every supported position.
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. Bravo. 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". |
danielhanchen
added a commit
that referenced
this pull request
Oct 19, 2026
## Summary The `Core zoo` cells in `consolidated-tests-ci.yml` keep hitting their 25 minute job cap after the tests have already passed. In one cancelled cell: - the zoo `pytest -n 4` step ran from 08:41 to 09:03 and passed (3015 passed, 620 skipped), - the job was then cancelled at 25:17 during `test_apply_fused_lm_head` and the pip cache save. The comment above the cap assumed a ~7.6 min zoo suite. It now takes up to about 23 minutes on a busy runner, so the cap cancels cells that have already passed. Today that cancelled Core zoo cells on #14152, #14165, #14188, #14192, #14199 and #14207, and on staging runs. Each one needs a manual rerun before the PR can merge. This raises the cap to 35 minutes, the same as `consolidated`. Hung tests are still bounded: `PYTEST_TIMEOUT: 300` in the step still names the culprit per test. ## Tests The workflow-parsing tests (`git grep -l consolidated-tests-ci -- tests`): 158 passed, 3 skipped. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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
The RoPE cache is built lazily, with only the rows asked for. #13976 fixed Llama's decode loop for explicit
position_idspast the KV length (for example after left padding or a prefill withoutposition_ids). Gemma2, Cohere, Granite and FalconH1 have their own decode loops and still read cos / sin at the KV length, so a position past the cached rows hit a CUDA index-out-of-bounds assert.Each of the four decode loops now computes the rows one step needs once, with a new helper
_decode_rotary_seq_leninllama.py: the larger of the KV length and the highest explicit position + 1. It then passes that value to every layer. Attention only extends the cache and reads the larger table when the position is past the KV length; otherwise it makes exactly the same calls as before.Cost: one
.item()host sync per decode step, the same one Llama's loop already pays. It is skipped entirely (zero syncs) when the cache built at load already coversmax_position_embeddings, which holds for any model with 32768 or fewer positions, such as Gemma2 (8192). Nothing is computed per layer.Tests
tests/test_decode_offset_rope_model_loops.pyuses tiny models withmax_position_embeddings = 40960. It prefills 4 tokens withoutposition_ids, then decodes at position 35000.For normal decoding, logits are bitwise equal to main:
generateat batch 1 and 2, on both the one-sync and the zero-sync path.tests/test_rope_cache_current_device.pyneeds a one line update for the new argument; all 23 tests in the two files pass on GPU.Not covered here
FastLanguageModeldoes not route Cohere, Granite or FalconH1 to these decode loops, so they are only reached through their patchers directly.