Skip to content

[Feat] hisparse: Support Kimi-K3.1 DSA layers on PD decode with DFLASH - #50005

Merged
kpham-sgl merged 5 commits into
sgl-project:mainfrom
alphabetc1:port-k31-hisparse
Nov 12, 2026
Merged

kpham-sgl merged 5 commits into
sgl-project:mainfrom
alphabetc1:port-k31-hisparse

Conversation

@alphabetc1

@alphabetc1 alphabetc1 commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Port of the HiSparse part of #48414 to main.

Kimi-K3.1 rejects --enable-hisparse on main. This enables HiSparse on the PD decode instance for K3.1's DSA layers, including DFLASH speculative decoding up to block size 8. The KDA recurrent state stays on GPU and is transferred as usual.

The speculative swap kernel half of the change (2-8 steps, up to 16384 occurrences) is already on main from #49411.

Modifications

  • Server args: K3.1 accepts --enable-hisparse on CUDA. The DSA backend must be flashmla_kv; trtllm is rejected, since it is not on the HiSparse FP8 allow-list. ROCm still rejects it. DCP and the decode radix cache stay rejected with HiSparse by the existing checks.
  • KV pool: with HiSparse on, the hybrid linear pool builds its DSA sub-pool as HiSparseDSATokenToKVPool (forwarding host_to_device_ratio) and forwards the HiSparse mapping and translation API to it, as MiniMaxSparseKVPool does for its main pool.
  • Coordinator: get_hisparse_kvcache() returns the dense DSA sub-pool of a hybrid linear pool, and swap_in_selected_pages maps the model layer id to the sub-pool's layer index. The spec swap limits read SPEC_SWAP_MAX_STEPS / SPEC_SWAP_MAX_OCCURRENCES from the kernel module instead of the stale 4 / 8192.
  • DFLASH: verify calls prepare_spec_verify once the verify locs are assigned, and commit_spec_accept_tokens after accept, with accept indices in the EAGLE topk-1 layout.
  • Spec allow-list: DFLASH joins HISPARSE_VALIDATED_SPEC_ALGORITHMS (added on main by [Feat] hisparse: reject unvalidated speculative algorithms by name #48846), since its worker now binds the HiSparse verify slots. This applies to every DSA model; only Kimi-K3.1 was run end to end.
  • Retraction: a retracted HiSparse decode request goes back to the prefill (rebootstrap), as DeepSeek-V4 already does. The HiSparse allocator has no host-copy path. dsv4_needs_rebootstrap is renamed to retraction_needs_rebootstrap.
  • Docs: Kimi-K3.1 section in the HiSparse guide.

Differences from the branch:

  • The branch picks the device pool inside the coordinator; main already has get_hisparse_kvcache() on the allocator, so the hybrid case goes there.
  • The branch's DFLASH draft KV ring sizing change is not needed: on main the ring branch already precedes the HiSparse draft sizing.

Tests

  • test_hisparse_pool_mapping.py: a hybrid linear pool resolves to its DSA sub-pool.
  • test_hisparse_allocator.py: a HiSparse allocator needs rebootstrap on retraction.
  • test_model_overrides.py: K3.1 with HiSparse defaults to flashmla_kv and rejects trtllm.
  • test_server_args.py: HiSparse accepts DFLASH and still rejects an unvalidated algorithm.
  • Each new test fails when its source change is reverted.
  • CPU: the touched test files (148 passed) and the HiSparse / DFLASH / server-args unit files (503 passed, 2 skipped) pass.
  • GPU (1x B300): test_hisparse_unit.py, test_hisparse_spec_coordinator.py and kernels/ops/kvcache/test_hisparse*.py give the same pass and skip counts as main (51 passed, 10 skipped).

End to end

Kimi-K3.1 1P1D on 4 GB300 nodes at 8b10ec7 (this PR before the merge of main): prefill TP8, decode TP8 with DFLASH block 8 and --enable-linear-replayssm-spec, Mooncake over InfiniBand, --hisparse-config '{"top_k":2048,"device_buffer_size":4096,"host_to_device_ratio":4}'. The baseline is the same decode without --enable-hisparse, behind the same prefill. sgl-eval 0.1.3.

Eval HiSparse Baseline
gsm8k, 200 examples (T=1.0, top_p 0.95, thinking, max_tokens 16384) 99.0% 98.5%
ruler2 32K, 240 examples (T=1.0, top_p 0.95, no thinking, max_tokens 256) 75.5% 76.2%
ruler2 32K, 240 examples (greedy, max_tokens 512; A/B only) 81.7% 80.7%
  • No request errors and no exceptions in the server logs in either arm. DFLASH accept length 4.55 with HiSparse, 4.50 without.
  • The decode differs from the cookbook's GB300 decode recipes, which all run DCP: HiSparse rejects DCP, so it runs TP8 without it.
  • The end-to-end commit predates [Feat] hisparse: reject unvalidated speculative algorithms by name #48846, so the allow-list change is covered by the unit test only; the head after merging main has not been rerun end to end.
  • Not covered: retraction of a HiSparse decode request (the rebootstrap path) did not occur in these runs.

CI States

Latest PR Test (Base): ⏳ Run #43177167348
Latest PR Test (Extra): ❌ Run #43177167024
Latest PR Test (AMD ROCm 10): ⏳ Run #43177167260

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.

@mintlify

mintlify Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 3476e85.

Approve preview

@github-actions github-actions Bot added documentation Improvements or additions to documentation memory-pool labels Nov 12, 2026
@alphabetc1 alphabetc1 added the run-ci CI: run the baseline test suite on this PR label Nov 12, 2026
@alphabetc1 alphabetc1 added bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) highest-priority CI: all three control labels, plus never batch-cancelled or stale-closed labels Nov 12, 2026
@huangtingwei9988 huangtingwei9988 self-assigned this Nov 12, 2026
@huangtingwei9988

Copy link
Copy Markdown
Collaborator

There is a draft KV memory-accounting gap in the newly enabled DFLASH + HiSparse PD path:

  • KVCacheConfigurator._init_pools() allocates the dense draft pool with allocator.size_full rows, including the host_to_device_ratio expansion.
  • _dflash_draft_cell_size() accounts only for the DCP scale and does not include the HiSparse ratio.
  • The adjacent EAGLE sizing path already accounts for this expansion.

For example, with host_to_device_ratio=4 and N target physical rows, sizing charges for N draft rows while allocation creates 4N. The missing budget is (ratio - 1) × N × draft_bytes_per_row.

This can make automatic sizing exceed the intended memory budget and cause an OOM during draft pool initialization. The ring path does not avoid this issue: DFLASH draft KV rings are currently disabled for PD disaggregation.

Please make the DFLASH memory charge match the host-expanded address space and add a sizing regression test with host_to_device_ratio > 1.

I verified the accounting mismatch through code inspection and an isolated execution of the sizing helper; I have not reproduced a GPU OOM.

@kpham-sgl
kpham-sgl merged commit 56005a5 into sgl-project:main Nov 12, 2026
149 of 163 checks passed
@alphabetc1
alphabetc1 deleted the port-k31-hisparse branch November 12, 2026 08:59
qidaye added a commit to qidaye/sglang that referenced this pull request Nov 12, 2026
sgl-project#50005 makes a retracted request on a HiSparse decode pool go back to the
prefill (retraction_needs_rebootstrap), but no test runs that path on the
decode side. Before it, the cpu_tensor backup reached
HiSparseTokenToKVPoolAllocator.get_cpu_copy and raised NotImplementedError.

Check that backup_kv_cache and DecodePreallocQueue.add agree on which pools
recompute (HiSparse and DeepSeek-V4 do, a host-copy pool does not), and that
a HiSparse request the prefill cannot rebuild is not resumed.

Refs sgl-project#40729

Signed-off-by: Jianliang Qi <[email protected]>
mlleo added a commit to mlleo/sglang that referenced this pull request Nov 12, 2026
Resolves conflicts with sgl-project#50005 (Kimi-K3.1 DSA DFLASH) and the main-side
hisparse gate tests: keep the branch's wiring comments and the stricter
unvalidated-algorithm rejection test alongside main's spec-validation
tests.
hnyls2002 added a commit that referenced this pull request Nov 12, 2026
# Conflicts:
#	python/sglang/srt/managers/hisparse_coordinator.py
#	python/sglang/srt/mem_cache/kv_cache_configurator.py
#	python/sglang/srt/speculative/dflash_worker_v2.py
#	test/registered/unit/mem_cache/test_hisparse_allocator.py
Yuening-wa added a commit to Yuening-wa/sglang that referenced this pull request Nov 19, 2026
…id pools

The DSA backend passes a model layer id to the HiSparse swap-in, while the
device and host buffers hold only the layers of this pipeline-parallel
stage, or only the full-attention layers of a hybrid model.

main (sgl-project#50005) maps hybrid pools through `_pool_layer_index` inside
`swap_in_selected_pages`. This branch added a second entry point,
`swap_in_selected_dsa_pages`, that subtracted the stage's start layer and
range-checked against the device pool before calling it. After merging
main the two stack: for a hybrid pool the dense full pool starts at 0 and
has fewer layers than the model, so the range check rejects most layers.

Keep one entry point and one table. `_pool_layer_index` now also covers a
plain DSA pool on a stage with start_layer > 0, and is applied once at the
top of `swap_in_selected_pages`. `swap_in_selected_dsa_pages` is removed
and the DSA backend call sites match main again. DeepSeek-V4 (callers pass
the compressed pool's layer index), MiniMax M3 (`swap_in_selected_blocks`)
and stage 0 are unchanged.

The test drives the real swap-in down to the kernel boundary and checks
which layer's buffers it reaches, for PP stages, hybrid pools on stage 0
and on a later stage, and DeepSeek-V4.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
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) documentation Improvements or additions to documentation 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants