Repository navigation
[Fix] deepseek-v4.1: Keep the full SWA window for short bounded-replay extends - #41303
Merged
hnyls2002 merged 8 commits intoOct 16, 2026
Conversation
vineelbhat
force-pushed
the
fix/dsv41-decoder-swa-replay-short-extend
branch
7 times, most recently
from
September 26, 2026 05:50
6075d03 to
9ec00c1
Compare
vineelbhat
marked this pull request as ready for review
September 26, 2026 07:46
vineelbhat
requested review from
Ying1123,
alphabetc1,
hanming-lu,
hnyls2002,
huangtingwei9988,
hzh0425,
ispobock,
merrymercy,
xiezhq-hermann and
yizhang2077
as code owners
September 26, 2026 07:46
vineelbhat
force-pushed
the
fix/dsv41-decoder-swa-replay-short-extend
branch
2 times, most recently
from
September 26, 2026 09:01
d5a72f1 to
b34704b
Compare
vineelbhat
force-pushed
the
fix/dsv41-decoder-swa-replay-short-extend
branch
from
September 27, 2026 20:34
b34704b to
5f06772
Compare
…ed replay swa_reprefill_tail_tokens() returns the window when decoder bounded replay is on, so the scheduler's key_limit stops every prefix hit at least one window short of the prompt. Adds a unit test on a real FULL+SWA cache. A streaming session whose slot cannot rewind to the capped match releases the slot and falls back to the radix match. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…long PrefillAdder._hold_back_final_chunk shortens a chunk so that exactly one window remains when the remainder would be shorter than the window, at the three places a chunk length is committed. The boundary it creates is not page aligned. Adds three unit tests. Co-Authored-By: Claude Fable 5.1 <[email protected]>
vineelbhat
force-pushed
the
fix/dsv41-decoder-swa-replay-short-extend
branch
from
September 28, 2026 21:34
5f06772 to
9dac568
Compare
Contributor
|
/tag-and-rerun-ci |
vineelbhat
requested review from
BBuf,
DarkSharpness,
HydraQYH,
celve and
yuan-luo
as code owners
September 30, 2026 22:17
Contributor
Author
|
@kpham-sgl replaced with your fix in 99d8156 and re-ran the short final chunk accuracy tests. |
kpham-sgl
reviewed
Oct 3, 2026
3 of 5 tasks
dcw02
reviewed
Oct 15, 2026
| if len(extend_lens_cpu) == 1: | ||
| n, t, s = extend_lens_cpu[0], tail_lens_cpu[0], seq_lens_cpu[0] | ||
| floor = torch.full((t,), s - t, dtype=torch.int32, device=device) | ||
| floor = torch.full((t,), max(0, s - tail_len), dtype=torch.int32, device=device) |
Collaborator
There was a problem hiding this comment.
i think this is missing testing coverage, the new test covers prefix holdback but wouldn't catch the window floor reverting to chunk start
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add a late_layer_tail_layout test for a final prefill chunk shorter than a window, in a batch of one request and a batch of several. It fails if the floor goes back to the chunk start. Also update the docstring of test_tail_keeps_its_own_floor_under_fold, which described the tail floor as the tail start. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Author
|
merged main in and added test coverage for the chunked prefill side |
…ase branch; fix hold-back test after Req.prefix_indices removal; refresh comments
Collaborator
|
/rerun-test test_encoder_swa_replay.py test_unified_radix_cache_unittest.py test_unified_cache_linker.py test_radix_force_miss.py test_deepseek_v41_flash_gb300.py |
Contributor
|
🚀 🚀 🚀 |
akhilg-nv
added a commit
to akhilg-nv/sglang
that referenced
this pull request
Oct 16, 2026
Resolve conflicts with sgl-project#43922 (MegaAttention) by keeping both sides. After sgl-project#41303 floors the bounded-replay tail at seq_len - SWA_WINDOW, tail rows bound their SWA columns by the floored swa_topk_lengths instead of the tail offset. Co-Authored-By: Claude Opus 5.5 <[email protected]>
5 tasks done
3 of 4 tasks
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.
Motivation
With DeepSeek-V4.1's
--enable-decoder-swa-bounded-replay, the layers after the last kv_source layer attend over only the lastmin(window, extend_len)rows of each prefill extend. An extend shorter than the window therefore gives the prompt's first sampled token a truncated window.This happens on a prefix-cache hit that leaves fewer than
windowuncached rows, and on a chunked prefill whose final chunk is shorter thanwindow.Modifications
swa_reprefill_tail_tokens()returnssliding_window_sizewhen the newCacheInitParams.decoder_swa_bounded_replayis set.seq_len - windowinstead of at the chunk start, so the chunk reads the previous chunk's tail rows, which already hold their late-layer KV. This is a two line change inlate_layer_tail_layout.swa_reprefill_tail_tokens(req)takes the request for this.Accuracy Tests
4xB200, DeepSeek-V4.1-Flash TP4/EP4, greedy, 12 prompts per row, at the first generated position. Flips count prompts whose sampled token changed; shift is the median change of the reference's sampled-token logprob, in nats.
Prefix hit. An 8192-token cached prefix plus N fresh tokens, against a cold prefill of the same prompt.
Short final chunk. A cold 16384 + m token prompt prefilled with a 16384-token chunk size, so its final chunk has m rows, against the same prompt prefilled as one 8192 + m extend after priming its first 8192 tokens.
test_unified_radix_cache_unittest.py: 2789 run on 1xH100, OK (1504 config skips), 1 new case.test_unified_cache_linker.py: 32 passed, one existing test updated.Speed Tests and Profiling
The prefix-match limit only applies when a hit would leave fewer than
windowuncached rows, and then recomputes at most one page. The floor change costs each token of a short final chunk at most a full window of 128 keys to score.Checklist
CI States
Latest PR Test (Base): 🚫 Run #38824417900
Latest PR Test (Extra): ❌ Run #38824417703
Latest PR Test (AMD ROCm 10): ⏳ Run #38824417750