Skip to content

[Feat] dflash: Serve sliding-window MLA drafts on trtllm_mla and cutedsl_mla - #49110

Closed
kpham-sgl wants to merge 6 commits into
sgl-project:mainfrom
kpham-sgl:kpham/k31-dflash-mla-swa-draft
Closed

kpham-sgl wants to merge 6 commits into
sgl-project:mainfrom
kpham-sgl:kpham/k31-dflash-mla-swa-draft

Conversation

@kpham-sgl

@kpham-sgl kpham-sgl commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Original authors: @yhyang201

Port of #48414

A DFLASH MLA draft whose layers are all sliding_attention (the Kimi-K3.1 DFlash2 SWA drafts) cannot run under Kimi-K3.1 DCP on main: the K3.1 override requires --speculative-draft-attention-backend cutedsl_mla with DCP + DFLASH, while DFlashMLAAttention accepts only triton for sliding layers. It also resolved the draft backend without algo_label="DFLASH", so a requested cutedsl_mla silently became flashinfer in that check. This PR ports the Day-0 window path that serves these layers on the MLA-only draft backends:

  • mla_window_sparse_indices lists, per query row at position p, this rank's keys in [p - window_left, p].
  • trtllm_mla (and cutedsl_mla, which inherits its target-verify path) runs a sliding layer through trtllm-gen sparse MLA over those lists (_forward_sliding_window). Under DCP it returns the rank-local (out, lse) for the existing merge, with the LSE base each backend declares (dcp_lse_base_on_e).
  • The DFLASH draft backend resolver admits trtllm_mla / cutedsl_mla for MLA drafts (DFLASH_MLA_ONLY_DRAFT_BACKENDS), and --speculative-draft-window-size is resolved against the draft's own window on those backends (_resolve_dflash_mla_draft_window).

Against the raw port (first commit):

  • Main's _parse_dflash_is_mla stays; is_dflash_mla_draft_config is a thin entry over it.
  • SGLANG_OPT_DFLASH_SWA_SKIP_LSE defaults off (its Day-0 default reads an env var main does not have).
  • The window indices are built from req_to_token without a draft KV ring.
  • DFlashMLAAttention keeps main's sliding-layer check, widened to triton, trtllm_mla and cutedsl_mla, and resolves the backend with algo_label="DFLASH".

Left for later ports: the draft KV ring (dflash_draft_ring.py; the window kernel keeps its ring arguments), L2 prefetch, simulated acceptance, the fused candidate all-gather, the grouped-conv kernel, the megakernel pre-built FP8 query, and SGLANG_TRTLLM_MLA_WORKSPACE_MB.

Modifications

  • kernels/ops/attention/mla_window_indices.py: per-row window key indices, DCP owner filtering.
  • layers/attention/trtllm_mla_backend.py, cutedsl_mla_backend.py, dsa/dsa_dcp.py: the sliding-window target-verify path and its LSE handling.
  • speculative/dflash_utils.py, speculative/draft_worker_common.py, arg_groups/speculative_hook.py, models/dflash.py, environ.py: draft backend admission and compact-window resolution.

Tests

  • Ported: test_mla_window_indices.py (kernel), test_dflash_mla_draft_window.py; test_dflash_mla.py now checks the three window backends. None has run yet.
  • Static checks: ruff check --select F,E9, ruff format, and pre-commit on the touched files.
  • GPU validation owed: Kimi-K3.1 TP8/DCP8 with the SWA DFlash2 draft on cutedsl_mla, GSM8K via sgl-eval, plus acceptance length against the same draft on triton without DCP.

CI States

Latest PR Test (Base): ❌ Run #42435247021
Latest PR Test (Extra): ❌ Run #42435246838
Latest PR Test (AMD ROCm 10): ❌ Run #42435246935

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

kpham-sgl and others added 6 commits November 7, 2026 17:27
…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: the per-row window index kernel
(mla_window_sparse_indices), 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.

Co-authored-by: Yuhao Yang <[email protected]>
…_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.
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

Accuracy at #49110 merged with #48741 (7221465fa2): Kimi-K3.1 PD under DCP with the sliding-window DFlash2 MLA draft (5 sliding_attention layers, window 1024) on --speculative-draft-attention-backend cutedsl_mla, GB300.

Prefill Decode GSM8K Accept len
TP8, DCP1 TP8 / DCP8 98.5% 3.65
TP8 / DCP8 TP8 / DCP8 98.0% 3.67

Same setup and eval as #48741 (comment) (sgl-eval 0.1.3 GSM8K, 200 examples, temperature 1.0, top_p 0.95). Accept len is the decode server's logged mean over batches of 8 or more running requests.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants