Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24979
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 44 PendingAs of commit ec3b0f7 with merge base 1ab77be ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
This PR needs a
|
Gasoonjia
force-pushed
the
fix/muse-glimmer-ring-buffer-size
branch
from
November 12, 2026 08:29
743f9d0 to
638174d
Compare
The sliding-window RingKVCache was hardcoded to 2 * window (4096), and the
CUDA export's max prefill chunk is also 2 * window. A T-token write needs
W + T - 1 consecutive positions resident so its first query still sees the
W - 1 keys before it, so from the second chunk on, 2047 of 4096 query rows
saw only part of their 2048-key window (about 1024 keys missing on average).
The window comes from the model, but the chunk is an export choice, so the
ring now takes it as a parameter: RingKVCache(max_write_len=...) sizes to
window + max_write_len - 1, matching the MLX RingBufferKVCache.
MuseGlimmerModel.set_max_prefill_chunk() resizes the sliding rings and the
mask together; the CUDA solo and DFlash exports call it with their max
prefill (4096 -> ring 6143). The default max_write_len is window, as on MLX.
Test plan:
- test_prefill_chunks_see_full_window: for chunk sizes 3, window and
2 * window, every query attends to exactly min(pos + 1, window) keys. It
fails with the old 2 * window ring.
- test_chunked_prefill_matches_sequential (CUDA) now runs max-size chunks
that wrap the ring.
- pytest examples/models/muse-glimmer/tests/{test_pipeline,
test_export_dflash,test_checkpoint_context,test_mlx_offgraph}.py:
61 passed, 9 skipped.
Gasoonjia
force-pushed
the
fix/muse-glimmer-ring-buffer-size
branch
from
November 12, 2026 08:43
638174d to
ec3b0f7
Compare
Gasoonjia
requested a deployment
to
cadence
November 12, 2026 08:59 — with
GitHub Actions
In progress
Gasoonjia
requested a deployment
to
cadence
November 12, 2026 08:59 — with
GitHub Actions
In progress
This branch is being 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.
Summary
The Muse Glimmer sliding-window
RingKVCachewas hardcoded to2 * window(4096 for window 2048), and the CUDA export's max prefill chunk is also2 * window. After a T-token write, its first query still needs the W − 1 keys before it, so W + T − 1 consecutive positions must stay in the ring at once. With ring = chunk = 4096, from the second chunk on, 2047 of 4096 query rows saw only part of their 2048-key window (about 1024 keys missing on average). This affects any chunk=4096 prefill / NLL on the in-graph CUDA path.The window is fixed by the model, but the chunk is an export choice. So the ring now takes the chunk as a parameter instead of deriving it from the window:
RingKVCache(..., max_write_len=None)sizes towindow + max_write_len - 1, the same rule as the MLXRingBufferKVCache.max_write_lendefaults towindow, as on MLX.MuseGlimmerModel.set_max_prefill_chunk(n)rebuilds the sliding-window rings and keeps_build_masksconsistent with them._export_cuda) and the DFlash CUDA export call it with their existing max prefill (min(max_seq_len - 1, 2 * window), i.e. 4096). That gives a ring of 6143. The chunk size is unchanged.inference.pychunks eager prefill bymodel.max_prefill_chunk, so eager chunks always match the ring.Unchanged paths:
max_write_len=window, which covers its writes (min(window, max_target_prefill)).max_write.Test plan
test_prefill_chunks_see_full_window: for chunk sizes 3,window, and2 * window, every query attends to exactlymin(pos + 1, window)keys. It fails with the old2 * windowring.test_ring_sized_for_max_write_len: checks thebuf_sizeformula.test_chunked_prefill_matches_sequential(CUDA) now runs max-size chunks that wrap the ring.pytest examples/models/muse-glimmer/tests/{test_pipeline,test_export_dflash,test_checkpoint_context,test_mlx_offgraph}.py: 61 passed, 9 skipped (CPU). CUDA tests not run locally (no GPU on this host).