Skip to content

[Fix][DCP] Localize widened KV ids in MLA retraction CPU backup/restore - #39487

Merged
ShangmingCai merged 9 commits into
sgl-project:mainfrom
kpham-sgl:kpham/dcp-retraction-cpu-copy
Sep 15, 2026
Merged

ShangmingCai merged 9 commits into
sgl-project:mainfrom
kpham-sgl:kpham/dcp-retraction-cpu-copy

Conversation

@kpham-sgl

@kpham-sgl kpham-sgl commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Fixes #38645 (related draft: #38790). On a PD decode node with --dcp-size > 1, retract_decode backs up the retracted request's KV through MLATokenToKVPool.get_cpu_copy, which indexes kv_buffer with the widened req_to_token ids. Ids past this rank's rows trip a CUDA device-side assert; in-range ones back up and restore the wrong token's row.

Modifications

  • HostKVCache.maybe_dcp_kernel_indices moves to layers/dcp/layout.py as a pure function maybe_dcp_kernel_indices(indices, dcp_size, dcp_rank) next to the other DCP index math; the HiCache MLA host pool and the PD retraction path both call it. Its whole-widened-page assert is dropped because a retracted prefix (seqlen - 1 tokens) is ragged; the strided select only needs the run to start page-aligned. test_ragged_run_is_rejected goes with it.
  • MLATokenToKVPool.get_cpu_copy / load_cpu_copy run their ids through it with dcp_size = _write_loc_dcp_span, so the unified pool's already-physical ids (write_loc_is_dcp_resolved) pass through untouched. Mamba/KDA state indices are not touched.
  • Regression cases added to test/registered/unit/mem_cache/test_decode_retraction_backup.py: the DCP backup/restore round-trip fails on main with an out-of-range row index, and the resolved-pool case guards against double translation.

Testing

  • CPU unit tests: the new TestDcpRetractionBackup cases in test_decode_retraction_backup.py pass here and the round-trip case fails on main; test_hicache_dcp_host_pool.py index cases pass.
  • 4xB200, Kimi-Linear-48B-A3B, PD TP2 prefill -> TP2/DCP2 decode (tokenspeed_mla, fp8 KV, page 64), forced retraction via SGLANG_TEST_RETRACT=1 SGLANG_TEST_RETRACT_INTERVAL=6 on the decode node, 48 concurrent requests x 256 tokens, decode --max-total-tokens 122880 so widened ids exceed the per-rank row count:
    • main (433c999): CUDA index out of bounds device-side assert in MLATokenToKVPool.load_cpu_copy on the first round (~12 retractions in).
    • this branch: repeated 2-3 round runs, ~140-200 retractions each, no assert, all requests completed; per-token logprob delta vs a no-retraction reference within the batch-composition noise of a no-retraction rerun.
  • Not addressed here: with forced retraction some resumed requests (~4/48 per round) degenerate into token repetition. This reproduces identically with --dcp-size 1 on the same PD setup, so it is a separate retraction issue, not DCP.

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ❌ Run #34913372976
Latest PR Test (Extra): ❌ Run #34913372667
Latest PR Test (AMD ROCm 10): ❌ Run #34913372787

…store

`MLATokenToKVPool.get_cpu_copy` / `load_cpu_copy` indexed `kv_buffer` with
the widened `req_to_token` ids under DCP, so decode retraction on a DCP > 1
PD decode node read past this rank's rows (device-side assert) or copied the
wrong token's row. Keep the ids this rank owns and collapse them to rows,
following the pool's existing `write_loc_is_dcp_resolved` contract so the
unified pool's physical ids pass through untouched.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@github-actions github-actions Bot added the hicache Hierarchical Caching for SGLang label Sep 15, 2026
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/unit/mem_cache/test_hicache_dcp_host_pool.py test/registered/unit/mem_cache/test_decode_retraction_backup.py test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_dcp.py test/registered/disaggregation/test_kimi_linear_pd_dcp4.py test/registered/e2e/disaggregation/test_kimi_linear_pd_dcp4_dspark.py

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/unit/mem_cache/test_hicache_dcp_host_pool.py test/registered/unit/mem_cache/test_decode_retraction_backup.py test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_dcp.py test/registered/disaggregation/test_kimi_linear_pd_dcp4.py test/registered/e2e/disaggregation/test_kimi_linear_pd_dcp4_dspark.py:

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/mem_cache/test_hicache_dcp_host_pool.py

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

cd test/ && python3 registered/unit/mem_cache/test_decode_retraction_backup.py

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

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

🚀 8-gpu-b200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/disaggregation/test_kimi_linear_pd_dcp4.py
cd test/ && python3 registered/e2e/disaggregation/test_kimi_linear_pd_dcp4_dspark.py

@kpham-sgl kpham-sgl changed the title [BugFix][DCP] Localize widened KV ids in MLA retraction CPU backup/restore [Fix][DCP] Localize widened KV ids in MLA retraction CPU backup/restore Sep 15, 2026

@ShangmingCai ShangmingCai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This minor fix looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hicache Hierarchical Caching for SGLang memory-pool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][DCP][PD Disagg] Decode retraction crashes in get_cpu_copy with CUDA device-side assert

2 participants