Skip to content

[Feat] kimi-k3.1: DSPARK and DFLASH under decode context parallelism - #48739

Merged
kpham-sgl merged 13 commits into
sgl-project:mainfrom
kpham-sgl:kpham/k31-dcp-spec-verify
Nov 7, 2026
Merged

kpham-sgl merged 13 commits into
sgl-project:mainfrom
kpham-sgl:kpham/k31-dcp-spec-verify

Conversation

@kpham-sgl

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

Copy link
Copy Markdown
Collaborator

Original authors: @yhyang201

Stacks on #48721. The diff includes #48721 until it merges; the commits of this PR start at "Raw port of DSPARK and DFLASH under DCP".

Port of #48414

On top of the Kimi-K3.1 DCP decode runtime (#48721), this ports the branch's speculative decoding under DCP. DSA target verify attends over each rank's shard and returns (o, lse) partials for the existing DCP merge, as decode does. The indexer scores each verify row's local share of its causal length; on SM100, DG-native paged MQA logits read a request's index-K once for all of its draft rows. The Kimi-K3.1 DCP override admits DSPARK (static ragged verify, decode attention mode) and DFLASH (cutedsl_mla draft backend, decode attention mode). DFLASH MLA drafts are no longer rejected under DCP: they run the target's DCP decode path. The target's pool budget charges the DFLASH draft KV once per draft pool row per target row, not per widened location (#64 on the branch).

Against the raw port (first commit), the draft-backend check reads the draft config through main's get_config / parse_dflash_draft_config(...).is_mla instead of the branch's is_dflash_mla_draft_config. Only cutedsl_mla is admitted as an MLA-only DFLASH draft backend; the branch also admits trtllm_mla, which needs the sliding-window draft table work. For the draft KV budget, the branch's mla_draft_rows_are_dcp_collapsed predicate and its resolver are replaced by main's rule. draft_loc_space_scale(hf_config=, use_mla_backend=, dcp_size=) now holds KVCacheConfigurator.loc_space_scale's draft rule; the target-side configurator resolves dflash_draft_loc_space_scale from the draft model config with it. _dflash_draft_cell_size and the layer-count fallback scale the draft by that instead of attn_dcp_size. API changes for the branch's callers: _dflash_draft_loc_scale / dflash_draft_rows_dcp_collapsed become KVCacheConfigurator.dflash_draft_loc_space_scale.

Not taken, because main's design covers it: the branch's DCP-collapsed draft row layout (draft_mla_rows_are_physical, mla_draft_rows_are_dcp_collapsed). On main, mla_attention_dcp_size already keeps a DCP-executing MLA draft on per-rank rows (loc_space_scale == 1).

Left for later ports:

  • Sliding-window MLA drafts on trtllm_mla / cutedsl_mla under DCP.
  • The context-split verify indexer and the DCP top-k merge split mode; their only caller is the megakernel verify path.
  • EAGLE3 MLA drafts under DCP.
  • PD and HiCache under DCP.

Modifications

  • dsa_backend.py: target verify under DCP skips the prefill KV gather and asks _forward_flashmla_kv for a partial. Verify rows get this rank's local lengths, laid out [B, next_n] for DG-native. The captured-verify DG-native refresh stays off under DCP.
  • dsa_indexer.py: DG-native paged MQA logits for DCP verify on SM100.
  • kimi_k3.py override: DSPARK and DFLASH rules in the DCP branch of _kimi_k31_overrides. PD, HiCache, HiSparse and prefill CP stay rejected.
  • speculative_hook.py, draft_worker_common.py: cutedsl_mla is a DFLASH draft backend for MLA drafts.
  • models/dflash.py: drop the --dcp-size > 1 rejection of MLA drafts.
  • kv_cache_configurator.py, pool_configurator.py: the DFLASH draft KV is charged at cell_size * dflash_draft_loc_space_scale: 1 for an MLA draft that executes DCP, attn_dcp_size for a draft that spans the widened locs. Before, it was always attn_dcp_size.

Tests

Static checks: pre-commit and ruff --select F on the touched files. test_pool_configurator.py covers the draft charge at loc_space_scale 1 and 8 and draft_loc_space_scale itself; it has not been run yet (pending a /rerun-test). GPU validation owed: Kimi-K3.1 TP8 / DCP8 with DSPARK (SGLANG_RAGGED_VERIFY_MODE=static) and with an MLA DFLASH draft on B300, checking accept length and GSM8K (sgl-eval) against DCP1.


CI States

Latest PR Test (Base): ⏳ Run #42339255226
Latest PR Test (Extra): ⏳ Run #42339255042
Latest PR Test (AMD ROCm 10): ⏳ Run #42339255091

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

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

…oject#48414

Copy the speculative hunks of the Kimi-K3.1 Day-0 branch's DCP runtime
onto the DCP decode port as they are: DSA target verify returns per-rank
partials, the verify rows' local lengths (DG-native on SM100), the
DSPARK and DFLASH branches of the Kimi-K3.1 DCP override, and DFLASH MLA
drafts on the MLA-only draft backends under DCP. Follow-up commits adapt
it to main.
kpham-sgl and others added 9 commits November 6, 2026 01:27
…sl_mla

- The draft-backend check loads the draft config with get_config and
  reads parse_dflash_draft_config(...).is_mla, as main's trtllm_mha
  check does, instead of the source's is_dflash_mla_draft_config.
- Only cutedsl_mla is an MLA-only DFLASH draft backend here; trtllm_mla
  needs the sliding-window draft table work that is not ported.
- The DFlashMLAAttention comment points at mla_attention_dcp_size, which
  keeps a DCP MLA draft on per-rank owner rows on main.


Copy the Kimi-K3.1 Day-0 branch's DFLASH draft KV budget under DCP as it
is: the target's pool budget charges a draft whose MLA rows stay per
rank once per target row, not per widened location. A follow-up commit
adapts it to main's loc_space_scale rule.
The target's pool budget charged the DFLASH draft KV at attn_dcp_size
times its cell size, as if the draft pool always spanned the widened
locs. On main an MLA draft that executes DCP (mla_attention_dcp_size)
keeps per-rank rows, so its loc_space_scale is 1 and the charge was
dcp_size times too high.

- draft_loc_space_scale(hf_config=, use_mla_backend=, dcp_size=) holds
  KVCacheConfigurator.loc_space_scale's draft rule; the draft property
  calls it, and the target-side configurator resolves
  dflash_draft_loc_space_scale from the draft model config with it.
- _dflash_draft_cell_size and the layer-count fallback scale the draft by
  dflash_draft_loc_space_scale instead of attn_dcp_size.
- Drop the source's mla_draft_rows_are_dcp_collapsed predicate and its
  resolver; main's rule replaces them.
- The unit test covers both scales and draft_loc_space_scale itself.
sgl-project#48721 dropped its target-verify branches and moved the sharded-mode
checks to dsa_shards_index_k. Restore verify on top of that shape:
- the paged top-k and the k-only path take target-verify rows;
- prefill gathers KV only outside target verify;
- the merge sizes rows by draft tokens;
- the verify-only sites test dsa_shards_index_k instead of the DCP width.
The Kimi-K3.1 DCP override admits DSPARK (static ragged verify) and
DFLASH (cutedsl_mla draft) inline, with decode attention mode for verify.
…ckend check

Main moved sglang.srt.utils.hf_transformers to sglang.srt.hf_transformers (sgl-project#48758).
@kpham-sgl
kpham-sgl force-pushed the kpham/k31-dcp-spec-verify branch from ffb95fb to 1699dd3 Compare November 6, 2026 09:28
@sgl-project sgl-project deleted a comment from github-actions Bot Nov 6, 2026
@kpham-sgl kpham-sgl added run-ci CI: run the baseline test suite on this PR run-ci-nv-extra CI: NVIDIA/shared Extra suite (requires run-ci) labels Nov 6, 2026
@kpham-sgl

kpham-sgl commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci one

@kpham-sgl kpham-sgl added the bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) label Nov 6, 2026
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/unit/model_executor/test_pool_configurator.py

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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

cd test/ && python3 registered/unit/model_executor/test_pool_configurator.py  # base-a

@kpham-sgl kpham-sgl added the highest-priority CI: all three control labels, plus never batch-cancelled or stale-closed label Nov 7, 2026
…cp-spec-verify

# Conflicts:
#	python/sglang/srt/layers/attention/dsa_backend.py
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author
Image

@kpham-sgl
kpham-sgl merged commit 709b8b3 into sgl-project:main Nov 7, 2026
46 of 50 checks passed
EricKing626 added a commit to EricKing626/sglang that referenced this pull request Nov 9, 2026
Two conflicts, both against the kimi-k3.1 DCP work that landed on 11-06.

sgl-project#48739 widened the absorbed-MLA gather to skip target-verify, where a
sharded index-K now keeps its per-rank partials. The gathered-prefill
override is a different route and the two cannot both be on: the route
is planned only when index-K is replicated. Keep both, ours first, and
keep the dcp_gathered local the rest of the method reads.

sgl-project#48740 added dcp_push_combine_fits and dcp_push_combine_reduce to the
layers.dcp import in forward_mla, next to is_dsa_dcp_gathered_prefill.
Take the union.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) deepseek highest-priority CI: all three control labels, plus never batch-cancelled or stale-closed memory-pool run-ci CI: run the baseline test suite on this PR run-ci-nv-extra CI: NVIDIA/shared Extra suite (requires run-ci) speculative-decoding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants