Skip to content

[HiSparse][Kimi K3.1] Support Kimi-K3.1's hybrid KDA + DSA layout - #67262

Open
MatthewBonanni wants to merge 21 commits into
vllm-project:mainfrom
MatthewBonanni:hisparse-kimi-k31
Open

MatthewBonanni wants to merge 21 commits into
vllm-project:mainfrom
MatthewBonanni:hisparse-kimi-k31

Conversation

@MatthewBonanni

@MatthewBonanni MatthewBonanni commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Purpose

HiSparse doesn't start on Kimi-K3.1 on main. This PR makes it start and serve correctly with pages offloaded to host, without using more GPU KV memory per request than serving without HiSparse.

Repro on main (4×B200):

vllm serve vllm-project/Kimi-K3.1-Pro-pruned75 -tp 4 --trust-remote-code \
  --max-model-len 20480 --max-num-seqs 64 \
  --attention-config '{"hisparse_config":{}}' \
  --kv-transfer-config '{"kv_connector":"HiSparseConnector","kv_role":"kv_both","kv_connector_extra_config":{"host_pool_gib":64}}'
ValueError: A model-declared get_kv_cache_groups cannot be combined with HiSparse, which owns its own KV cache grouping. Remove one of them.

Changes

Starting and serving

  • With HiSparse on, its grouping replaces a model-declared one instead of raising. K3's GQA-draft grouping, the only model grouping, already defers to the default under the block-outermost layouts HiSparse requires.
  • K3.1's indexer no longer reads its group's slot mapping, which HiSparse leaves all padding because the indexer is self-addressed ([Core][Kimi K3.1] Write draft KV at block-stride slots instead of translating slot mappings #66604); every write was skipped (passkey 10/64). It now derives DCP ownership from token position and rank, the rule the slot mapping encodes. DeepSeek-V4 and the shared indexer are unchanged.

GPU memory per request

  • Every HiSparse group block costs a whole pool row, so the layout picks the row that minimizes device bytes per request: the smallest row the indexer and a hot layer fit in, or a whole number of KDA states above it, with KDA groups split to fit. K3.1 TP4 lands on 5 KDA states per row (8.15 MB).
  • Capacity checks and reported concurrency count max(resident window, hot + active tail) instead of their sum: when a request's hot region is allocated, the reclaim hook ([Bugfix][HiSparse] Reclaim resident pages before allocating the next prefill chunk #67185) releases its clean resident blocks, so it never holds both for long.
  • Keep the 2304-token block when the indexer is self-addressed and every sparse backend supports it.
  • When the attention backend needs smaller blocks (FlashMLA fp8: 64 tokens), a resident or hot block holds as many consecutive 64-token host pages as fit in its row, instead of spending a whole row on one page. Host transfers stay per page; a block is released once all its pages are on host. A prefix hit ending inside a block allocates that block and restores its hit pages from host. The default config is unchanged (one page per block).

Manager-block view (vllm/v1/worker/utils.py): the view used to zero freed blocks is now exactly a manager block's kernel blocks ([..., kernel_blocks, kernel_rows, C]). Rounding a page that ends mid-row up to whole rows ran past the pool and crashed startup.

FlashMLA fp8 KV (flashmla_sparse.py): the fp8 kernel reads KV as 64-token pages, so it now declares MultipleOf(64) block-stride alignment on SM100 as it already does elsewhere. HiSparse's 64-token hot blocks sit at arbitrary row strides in the shared pool, which caused an illegal memory access on K3.1's first host read. Non-HiSparse K3.1 fp8 TP4 is unaffected: 39,149,568 bytes per block before and after.

Test Plan

Server: the repro command with --gpu-memory-utilization 0.80; for FlashMLA add --kv-cache-dtype fp8 --attention-backend FLASHMLA_SPARSE --gpu-memory-utilization 0.88.

  • Passkey: 192 prompts of 18,049 tokens, 32 at a time, alongside 64 long-decoding requests; host reads confirmed by vllm:hisparse_host_to_device_bytes_total.
  • GSM8K 5-shot, 1319 questions: python tests/evals/gsm8k/gsm8k_eval.py --port 8000.
  • Capacity: KV cache size and max concurrency vLLM reports at startup.
pytest tests/v1/core/test_kv_cache_utils.py tests/v1/core/test_kv_cache_planning.py tests/v1/core/test_prefix_caching.py tests/v1/kv_connector/unit/test_hisparse_connector.py tests/v1/worker/test_utils.py tests/v1/attention/test_sparse_mla_backends.py -k hisparse
pytest tests/v1/core/test_kv_cache_config_builder.py tests/v1/worker/test_attn_utils.py tests/v1/attention/test_sparse_mla_kv_cache_layout.py
pytest tests/v1/attention/test_indexer_deepseek_v4_slot_mapping.py tests/v1/worker/test_attn_utils.py \
  tests/benchmarks/test_forward_cli.py -k "not bench_forward and not balanced_routing"   # 1x B200

Test Results

Accuracy (TP4)

GPUs Setup Passkey GSM8K Read from host
4×B300 no HiSparse (main) 192/192 0.357
4×B200 HiSparse 192/192 0.364 959 GB (passkey), 74 GB (GSM8K)
4×B200 HiSparse, FlashMLA fp8 KV 192/192 0.362 1016 GB (passkey), 0 (GSM8K fits on GPU)

GSM8K scores are for the 75%-pruned test checkpoint; CI's threshold for Kimi-K3-pruned75 on the same eval is 0.33.

Passkey runs alongside 64 long-decoding requests, so passkey requests move to their hot regions and read from host; alone, every prompt fits its resident window and nothing is read from host.

Capacity (4×B200, 20k-token requests, GPU KV memory per request at admission)

no HiSparse (main) HiSparse
Default KV (block 2304) 0.66 GiB 0.66 GiB (87 blocks × 8.15 MB); startup concurrency 5.89×
FlashMLA fp8 KV (64-token pages, 8 per block) doesn't start on K3.1 0.68 GiB (90 blocks × 8.15 MB); startup concurrency 26.56×

GLM-5.3-Flash (4×B200, TP4, HiSparse, --gpu-memory-utilization 0.80): same device pool as main (60,381 blocks, 62.7 GiB). Reported max concurrency rises from 189× to 213× because a request no longer counts its resident window and hot region together.

Note: with a small fixed pool (--num-gpu-blocks-override or --kv-cache-memory-bytes), CUDA graph capture fails with HiSparse layer 0 mirrored twice, also on main.


Pull Request Checklist
  • I used vLLM's /pr-checklist skill. (Mandatory for agents, optional for humans).

  • AI assistance was used during the creation of this PR.

  • Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.

  • Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.

  • Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.

  • Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.

🤖 Generated with Claude Code

HiSparse shrank the MLA specs to the kernel block, so K3.1's 69 KDA
state layers sized every device row (one 112 MB group) and admission
fell to ~3x vs 34x without HiSparse. Keep the scheduler's packed block,
split state groups to fit the indexer row, and align hot pages to kernel
rows instead of whole pages. HiSparse now owns grouping over a
model-declared grouping instead of rejecting it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
SelfAddressedMLASpec declares the indexer needs no slot mapping, but its
builder still read the group's slot mapping as a PAD mask. HiSparse puts
the indexer in its own group, whose slot mapping is then disabled, so
every indexer write was dropped. Let self-addressed callers pass no slot
mapping and take DCP ownership from the rank instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@mergify mergify Bot added the deepseek Related to DeepSeek models label Nov 12, 2026
@MatthewBonanni MatthewBonanni changed the title [HiSparse] Support Kimi-K3.1's hybrid KDA + DSA layout [HiSparse][Kimi K3.1] Support Kimi-K3.1's hybrid KDA + DSA layout Nov 12, 2026
@MatthewBonanni
MatthewBonanni marked this pull request as ready for review November 12, 2026 18:21

@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.

Shrink HiSparse MLA specs to the common kernel block unless the indexer is
self-addressed and every sparse attention backend supports the scheduler
block. Expose the hot buffer as exact-length kernel pages and pass that page
size to the sparse MLA hot-cache kernels. Size state-group splits by their
largest page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
…ecewise steps

MRv2 passed attn_metadata to the KV connector's pre_forward only for FULL
CUDA graph steps. On piecewise and eager steps HiSparse skipped its
per-forward setup, and models whose attention layers do not prepare HiSparse
themselves (Kimi-K3.1) overflowed the swap rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@mergify mergify Bot added the mrv2 Model Runner V2 specific label Nov 12, 2026
MatthewBonanni and others added 2 commits November 13, 2026 09:32
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
…n pages on SM100

The quantized kernel reads 64-token pages on every platform. Declaring
MultipleOf(64) keeps HiSparse hot caches, whose block stride is otherwise
only row-aligned, readable as whole pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@mergify mergify Bot removed the needs-rebase label Nov 13, 2026
A padded indexer page that is not whole rows cannot be viewed as manager
blocks: the row view of the last indexer layer ran past the pool block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@mergify

mergify Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @MatthewBonanni.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Nov 13, 2026
MatthewBonanni and others added 3 commits November 16, 2026 17:03
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
The K3.1 indexer's slot-mapping kernel variant (no group slot mapping)
is now registered for JIT warmup, and dcp_rank is no longer specialized,
so every DCP rank shares one compiled kernel. A builder-level test pins
that K3.1 writes at block-table slots when its group's slot mapping is
all padding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@mergify mergify Bot removed the needs-rebase label Nov 16, 2026
MatthewBonanni and others added 2 commits November 16, 2026 23:23
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
…w pages

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@mergify mergify Bot added the performance Performance-related issues label Nov 17, 2026
…dget

- Pick the pool row that minimizes device bytes per request.
- Release clean resident blocks before allocating the hot region; count
  the peak of the two, not their sum, in capacity checks.
- Pack consecutive host pages into each resident and hot block when the
  backend needs smaller blocks than the row fits (FlashMLA fp8), with
  per-page host transfers and restores of a prefix hit's partial block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
@mergify

mergify Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @MatthewBonanni.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Nov 19, 2026
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>

# Conflicts:
#	vllm/v1/attention/backends/mla/index_group.py
#	vllm/v1/hisparse/binding.py
#	vllm/v1/hisparse/coordinator.py
#	vllm/v1/hisparse/layout.py
@mergify mergify Bot removed the needs-rebase label Nov 24, 2026
@mergify

mergify Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @MatthewBonanni.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Nov 24, 2026
MatthewBonanni and others added 3 commits November 24, 2026 16:04
Upstream's reclaim hook already releases them once the hot region exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>

# Conflicts:
#	tests/v1/core/test_prefix_caching.py
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>

# Conflicts:
#	vllm/v1/hisparse/coordinator.py
@MatthewBonanni

Copy link
Copy Markdown
Member Author

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #105730 for commit 841f8cb37291.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>

This branch has not been deployed

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

Labels

deepseek Related to DeepSeek models hisparse Related to HiSparse kimi kv-cache-manager kv-connector mrv2 Model Runner V2 specific nvidia performance Performance-related issues

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant