Repository navigation
[Mamba] Fix checkpoint depth for prefixes that end off the radix page - #39115
Conversation
… prefix is off the tree page With DCP the allocator and radix-tree page widen (e.g. 64 -> 512) while PrefillAdder still aligns chunk budgets to the scheduler page, so a prefill chunk can end at 64. `cache_unfinished_req` inserts nothing for that chunk (no Mamba checkpoint yet, key shorter than a page) and leaves `prefix_indices` at 64. The next extend then measures the checkpoint depth relative to the prefix: 64 + floor(540 / 512) * 512 = 576, a position no 512-token page can name. On finish the Mamba component truncates the insert to 576 while the radix key is page-floored to 512, and the two freed kv-row tails [512, 576) and [576, 605) share a page (`_page_disjoint` assertion); without the assertion the tree would hold a 576-token Mamba state on a 512-token node. Pick the depth on the absolute checkpoint grid instead and donate only where an h snapshot exists ((depth - prefix) % cache_chunk_size == 0). Extends that cross no page boundary, or whose prefix is off the kernel chunk grid, donate nothing. Unit test: one table-driven case; three of its four rows fail before this change.
|
@codex review |
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. |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
|
/rerun-failed-ci |
| mamba_track_seqlen = len(req.prefix_indices) + req.extend_range.length | ||
| mamba_track_seqlen = seq_end | ||
|
|
||
| # mamba_track_seqlen_aligned/mamba_last_track_seqlen is actual tracked seqlen. Used to pass to |
There was a problem hiding this comment.
let's update the comments as well.
[Unified Cache][9/N] add opt-in MLA load deduplication for Mooncake Linker. Squashes 5 upstream commits (cc4431b, 455f5bb, 310b76e, 8acfd72, d52e749 — three of them merge-main commits whose only net effect on this PR's files is what lands below). New opt-in flag --enable-linker-mla-dedup: with the Mooncake external linker, rank 0 loads replicated MLA KV from L3 and broadcasts each layer to the other TP ranks instead of every rank reading the same objects. Files: - python/sglang/srt/arg_groups/fields/memory.py: add enable_linker_mla_dedup. - python/sglang/srt/arg_groups/hicache_hook.py: require the Mooncake linker. - python/sglang/srt/mem_cache/unified_cache/linker_mla_dedup.py (new): LinkerMLADedupBroadcaster, adapting hybrid device-pool geometry to the existing MLAHostDedupBroadcaster primitive. - python/sglang/srt/mem_cache/storage/mooncake_store/mooncake_direct_linker.py: LayerWiseLoadCounter on_layer_ready hook; broadcaster construction; per-batch logical-plan all_gather gate; rank-0-only load queueing; forward-stream broadcasts; broadcast-completion event tracking in num_completed_loads; reset/close teardown. - test/registered/unit/server_args/test_server_args.py: flag validation test. Manual merge notes: - Our fork's mooncake_direct_linker.py carries fork-local behavior (fail-soft revalidate_load, retrying session start, SGLANG_LINKER_DEBUG_KEY probes, idx-checksum probe, rank-key handling). All of it is preserved untouched; the upstream hunks apply around it (imports, LayerWiseLoadCounter, __init__ broadcaster wiring, num_completed_loads, start_layer_wise_loading, load_thread_func, reset/close). - The upstream branch was based on main before sgl-project#39835/sgl-project#39115/sgl-project#37474; those are unrelated to this PR's files (verified by diffing the PR range against the merge base), so the squash is a faithful net port. - Depends on MLAHostDedupBroadcaster and attn_tp_cache_group/tp_cache_group in CacheInitParams, both already present in our base (upstream parent == ours).
[Unified Cache][9/N] add opt-in MLA load deduplication for Mooncake Linker. Squashes 5 upstream commits (cc4431b, 455f5bb, 310b76e, 8acfd72, d52e749 — three of them merge-main commits whose only net effect on this PR's files is what lands below). New opt-in flag --enable-linker-mla-dedup: with the Mooncake external linker, rank 0 loads replicated MLA KV from L3 and broadcasts each layer to the other TP ranks instead of every rank reading the same objects. Files: - python/sglang/srt/arg_groups/fields/memory.py: add enable_linker_mla_dedup. - python/sglang/srt/arg_groups/hicache_hook.py: require the Mooncake linker. - python/sglang/srt/mem_cache/unified_cache/linker_mla_dedup.py (new): LinkerMLADedupBroadcaster, adapting hybrid device-pool geometry to the existing MLAHostDedupBroadcaster primitive. - python/sglang/srt/mem_cache/storage/mooncake_store/mooncake_direct_linker.py: LayerWiseLoadCounter on_layer_ready hook; broadcaster construction; per-batch logical-plan all_gather gate; rank-0-only load queueing; forward-stream broadcasts; broadcast-completion event tracking in num_completed_loads; reset/close teardown. - test/registered/unit/server_args/test_server_args.py: flag validation test. Manual merge notes: - Our fork's mooncake_direct_linker.py carries fork-local behavior (fail-soft revalidate_load, retrying session start, SGLANG_LINKER_DEBUG_KEY probes, idx-checksum probe, rank-key handling). All of it is preserved untouched; the upstream hunks apply around it (imports, LayerWiseLoadCounter, __init__ broadcaster wiring, num_completed_loads, start_layer_wise_loading, load_thread_func, reset/close). - The upstream branch was based on main before sgl-project#39835/sgl-project#39115/sgl-project#37474; those are unrelated to this PR's files (verified by diffing the PR range against the merge base), so the squash is a faithful net port. - Depends on MLAHostDedupBroadcaster and attn_tp_cache_group/tp_cache_group in CacheInitParams, both already present in our base (upstream parent == ours).
[Unified Cache][9/N] add opt-in MLA load deduplication for Mooncake Linker. Squashes 5 upstream commits (cc4431b, 455f5bb, 310b76e, 8acfd72, d52e749 — three of them merge-main commits whose only net effect on this PR's files is what lands below). New opt-in flag --enable-linker-mla-dedup: with the Mooncake external linker, rank 0 loads replicated MLA KV from L3 and broadcasts each layer to the other TP ranks instead of every rank reading the same objects. Files: - python/sglang/srt/arg_groups/fields/memory.py: add enable_linker_mla_dedup. - python/sglang/srt/arg_groups/hicache_hook.py: require the Mooncake linker. - python/sglang/srt/mem_cache/unified_cache/linker_mla_dedup.py (new): LinkerMLADedupBroadcaster, adapting hybrid device-pool geometry to the existing MLAHostDedupBroadcaster primitive. - python/sglang/srt/mem_cache/storage/mooncake_store/mooncake_direct_linker.py: LayerWiseLoadCounter on_layer_ready hook; broadcaster construction; per-batch logical-plan all_gather gate; rank-0-only load queueing; forward-stream broadcasts; broadcast-completion event tracking in num_completed_loads; reset/close teardown. - test/registered/unit/server_args/test_server_args.py: flag validation test. Manual merge notes: - Our fork's mooncake_direct_linker.py carries fork-local behavior (fail-soft revalidate_load, retrying session start, SGLANG_LINKER_DEBUG_KEY probes, idx-checksum probe, rank-key handling). All of it is preserved untouched; the upstream hunks apply around it (imports, LayerWiseLoadCounter, __init__ broadcaster wiring, num_completed_loads, start_layer_wise_loading, load_thread_func, reset/close). - The upstream branch was based on main before sgl-project#39835/sgl-project#39115/sgl-project#37474; those are unrelated to this PR's files (verified by diffing the PR range against the merge base), so the squash is a faithful net port. - Depends on MLAHostDedupBroadcaster and attn_tp_cache_group/tp_cache_group in CacheInitParams, both already present in our base (upstream parent == ours).
Motivation
With DCP the radix-tree page is wider than the scheduler page (e.g. 512 vs 64), so a prefill chunk can leave
prefix_indicesat 64 with no node inserted. The next extend picks the Mamba checkpoint depth relative to that prefix,64 + 512 = 576, a position no 512-token page can hold. On finish the two freed kv-row tails[512, 576)and[576, 605)share a page and the scheduler dies:Without the assertion the node would carry a Mamba state 64 tokens past its end. Reproduced on Kimi-K3 with
--dcp-size 8and radix cache on.Modifications
_mamba_radix_cache_v2_req_prepare_for_extendpicks the depth on the absolute checkpoint grid and donates only where an h snapshot exists ((depth - prefix_len) % cache_chunk_size == 0).Accuracy Tests
test/registered/unit/managers/test_mamba_checkpoint_depth.pygains one table-driven case (prefix off the widened page, short extend crossing a page, extend crossing no page, prefix off the kernel chunk grid). Three of its four rows fail on main and pass with this change. Kimi-K3 dcp=8 agentic serving with the radix cache runs to completion instead of crashing.Speed Tests and Profiling
Not affected: a few scalar ops per request at batch preparation.
Checklist
CI States
Latest PR Test (Base): 🚫 Run #35121066591
Latest PR Test (Extra): 🚫 Run #35121066143
Latest PR Test (AMD ROCm 10): ❌ Run #35121066600