Repository navigation
[Feat] dflash: Send the draft KV ring over PD disaggregation (Mooncake) - #49665
Merged
hnyls2002 merged 94 commits intoNov 12, 2026
Merged
Conversation
…d cutedsl_mla from sgl-project#48414 Copy the Day-0 hunks that serve a DFLASH MLA draft's sliding_attention layers on the MLA-only draft backends: trtllm_mla's sliding-window verify path over trtllm-gen sparse MLA (with the rank-local LSE under DCP), the MLA-only draft backend admission, and the compact draft window resolution. The per-row window index kernel (mla_window_sparse_indices) and its test are on main since sgl-project#49411. Co-authored-by: Yuhao Yang <[email protected]>
…rafts Copy the Day-0 hunk that runs DFlashGroupedConv on the Triton dflash_grouped_conv kernel (on main since sgl-project#49411) for 2-D CUDA inputs.
…_draft_config Main's parse_dflash_draft_config reads is_mla through _parse_dflash_is_mla, which accepts a scalar attention_mode without num_hidden_layers. The Day-0 get_dflash_attention_modes rejects that, so restore main's parser and make is_dflash_mla_draft_config, the name the ported hook and window resolution call, a thin entry over it.
Day-0 defaults it to SGLANG_ENABLE_NV_MEGA_RUNTIME_K31_GB_OPTIMIZATION, which main does not have.
The draft KV ring is not ported, so the sliding-window path always reads the draft's keys through req_to_token and the runner's page table.
…layers Day-0 drops the triton-only check and rejects windows in FlashInfer MLA's causal planning, which main replaced with _planned_causal. Keep main's check in DFlashMLAAttention and widen it to the window-capable backends, resolving with algo_label="DFLASH" so an MLA-only backend is not silently replaced by the platform fallback.
…aft comment KVCacheConfigurator.draft_mla_rows_are_physical is Day-0's; on main the draft's row space comes from draft_loc_space_scale.
…layer forward_extend now reads layer.sliding_window_size to pick the window path; the stub layer of the DCP metadata test had none.
The raw port admits trtllm_mla for any MLA draft, including one that inherits it from the target. Its decode kernel has no bidirectional mask, so main falls back to flashinfer there (test_oot_dflash_hooks); keep that fallback and admit trtllm_mla only from --speculative-draft-attention-backend.
…a and cutedsl_mla
# Conflicts: # python/sglang/srt/models/dflash.py
Without the ring transfer a decode server would start with an empty draft window. Resolve the default off with a log line on prefill and decode servers, and refuse an explicit SGLANG_DFLASH_DRAFT_KV_RING=1.
Under --enable-unified-memory the draft runner binds its KV views inside the target's pool (the fused draft placement, which gives sliding-window draft layers their own window band), so there is no private draft pool to size as a ring, and ring locs would index the target's pages.
A draft pool that follows the target's post-capture backing is resized to the target's token count after capture, which would replace the ring's fixed size. The ring is allocated up front instead.
…fill port The raw port brings _has_dflash_draft_kv with Day-0's last-PP-stage clause, which belongs to DFLASH on a pipelined prefill, ported separately. Keep only the ring clause here.
The raw port takes draft rows out of the target's per-token cost but charges the ring itself nowhere, so it is allocated from the activation slack after the target pool. Main charges per-request fixed pools before token sizing (the Mamba state in _profile_available_bytes); charge the ring there too, sized like the draft runner builds it: rows for every req pool row and the pool's padding page, at the draft's resolved bytes per row.
The ring stays on for a sliding-window MLA draft on trtllm_mla and cutedsl_mla, resolves off under PD and unified memory (an explicit 1 there is an error), and is charged as its draft pool while the target's per-token cost drops the draft row.
dflash_ring_block_locs (SGLANG_OPT_DFLASH_RING_LOCS_FUSED) has no test on main; compare it with DFlashDraftKVRing.locs with and without DCP.
…KV ring The draft block now reads DFlashWorkerV2.draft_kv_ring, which the stub built with object.__new__ did not set.
…T_KV_RING The env-var conventions want a verb token. The default stays on, and an explicit 1 where the ring does not fit stays an error. The K3.1 memory calculator reads the new name.
hnyls2002
requested review from
ByronHsu,
Qiaolin-Yu,
alphabetc1,
hanming-lu,
hnyls2002,
huangtingwei9988,
hzh0425,
ispobock,
xiezhq-hermann and
yizhang2077
as code owners
November 12, 2026 07:54
hnyls2002
requested review from
Duyi-Wang,
HaiShaw,
JustinTong0323,
ShangmingCai,
sogalin,
wisclmy0611 and
zijiexia
as code owners
November 12, 2026 07:54
Collaborator
|
/rerun-test registered/unit/mem_cache/test_decode_retraction_backup.py registered/unit/managers/test_priority_scheduling_disaggregation.py registered/ep/test_mooncake_ep_small.py |
Contributor
|
🚀 🚀 🚀 |
hnyls2002
added a commit
that referenced
this pull request
Nov 12, 2026
# Conflicts: # python/sglang/srt/disaggregation/base/conn.py # python/sglang/srt/disaggregation/decode.py # python/sglang/srt/disaggregation/mooncake/conn.py # python/sglang/srt/disaggregation/prefill.py # python/sglang/srt/managers/scheduler.py # python/sglang/srt/speculative/dflash_draft_ring.py # python/sglang/srt/speculative/dflash_worker_v2.py
This was referenced Nov 13, 2026
4 of 5 tasks
5 tasks done
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.
Original authors: @yhyang201
Port of #48414
Builds on #49664 and #49621 (both merged); based on main.
#49664 keeps an all-sliding-window MLA DFLASH draft's KV in a per-request ring of
window + blockrows, but nothing sends the ring between PD peers, so #49664 resolves it off under PD disaggregation and K3.1's PD deployment keeps the per-token draft pool. This takes the PD part of the Day-0 ring (with its later Day-0 fixes), which sends the ring from prefill to decode, so PD gets the same target KV gain (+15.0% target KV on K3.1 colocated, see #49664).Changes against the raw port (the first commit,
[Feat] dflash: Raw port of the draft KV ring's PD transfer from kimi-k3.1-day-0, copies the Day-0 hunks byte for byte; each change below is its own commit):dflash_draft_ring.pykeepsAnyandCallablein itstypingimport next to the PD transfer's names; the ring part of the module ([Perf] dflash: Keep a sliding-window MLA draft's KV in a per-request ring #49664) uses them.speculative_dflash_draft_kv_ring([Perf] dflash: Keep a sliding-window MLA draft's KV in a per-request ring #49664), not from Day-0's env flag.PrefillBootstrapQueue/DecodePreallocQueue, which pass it tosetup_state_kv_argsand read it in their payloads. Day-0's process-wideset_draft_kv_ring/get_draft_kv_ringglobal is not added.setup_state_kv_argsregisters the ring when it is given one and reads no config bag. Day-0's version needed a publishedspecnamespace in every caller (13 existing wire tests failed).mooncake_tcpis rewritten tomooncakebefore resolution). It also resolves off when--disaggregation-decode-host-receive-thresholdis below 1: decode host buffering receives only SWA state. With other transfer backends (NIXL, Mori, Ascend, fake) it resolves off with a log line, because they have noDRAFT_RINGpath. An explicitSGLANG_ENABLE_DFLASH_DRAFT_KV_RING=1there is an error.--disaggregation-enable-kv-checksum):KvChecksumComputerdigested every registered state entry at the request's state indices. For a hybrid (KDA) target, these are the mamba slots, broadcast to all entries. With the ring, it digested ring rows and themin_posrow at mamba slot indices. That read pastmin_pos, and the digest did not match between the peers. On a unified pool, it failed the per-entry length assert.KvChecksumComputer.for_kv_argsnow leaves out exactly the ring's two entries. The ring is not checksummed. The same gap was found in [Feat] dflash: Enable FA3 draft KV rings and NIXL PD transfer #48842's draft-window rows.REQUEST_ROWwrite is the floor's only writer: a local reset there could land after that write underprefill_completeallocation and leave the request with an empty window.state_window_tailsis built, sostate_wirecarries them. Bootstrap then rejects a pair where only one side resolved the ring on, with a message that names the ring andSGLANG_ENABLE_DFLASH_DRAFT_KV_RING.DRAFT_RINGand theREQUEST_ROWfloor as replicated state, like QSA's (_REPLICATED_STATE_TYPES): no KV-head slicing, one elected writer under mixed TP, flat layout. A non-MLA target used to split them as K/V heads. This also covers DSpark'sREQUEST_ROW(its SWA valid-from): under mixed attention TP one prefill rank now writes it, with the flat layout (the same as the MLA path DSV4 already takes), the ruleshould_send_replicated_stateapplies to other replicated state; on main every rank wrote the same value._req_pool_pre_alloc_size).pp_size == 1, so empty-slot registration for a stage without the draft is left for [Feat] dflash: Run DFLASH on a pipelined PD prefill #49648.DRAFT_RINGregistration, not on "zero draft entries" or a global flag. Day-0's condition also let through a DFLASH peer with no draft entries and no ring, which main rejects.SGLANG_ENABLE_NV_MEGA_RUNTIME_OPTIMIZATION) falls back to the blocking path, because the ring's payloads are host arrays. The K3.1 recipes set neither.draft_kv_ring_row_pairs(the row-0 filter) moves out of the Mooncake sender intodisaggregation/utils.pyso it can be unit-tested without importing the speculative module.API changes the source's callers need:
set_draft_kv_ring/get_draft_kv_ringare not added: the scheduler passes the ring toPrefillBootstrapQueue/DecodePreallocQueue, andsetup_state_kv_argstakes adraft_kv_ringargument.speculative_dflash_draft_kv_ring([Perf] dflash: Keep a sliding-window MLA draft's KV in a per-request ring #49664), not fromSGLANG_DFLASH_DRAFT_KV_RING.draft_kv_ring_row_pairsindisaggregation/utils.py(the Mooncake row-0 filter);KvChecksumComputer.for_kv_argsdrops the ring's two entries.DFlashDraftKVRingtakeswindow_left,dcp_rankandpool(required); itsmin_posuses the pool's custom mem pool.Left for #49648: running the ring on a pipelined PD prefill (stages without the draft register empty slots for the ring's entries and are not charged for it).
Modifications
What the PD transfer does:
StateType.DRAFT_RING: one item per ring row. The ring's window floor (min_pos) is sent as the existingREQUEST_ROWstate, one item per req pool row._draft_ring_payloadsendstransfer_rows(slot, seq_len), which is this rank's ring rows of the lastwindow_left + 1positions in position order. Row 0 marks a position that this rank does not own under DCP.setup_state_kv_argsregisters the ring's two entries last on both sides, so they pair by position.DRAFT_RINGis a generic, exactly-matched, replicated state. Pairs where either side has row 0 are dropped. The draft TP-reslice check is skipped, because there are no draft KV entries.min_posis allocated in the KV pools' cuMemCreate pool, because Mooncake's NVLink transport writes it remotely.Dependencies
_charges_dflash_draft_kv_per_token/_dflash_draft_kv_ring_bytes).check_state_wire) with a message that names the ring.Compared with #48842's lifecycle handling
#48842 (NIXL, FA3 drafts, opt-in
--speculative-draft-window-kv) keeps a per-request draft-window ring on decode. It handles these lifecycle cases:SGLANG_DISAGGREGATION_DEFERRED_DECODE_KV_RELEASE).window + blockpositions per rank. Verify writes every block position, and the next block overwrites the rejected ones. [Feat] dflash: Enable FA3 draft KV rings and NIXL PD transfer #48842's partial-commit case comes from its window-only ring.The target model verifies every draft token. So these gaps can lower acceptance length, but they cannot change the output. Ring locs are always in range.
Accuracy and performance
Not run. PD end to end needs two 8-GPU nodes (prefill and decode). Day-0 measured it on the source branch (K3.1, TP8 prefill, DCP8 decode, Mooncake): target KV +15.2%, accept length unchanged within noise. Those numbers are not from this port.
Tests
unit/spec/test_dflash_draft_kv_ring.py(CPU). With DCP 1/8 and 8/8, each decode rank gets exactly the window positions it owns, at the row its own ring locs give. The test also checks the buffer infos (one item per ring row and per req pool row), and the resolution under PD over mooncake (on), over nixl and with decode host receive (off, and an error with an explicit=1).unit/disaggregation/test_disaggregation_wire.py(CPU):setup_state_kv_argsregisters the ring's rows and floor after the storage's entries. Mooncake accepts a ring peer across a TP mismatch, and on a non-MLA target under mixed TP one rank sends the ring entries flat. The existing no-ring rejection still holds.unit/disaggregation/test_unified_window_wire.py: a ring on one side only is rejected with a message naming the ring.unit/disaggregation/test_decode_queue_cleanup.py: decode resets the ring floor for a fake transfer and a resumed request, and never on a real transfer.unit/disaggregation/test_kv_checksum.py:for_kv_argsleaves out the ring's two entries and keeps a non-ringREQUEST_ROW.unit/model_executor/test_pool_configurator.py::TestDflashDraftKvBudget: the ring charge counts the PD decode pre-alloc rows.Local runs before the review fixes (1b4ed1b), 8x B300, one GPU per file:
test_dflash_mla_backends.py3 passed (9 subtests),test_mla_window_indices.py10,test_dflash_ring_locs.py2,test_kv_checksum.py30,test_dcp_lse_combine.py21 passed.test_dflash_draft_kv_ring.py12 (27 subtests),test_disaggregation_wire.py82,test_minimax_sparse_disagg_state_kv_args.py2,test_mooncake_transfer_batching.py21,test_pd_role_switch.py39,test_decode_queue_cleanup.py20,test_pool_configurator.py75,test_oot_dflash_hooks.py7,test_dflash_mla.py8 passed.CI States
Latest PR Test (Base): ⏳ Run #43196938396
Latest PR Test (Extra): ❌ Run #43196938299
Latest PR Test (AMD ROCm 10): ⏳ Run #43196938498
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: