Repository navigation
[Feat] dflash: Enable FA3 draft KV rings and NIXL PD transfer - #48842
Conversation
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
34b0200 to
7e38b17
Compare
|
Thanks for the PR and the detailed validation results! Two concerns:
|
ShangmingCai
left a comment
There was a problem hiding this comment.
Thanks for the detailed write-up and the numbers. I read through the whole diff; the ring math itself looks right to me and I did not find a new correctness bug in the enabled path. However, main now has a per-request DFLASH draft ring (speculative/dflash_draft_ring.py, #49664 / #50740 / #49665 / #51386). It covers MLA + MHA drafts on trtllm_mla / cutedsl_mla / trtllm_mha / fa4 and PD over Mooncake, opt-in with SGLANG_ENABLE_DFLASH_DRAFT_KV_RING=1. What it does not cover is exactly this PR's niche: the fa3 draft backend and NIXL. Merging this as-is gives us two ring layouts, two state types (DRAFT_WINDOW / DRAFT_RING), two flags and two budget charges for one feature. I would much rather see this rebased as "add set_draft_kv_ring to FA3 + DRAFT_RING to NIXL maybe_send_extra + drop the mooncake-only reason in draft_kv_ring_unsupported_reason". Most of the PD plumbing here (bootstrap layout negotiation, is_abort_release_safe gating, slot-reuse events) then goes away because the ring already handles the floor via req_generation.
| @@ -162,6 +162,10 @@ class Spec(msgspec.Struct): | |||
| resolvable=True, | |||
| ), | |||
| ] = None | |||
| speculative_draft_window_kv: A[ | |||
There was a problem hiding this comment.
This overlaps with speculative_dflash_draft_kv_ring on main (resolved from SGLANG_ENABLE_DFLASH_DRAFT_KV_RING). Two user-facing switches for a per-request draft ring is going to confuse people, and the two resolve independently per PD role, which is exactly the mismatch #51386 just fixed. Please fold this into the existing ring resolution instead of a second flag.
There was a problem hiding this comment.
Agreed. Removed --speculative-draft-window-kv and the separate resolution path. Both PD roles now use the existing SGLANG_ENABLE_DFLASH_DRAFT_KV_RING resolution.
| ) | ||
|
|
||
|
|
||
| @dataclass(frozen=True) |
There was a problem hiding this comment.
New containers go through msgspec.Struct (.claude/rules/no-dataclasses.md), not @dataclass. frozen=True + __post_init__ map directly.
There was a problem hiding this comment.
Removed this dataclass along with the custom layout implementation. The PR now reuses the upstream ring directly, so no replacement container is needed.
| @@ -357,6 +359,7 @@ def __init__( | |||
| self.kv_layout = args.kv_layout | |||
| self.dsv41_spec_layout = get_dsv41_spec_layout(args) | |||
| self.spec_kv_layout = get_spec_kv_layout(args) | |||
| self.draft_window_kv_layout = getattr(args, "draft_window_kv_layout", None) | |||
There was a problem hiding this comment.
KVArgs declares draft_window_kv_layout in this PR, so this should be args.draft_window_kv_layout. The getattr only hides a rename.
There was a problem hiding this comment.
Removed this custom field and its getattr access. NIXL now uses the upstream ring state and existing transfer metadata.
| @@ -1818,6 +1818,25 @@ def setup_state_kv_args( | |||
| if isinstance(owner_view, DeepSeekV4TokenToKVPool) | |||
| else None | |||
| ) | |||
|
|
|||
| if getattr(draft_token_to_kv_pool, "draft_window_size", None) is not None: | |||
There was a problem hiding this comment.
draft_window_size / draft_window_layout are monkey-patched onto the MHATokenToKVPool instance in dflash_worker_v2.py and then sniffed with getattr here, in prefill.py, decode.py and kv_pool_runtime.py. Please declare them on the pool (default None) and do a plain is not None check, or better, pass the layout in explicitly the way setup_state_kv_args takes the ring on main.
There was a problem hiding this comment.
Followed the explicit-ring approach you suggested. Removed the custom pool attributes and their layout-detection checks; state registration now follows the upstream setup_state_kv_args ring path.
| raise ValueError( | ||
| "Draft window KV requires contiguous NHD BF16 or tensor-scaled FP8 storage" | ||
| ) | ||
| pool.draft_window_size = window |
There was a problem hiding this comment.
Same as above: these two assignments turn the pool into an ad-hoc bag. Declare the attributes on the pool class.
There was a problem hiding this comment.
Removed both custom assignments. The worker now uses the existing upstream ring object without adding layout attributes to the KV pool.
| @@ -2686,7 +2786,28 @@ def forward_batch_generation( | |||
| ) | |||
|
|
|||
| seq_lens_cpu = self._draft_seq_lens_cpu_buf[:bs] | |||
| if self.use_compact_draft_cache: | |||
| window_layout = self.draft_window_layout | |||
There was a problem hiding this comment.
This read is unconditional, and self.draft_window_layout is only set in __init__ / alloc_memory_pool, so test_dflash_draft_graph_eligibility.py (fixture via object.__new__) now dies with AttributeError before it reaches the draft runner. Already reported above; still open at 7e38b17.
There was a problem hiding this comment.
Removed the custom draft_window_layout read and updated the fixture for the current upstream worker. The existing test now covers both full-history and ring modes, including graph admission and preservation of the ring write locations. The regression tests pass.
| @@ -3142,7 +3143,29 @@ def maybe_send_extra( | |||
| ) | |||
| dst_lids = dst_state_layer_ids[i] if i < len(dst_state_layer_ids) else [] | |||
|
|
|||
| if st == StateType.MAMBA: | |||
| if st == StateType.DRAFT_WINDOW: | |||
There was a problem hiding this comment.
Main already has DRAFT_RING handling for Mooncake in this dispatch's sibling. If this lands on top of the ring, this branch becomes "NIXL sends DRAFT_RING flat with force_flat=True" and nothing else here is new.
There was a problem hiding this comment.
Implemented this using upstream DRAFT_RING and REQUEST_ROW state with force_flat=True, including the request’s window floor. The NIXL path also validates row counts, buffer layouts, and attention TP compatibility for paged MHA rings.
|
|
||
| if is_retracted and ( | ||
| dsv4_needs_rebootstrap(self.token_to_kv_pool_allocator) | ||
| or uses_draft_window_kv() |
There was a problem hiding this comment.
This makes every decode retraction a full re-prefill under the flag, and backup_kv_cache aborts anything that is not resumable_by_rebootstrap. That is a user-visible behavior change for an opt-in memory optimization. Main's ring instead resets the request's window floor on resume and just loses acceptance for a few steps. Why not do the same here?
There was a problem hiding this comment.
Agreed. Removed the custom re-prefill behavior and reused upstream ring generation/floor handling on resume. This PR no longer introduces a separate retraction policy.
| if dsv4_needs_rebootstrap(token_to_kv_pool_allocator): | ||
| from sglang.srt.mem_cache.draft_window import uses_draft_window_kv | ||
|
|
||
| if dsv4_needs_rebootstrap(token_to_kv_pool_allocator) or uses_draft_window_kv(): |
There was a problem hiding this comment.
See the decode.py comment: with this clause a retracted non-resumable request is aborted rather than backed up. Needs at least a doc line, but I think the floor reset is the right fix.
There was a problem hiding this comment.
Removed this additional abort condition. Backup and recovery now follow the upstream behavior, including its existing ring-floor handling.
|
@ShangmingCai Thanks for the detailed feedback. I agree that extending the existing upstream draft ring is preferable to maintaining a parallel implementation. I’ll rework this PR around FA3 and NIXL support for DRAFT_RING, reuse the existing configuration and lifecycle handling, and address the test coverage and retraction concerns. |
|
/tag-and-rerun-ci |
7e38b17 to
38265a9
Compare
|
@ShangmingCai @JustinTong0323 |
|
/approve-ci |
@JustinTong0323 |
|
/tag-and-rerun-ci |
|
/rerun-failed-ci |
|
Hi @JustinTong0323 @ShangmingCai , the reworked PR now passes CI, including the required pr-test-finish check. Could you take another look and approve/merge it if everything looks good? Thanks! |
|
/tag-and-rerun-ci |
…ksum guard test_dflash_draft_graph_eligibility.py was deleted on main by sgl-project#53964 and came back through the merge; it exercises main's ring routing, not this change. KvChecksumComputer.for_kv_args already leaves the ring entries out on every transport, so NIXL needs no extra rejection of --disaggregation-enable-kv-checksum. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
/tag-and-rerun-ci |
|
@claude review |
There was a problem hiding this comment.
I reviewed the reworked version of this PR and didn't find any bugs. It adds a new NIXL transfer path for draft-ring state and has CODEOWNERS on both the nixl and speculative directories, so a maintainer should still look at it.
What was reviewed:
- The new
DRAFT_RING/REQUEST_ROWbranch inNixlKVManager.maybe_send_extra. It skips empty PP-stage components, checks that MHA attention TP sizes match, and checks index lengths, pointer counts and item lengths. DCP non-owner rows are dropped throughdraft_kv_ring_row_pairsbefore the flat send.REQUEST_ROWwas also removed from the path that pairs by state TP. - The ring gating in
dflash_draft_ring.py(fa3 added to the MHA backends, nixl accepted) and the new docs section, which match the code. - One mismatch with the description: it says NIXL draft rings are rejected together with
--disaggregation-enable-kv-checksum, but nothing in this diff or indraft_kv_ring_unsupported_reason/pd_disaggregation_hook.pyadds that check. The docs don't mention it either.
Extended reasoning...
The change adds a NIXL transfer branch for DFlash draft KV ring state in nixl/conn.py, allows fa3 and nixl in the ring gating in dflash_draft_ring.py, rewords one error message, and adds docs and unit tests. It touches no auth, crypto or data-exposure surface. I deferred because the transfer path is new and has CODEOWNERS, and because a CHANGES_REQUESTED review from another reviewer still stands in the timeline. The checksum rejection the description promises is not in the code.
|
/tag-and-rerun-ci |
Motivation
With FA3 draft attention and NIXL PD, draft KV storage still scales with target KV capacity even when the draft model uses sliding-window attention. This consumes memory that could otherwise hold target KV.
The original version of this PR implemented a separate draft window pool that overlapped with #49664 and #49665. Since those PRs merged first, this PR has been reworked to reuse their upstream draft KV ring implementation and extend support to FA3 draft attention and NIXL PD.
Modifications
DRAFT_RINGandREQUEST_ROWstate, including draft KV data and each request's window floor.--disaggregation-enable-kv-checksum, since the current checksum does not cover draft ring rows and their window floor.Enable
SGLANG_ENABLE_DFLASH_DRAFT_KV_RING=1on both prefill and decode servers.Request-private ring-buffer example (window = 4):
Each request owns a ring of physical KV rows. Old rows are reused as the window advances; logical token positions continue increasing. For paged rings, NIXL transfers the request's ring block together with the window floor that determines its logical interpretation.
Accuracy Tests
Speed Tests and Profiling
KV allocation on 4 × H200 per server, DFlash block size 8, FP8 target/draft KV, native draft attention window 2,048 tokens:
Decode is configured for 132 running requests and 6 PD extra slots. Each request's draft ring has 2,560 positions, including alignment and execution margin; the allocation totals also include reserved/padding rows. Target KV retains full history, and its capacity is not multiplied by TP size.
No material throughput regression was observed in the tested workload: enabling the ring changed output throughput by +0.52% at C8 and −0.48% at C32, with TPOT changes below 0.7%.
A/B uses the same seeded GSP requests: nominal 4K input / 2K output, 96.13% measured cache hit, and 256 requests × 2 runs per configuration. Both configurations simulate a commit length of 6 with
real-draft-token; the table reports each configuration's highest-throughput run and its corresponding latency metrics. Accuracy results above use normal acceptance.Reproduction
Single-node 8 × H200: prefill on GPUs 0–3, decode on GPUs 4–7. Run P, D, and Router in separate terminals using the same Python environment and PR checkout.
The commands below enable draft KV rings. For the baseline, set
SGLANG_ENABLE_DFLASH_DRAFT_KV_RING=0in both P and D terminals. Keep all other settings identical, and stop the previous configuration before starting the next one.P, D, and Router launch commands (click to expand)
Run these exports in both P and D terminals. Leave speculative-acceptance simulation variables unset for accuracy evaluation:
Prefill:
Decode:
Router:
GSM8K evaluation command (click to expand)
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): 🚫 Run #46587702268⚠️ Run #46587705323
Latest PR Test (Extra): ⊘ Skipped -- add the
run-ci-nv-extralabel to opt in.Latest PR Test (AMD ROCm 10):
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: