Skip to content

[Perf] dsa: Native-head FlashMLA and a precomputed schedule for DCP decode - #49980

Merged
kpham-sgl merged 2 commits into
mainfrom
kpham/port-k31-flashmla-dcp
Nov 12, 2026
Merged

kpham-sgl merged 2 commits into
mainfrom
kpham/port-k31-flashmla-dcp

Conversation

@kpham-sgl

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

Copy link
Copy Markdown
Collaborator

Original authors: @BBuf, @yhyang201

Port of #48414

sgl-flash-mla 1.0.4 (#49362) runs the SM100 legacy sparse decode at any head count in [1, 128], but the DSA backend still pads q to 64 or 128 heads, so Kimi-K3.1's 96 heads (and the 12 a TP8 rank keeps) run padded. #48721 left this out because the kernel was not on main yet. This PR ports the two FlashMLA pieces of the Kimi-K3.1 Day-0 branch's DCP decode path:

  • Native heads. flashmla_kv runs the real head count on SM100 when the installed wheel supports it, and pads as before otherwise.
  • Precomputed DCP decode schedule. A DCP rank's split-KV schedule depends on its topk_length, so it is rebuilt on every call. It now comes from the scheduler kernel's windowed schedule (on main since [Feat] dsa: Kernel prerequisites for a DCP-sharded indexer #48501) instead of FlashMLA's own scheduling launch.

Against the raw port (first commit):

  • _dcp_flashmla_sched_meta gets the empty schedule through _call_get_mla_metadata, the hook hardware backends override, instead of calling get_mla_metadata directly.
  • A test line that set _flashmla_kv_pad_q_in_place, a field this PR does not port, is dropped; one comment is shortened.

Left for later ports: the zero-padded q buffer written in place (_flashmla_kv_q, only used where padding remains) and absorbing q under the indexer, which builds on it.

Modifications

  • _flashmla_kv_padded_heads picks the head count flashmla_kv runs; flashmla_kv_num_q_heads and flashmla_kv_num_q_heads_prefill use it.
  • _maybe_precompute_flashmla_sched_meta takes a schedule argument, accepts native head counts, and sizes the schedule with sparse_decode_num_sm_parts when the wheel has native heads.
  • _forward_flashmla_kv under DCP calls _dcp_flashmla_sched_meta. Where the scheduler kernel does not apply, the schedule stays empty and FlashMLA schedules itself, as before.

Two things to review:

  • Native heads applies to every model on the flashmla_kv DSA path on SM100, not only Kimi-K3.1. The Day-0 branch only exercised Kimi-K3.1.
  • The windowed schedule splits the KV differently from FlashMLA's, so DCP decode outputs can differ in the last bits from before.

Tests

  • New test_native_heads_schedule_and_output (SM100, 12 and 96 heads): the precomputed schedule matches FlashMLA's own, outputs are bit-identical to the padded run, and a captured graph recomputes the schedule when topk_length changes.
  • Not run yet: static checks only (pre-commit, ruff --select F). GPU validation owed: this test, and Kimi-K3.1 TP8 / DCP8 on B300 before and after.

CI States

Latest PR Test (Base): ❌ Run #43133315952
Latest PR Test (Extra): ❌ Run #43133315886
Latest PR Test (AMD ROCm 10): ❌ Run #43133315919

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 repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@BBuf

BBuf commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

[BBuf Review Agent] Could you add before/after numbers with hardware and workload?

@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test registered/kernels/ops/attention/test_flashmla_sched_meta.py

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🚀 4-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/attention/test_flashmla_sched_meta.py  # base-b-kernel-unit

@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

Accuracy check on GB300 (2 trays, 2x4 GPUs), Kimi-K3.1, TP8 / DCP8 / EP2, FP8 KV, --dcp-comm-backend fi_a2a, --max-running-requests 64. Both arms ran back to back on the same two nodes in one job, with sgl-flash-mla 1.0.4 and sgl-deep-gemm 0.2.7 (the versions pinned in pyproject.toml).

Arm GSM8K AIME26 pass@1 (avg of 8) AIME26 pass@8 / majority@8
PR head b977e02 98.50% 100.00% 100% / 100%
Merge base 254d397 99.00% 99.17% +/- 1.54% 100% / 100%
  • GSM8K: sgl-eval 0.1.3, 200 examples, temperature 1.0, top_p 0.95, max_tokens 16384. The 0.5 point gap is one example out of 200.
  • AIME26: sgl-eval 0.1.3, --load-preset-from-model-id moonshotai/Kimi-K3, 8 repeats (240 samples), 64 threads, max_tokens 100000. The gap is 2 samples out of 240.
  • Error rate and truncated rate are 0% in all four runs; no server exception in either arm.

The differences are within sampling noise at temperature 1.0, so I see no accuracy change from this PR in this configuration.

The native-head path was active for the PR arm: on this GPU (SM 10.3, is_sm100 true) supports_native_heads() is true and _flashmla_kv_padded_heads returns 12 for 12 heads and 96 for 96, where the base pads to 64 and 128.

Also ran test/registered/kernels/ops/attention/test_flashmla_sched_meta.py from the PR head on one GB300 GPU: 256 passed, including the new test_native_heads_schedule_and_output.

Not covered: B300, performance before and after, and other models on the flashmla_kv DSA path.

@kpham-sgl
kpham-sgl merged commit 175ab80 into main Nov 12, 2026
114 of 132 checks passed
@kpham-sgl
kpham-sgl deleted the kpham/port-k31-flashmla-dcp branch November 12, 2026 03:24
hnyls2002 added a commit that referenced this pull request Nov 12, 2026
# Conflicts:
#	python/sglang/srt/layers/attention/dsa_backend.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants