Skip to content

[Fix] deepseek-v4.1: Keep the DSpark draft SWA out of the radix tree - #44673

Merged
hnyls2002 merged 2 commits into
mainfrom
lsyin/dspark-draft-request-window
Oct 16, 2026
Merged

hnyls2002 merged 2 commits into
mainfrom
lsyin/dspark-draft-request-window

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator
  • Under --enable-encoder-swa-bounded-replay the target already keeps SWA in a per-request window, but the DSpark draft still forced a paged SWA allocator, so the radix tree kept an SWA component only the draft used. Evicting the draft's SWA then cut prefix hits on Main KV the target could still reuse ([Fix] [AMD] hicache: Serve encoder-replay prefix hits with a paged DSpark draft SWA #42716 skips the same match gate).
  • The DSpark draft SWA now lives in a per-request ring on CUDA: swa_ring_rows (req_pool_idx * ring + pos % ring) and get_draft_swa_ring_size (sliding window + max draft tokens) own its layout for every reader and writer. No pool needs needs_paged_swa_allocator, so the tree holds no SWA component.
  • Writes reuse the existing ring path (_ring_inject_loc, and build_unified_commit_inject_layout renamed to build_ring_commit_inject_layout), now keyed on the draft pool's swa_req_ring_size instead of the unified_kv gate.
  • Reads: get_dspark_swa_page_indices builds the draft window from the ring (BuildDsparkSwaRingIndices), and the draft block writes its ring rows, both eagerly and in the graph.
  • A request placed by a prefix hit starts its ring at the hit (swa_req_ring_valid_from), so the draft masks earlier positions instead of reading rows left by the slot's previous request.
  • The ring is budgeted as a fixed reservation next to the request windows instead of per SWA token.

Only DeepSeek-V4.1 with encoder SWA bounded replay and DSpark on CUDA changes; HIP keeps the paged draft SWA, and every other configuration is unchanged. After a prefix hit, the draft attends only to rows written since the hit until its window fills again.

On DeepSeek-V4.1-Flash (4x GB300, TP4, DSpark, encoder replay), a prompt whose draft SWA was evicted by 400 other prompts re-hits 8448 of its 8565 tokens instead of 0. GSM8K stays at 98.0% with and without decoder replay, and the average accept length is 3.81 against 3.78 before.


CI States

Latest PR Test (Base): 🚫 Run #38868277003
Latest PR Test (Extra): ❌ Run #38868276936
Latest PR Test (AMD ROCm 10): 🚫 Run #38868276948

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_dsv4_compressed_pools.py test_pool_configurator.py test_encoder_swa_replay.py test_dspark_draft_block.py test_dsv4_c4_state_lifecycle.py test_dspark_kernel_parity.py test_deepseek_v41_flash_gb300.py test_unified_radix_cache_kl_dsv4.py

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (5 tests): ✅ View workflow run

cd test/ && python3 registered/unit/mem_cache/test_dsv4_compressed_pools.py
cd test/ && python3 registered/unit/model_executor/test_pool_configurator.py
cd test/ && python3 registered/unit/model_executor/test_encoder_swa_replay.py
cd test/ && python3 registered/unit/spec/test_dspark_draft_block.py
cd test/ && python3 registered/unit/mem_cache/test_dsv4_c4_state_lifecycle.py

🚀 1-gpu-5090 (1 test): ✅ View workflow run

cd test/ && python3 registered/spec/dspark/test_dspark_kernel_parity.py

🚀 4-gpu-gb300 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300.py

🚀 4-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_dsv4.py

@hnyls2002
hnyls2002 merged commit fad7d95 into main Oct 16, 2026
111 of 150 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/dspark-draft-request-window branch October 16, 2026 08:19
@hnyls2002 hnyls2002 mentioned this pull request Oct 16, 2026
17 of 56 tasks
JamesBrianD added a commit to sgl-project/sglang-torchtpu that referenced this pull request Nov 18, 2026
Under --enable-encoder-swa-bounded-replay the TPU DSpark draft kept paged SWA
through the target's full-to-SWA mapping, so the target kept its paged SWA
allocator, the radix tree kept tracking SWA, and a partial prefix hit whose SWA
was freed matched 0 tokens. The draft now keeps its SWA in a per-request ring,
as core DSparkWorkerV2 since sgl-project/sglang#44673, and TPU stops forcing
uses_draft_swa_ring() off.

- Pool: the draft SWA pool takes the request window's ring layout (4 x 64-token
  pages per slot after the reserved pages) and keeps swa_req_ring_valid_from on
  the host for the attention backend.
- Writes: TpuBlockSpecWorker computes ring rows from (req slot, position) for
  extend (last 256 positions of each request) and verify commit instead of the
  full-to-SWA map; a newly placed or retracted request restarts its ring at its
  cached prefix (encoder_swa_reset), since replayed rows never reach the draft.
- Reads: the draft backend's SWA table maps every logical page to the slot's
  ring and floors visibility at valid_from.
- Sizing: the TPU request-window price includes the draft ring pages; the
  0-token SWA floor skip also applies to the draft worker.
JamesBrianD added a commit to sgl-project/sglang-torchtpu that referenced this pull request Nov 18, 2026
Under --enable-encoder-swa-bounded-replay the TPU DSpark draft kept paged SWA
through the target's full-to-SWA mapping, so the target kept its paged SWA
allocator, the radix tree kept tracking SWA, and a partial prefix hit whose SWA
was freed matched 0 tokens. The draft now keeps its SWA in a per-request ring,
as core DSparkWorkerV2 since sgl-project/sglang#44673, and TPU stops forcing
uses_draft_swa_ring() off.

- Pool: the draft SWA pool takes the request window's ring layout (4 x 64-token
  pages per slot after the reserved pages) and keeps swa_req_ring_valid_from on
  the host for the attention backend.
- Writes: TpuBlockSpecWorker computes ring rows from (req slot, position) for
  extend (last 256 positions of each request) and verify commit instead of the
  full-to-SWA map; a newly placed or retracted request restarts its ring at its
  cached prefix (encoder_swa_reset), since replayed rows never reach the draft.
- Reads: the draft backend's SWA table maps every logical page to the slot's
  ring and floors visibility at valid_from.
- Sizing: the TPU request-window price includes the draft ring pages; the
  0-token SWA floor skip also applies to the draft worker.
JamesBrianD added a commit to sgl-project/sglang-torchtpu that referenced this pull request Nov 18, 2026
Under --enable-encoder-swa-bounded-replay the TPU DSpark draft kept paged SWA
through the target's full-to-SWA mapping, so the target kept its paged SWA
allocator, the radix tree kept tracking SWA, and a partial prefix hit whose SWA
was freed matched 0 tokens. The draft now keeps its SWA in a per-request ring,
as core DSparkWorkerV2 since sgl-project/sglang#44673, and TPU stops forcing
uses_draft_swa_ring() off.

- Pool: the draft SWA pool takes the request window's ring layout (4 x 64-token
  pages per slot after the reserved pages) and keeps swa_req_ring_valid_from on
  the host for the attention backend.
- Writes: TpuBlockSpecWorker computes ring rows from (req slot, position) for
  extend (last 256 positions of each request) and verify commit instead of the
  full-to-SWA map; a newly placed or retracted request restarts its ring at its
  cached prefix (encoder_swa_reset), since replayed rows never reach the draft.
- Reads: the draft backend's SWA table maps every logical page to the slot's
  ring and floors visibility at valid_from.
- Sizing: the TPU request-window price includes the draft ring pages; the
  0-token SWA floor skip also applies to the draft worker.
JamesBrianD added a commit to sgl-project/sglang-torchtpu that referenced this pull request Nov 19, 2026
Under --enable-encoder-swa-bounded-replay the TPU DSpark draft kept paged SWA
through the target's full-to-SWA mapping, so the target kept its paged SWA
allocator, the radix tree kept tracking SWA, and a partial prefix hit whose SWA
was freed matched 0 tokens. The draft now keeps its SWA in a per-request ring,
as core DSparkWorkerV2 since sgl-project/sglang#44673, and TPU stops forcing
uses_draft_swa_ring() off.

- Pool: the draft SWA pool takes the request window's ring layout (4 x 64-token
  pages per slot after the reserved pages) and keeps swa_req_ring_valid_from on
  the host for the attention backend.
- Writes: TpuBlockSpecWorker computes ring rows from (req slot, position) for
  extend (last 256 positions of each request) and verify commit instead of the
  full-to-SWA map; a newly placed or retracted request restarts its ring at its
  cached prefix (encoder_swa_reset), since replayed rows never reach the draft.
- Reads: the draft backend's SWA table maps every logical page to the slot's
  ring and floors visibility at valid_from.
- Sizing: the TPU request-window price includes the draft ring pages; the
  0-token SWA floor skip also applies to the draft worker.
JamesBrianD added a commit to sgl-project/sglang-torchtpu that referenced this pull request Nov 19, 2026
Under --enable-encoder-swa-bounded-replay the TPU DSpark draft kept paged SWA
through the target's full-to-SWA mapping, so the target kept its paged SWA
allocator, the radix tree kept tracking SWA, and a partial prefix hit whose SWA
was freed matched 0 tokens. The draft now keeps its SWA in a per-request ring,
as core DSparkWorkerV2 since sgl-project/sglang#44673, and TPU stops forcing
uses_draft_swa_ring() off.

- Pool: the draft SWA pool takes the request window's ring layout (4 x 64-token
  pages per slot after the reserved pages) and keeps swa_req_ring_valid_from on
  the host for the attention backend.
- Writes: TpuBlockSpecWorker computes ring rows from (req slot, position) for
  extend (last 256 positions of each request) and verify commit instead of the
  full-to-SWA map; a newly placed or retracted request restarts its ring at its
  cached prefix (encoder_swa_reset), since replayed rows never reach the draft.
- Reads: the draft backend's SWA table maps every logical page to the slot's
  ring and floors visibility at valid_from.
- Sizing: the TPU request-window price includes the draft ring pages; the
  0-token SWA floor skip also applies to the draft worker.
JamesBrianD added a commit to sgl-project/sglang-torchtpu that referenced this pull request Nov 19, 2026
Under --enable-encoder-swa-bounded-replay the TPU DSpark draft kept paged SWA
through the target's full-to-SWA mapping, so the target kept its paged SWA
allocator, the radix tree kept tracking SWA, and a partial prefix hit whose SWA
was freed matched 0 tokens. The draft now keeps its SWA in a per-request ring,
as core DSparkWorkerV2 since sgl-project/sglang#44673, and TPU stops forcing
uses_draft_swa_ring() off.

- Pool: the draft SWA pool takes the request window's ring layout (4 x 64-token
  pages per slot after the reserved pages) and keeps swa_req_ring_valid_from on
  the host for the attention backend.
- Writes: TpuBlockSpecWorker computes ring rows from (req slot, position) for
  extend (last 256 positions of each request) and verify commit instead of the
  full-to-SWA map; a newly placed or retracted request restarts its ring at its
  cached prefix (encoder_swa_reset), since replayed rows never reach the draft.
- Reads: the draft backend's SWA table maps every logical page to the slot's
  ring and floors visibility at valid_from.
- Sizing: the TPU request-window price includes the draft ring pages; the
  0-token SWA floor skip also applies to the draft worker.
cjx0709 pushed a commit to sgl-project/sglang-torchtpu that referenced this pull request Nov 19, 2026
Under --enable-encoder-swa-bounded-replay the TPU DSpark draft kept paged SWA
through the target's full-to-SWA mapping, so the target kept its paged SWA
allocator, the radix tree kept tracking SWA, and a partial prefix hit whose SWA
was freed matched 0 tokens. The draft now keeps its SWA in a per-request ring,
as core DSparkWorkerV2 since sgl-project/sglang#44673, and TPU stops forcing
uses_draft_swa_ring() off.

- Pool: the draft SWA pool takes the request window's ring layout (4 x 64-token
  pages per slot after the reserved pages) and keeps swa_req_ring_valid_from on
  the host for the attention backend.
- Writes: TpuBlockSpecWorker computes ring rows from (req slot, position) for
  extend (last 256 positions of each request) and verify commit instead of the
  full-to-SWA map; a newly placed or retracted request restarts its ring at its
  cached prefix (encoder_swa_reset), since replayed rows never reach the draft.
- Reads: the draft backend's SWA table maps every logical page to the slot's
  ring and floors visibility at valid_from.
- Sizing: the TPU request-window price includes the draft ring pages; the
  0-token SWA floor skip also applies to the draft worker.
JamesBrianD added a commit to sgl-project/sglang-torchtpu that referenced this pull request Nov 19, 2026
)

* [TPU] DSV4.1 CED: keep the DSpark draft SWA in a per-request ring

Under --enable-encoder-swa-bounded-replay the TPU DSpark draft kept paged SWA
through the target's full-to-SWA mapping, so the target kept its paged SWA
allocator, the radix tree kept tracking SWA, and a partial prefix hit whose SWA
was freed matched 0 tokens. The draft now keeps its SWA in a per-request ring,
as core DSparkWorkerV2 since sgl-project/sglang#44673, and TPU stops forcing
uses_draft_swa_ring() off.

- Pool: the draft SWA pool takes the request window's ring layout (4 x 64-token
  pages per slot after the reserved pages) and keeps swa_req_ring_valid_from on
  the host for the attention backend.
- Writes: TpuBlockSpecWorker computes ring rows from (req slot, position) for
  extend (last 256 positions of each request) and verify commit instead of the
  full-to-SWA map; a newly placed or retracted request restarts its ring at its
  cached prefix (encoder_swa_reset), since replayed rows never reach the draft.
- Reads: the draft backend's SWA table maps every logical page to the slot's
  ring and floors visibility at valid_from.
- Sizing: the TPU request-window price includes the draft ring pages; the
  0-token SWA floor skip also applies to the draft worker.

* [TPU] DSV4.1 draft ring: pick verify commit rows on device

The verify commit built draft ring rows from the host committed base, which
trails the device seq_lens by one commit under overlap, so accepted draft KV
landed one commit early (C64 accept length 4.32 -> 3.75). Map the whole
[base, base + 2 * capacity) candidate window to ring rows on the host and let
select_verify_rows pick the active rows on device, as the full-to-SWA path does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [TPU] DSV4.1 draft ring: count the ring draft layers in a TPU hook, not a core edit

DSV4PoolConfigurator.__init__ keeps the draft ring layer count as a local.
Promoting it to an attribute was the only change this PR made under
python/sglang/srt. An AROUND hook on __init__ now sets draft_ring_layers on
the configurator by core's rule (and checks it against paged_draft_layers),
so get_tpu_dsv41_swa_fixed_bytes can price the ring pages without the edit.

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek jit-kernel memory-pool run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant