Skip to content

[Feature][HiSparse] Unify Ascend HiSparse across models with GLM-5.3-Flash - #23142

Draft
LZZhang-HW wants to merge 4 commits into
vllm-project:mainfrom
LZZhang-HW:hisparse-multimodel-a5
Draft

LZZhang-HW wants to merge 4 commits into
vllm-project:mainfrom
LZZhang-HW:hisparse-multimodel-a5

Conversation

@LZZhang-HW

@LZZhang-HW LZZhang-HW commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it?

Introduce a unified HiSparse framework for multiple sparse-attention models on Ascend. Models describe their cache roles and physical layouts through cache specs. The shared planner and worker select a compatible layout, then use the same vLLM HiSparse request lifecycle and Ascend device operations. GLM-5.3-Flash on 950DT is the first end-to-end implementation in this PR.

This review candidate includes the GLM A5 implementation from #22772 and targets upstream main directly. The multi-model review diff isolates the framework change.

Shared framework

flowchart TD
    M["Model cache specs<br/>Sparse KV, indexer and recurrent state"] --> B["Ascend layout selection and placement"]
    B -->|"Pooled indexer + FP8 NoPE"| P["Compact KPool and tail ring<br/>Device KDA state groups"]
    B -->|"Native SFA indexer + recurrent state"| N["Native 128-token indexer pages<br/>Independent device state groups"]
    B -->|"Other compatible layouts"| D["Existing Core grouping"]
    P --> C["Core HiSparse lifecycle<br/>Admission, indexing, spill and reuse"]
    N --> C
    D --> C
    C --> W["Ascend binds Host, Resident and Hot caches"]
    W --> T["Device indexer emits logical TopK"]
    T -->|"Resident pages"| A["Paged SFA reads the resident table"]
    T -->|"Missing rows"| R["Resolve physical slots and gather KV into Hot"]
    R --> A2["SFA reads the resolved Hot rows"]
Loading
  • Core ownership. Core supplies cache roles, index groups, the request lifecycle and shared layout planning. On the verified c410543d pin, the Ascend compatibility code covers the pool budget, per-layer views, resident verifier copy deferral and terminal spill publication. vLLM #69247 tracks the corresponding native changes.
  • Ascend ownership. The builder selects a layout from the cache specs and backend capabilities. It derives the packed row width from the attention backend and accounts for the physical device stride. Binding and the device resolver/gather use the selected geometry.
  • GLM-5.3-Flash implementation. DSA declares a pooled FP8 indexer with four tokens per pool entry. Compact KPool keys, FP32 scales and the tail ring stay on device. HiSparse manages the 528-byte NoPE main KV rows while the 34 KDA layers retain six device state groups. Eligible MTP5 verifier steps keep the six-query resident path, and cache misses use the resolver and gather.

Onboarding another model, using Kimi K3.1 as an example

  1. Declare the cache contract. Use the native SFA indexer spec with the INDEXER role, declare the MLA cache as SPARSE, and describe recurrent state with MambaSpec. The attention backend supplies the packed row width. These declarations select the existing native-hybrid layout.
  2. Validate layout and binding. Keep the Indexer key/scale page at 128 tokens and size the KDA checkpoint groups separately on device. Check slot mapping, padding and Host/Resident/Hot views. Kimi's existing paired cache layout applies with HiSparse disabled. The native-hybrid HiSparse route requires speculative decoding to be disabled.
  3. Qualify the model. Run the planner and binding regressions, then check full-model serving, paired accuracy and performance, and real host misses. An additional model-specific implementation is needed only if it introduces a cache format or device operation the shared path cannot express. This PR has CPU coverage for native hybrid layout and binding. Kimi K3.1 full-model NPU evidence remains pending. See the related Kimi K3.1 draft #23038.

Does this PR introduce any user-facing change?

Yes. GLM-5.3-Flash can opt in on the single-node 950DT recipe through the existing attention_config.hisparse_config and HiSparseConnector. The validated GLM configuration uses Model Runner V2, FP8 main and indexer KV, and one rank each for DP, PP, PCP and DCP. Both hybrid layouts require the verified Core main pin with Mamba page fitting. The native hybrid layout uses the same opt-in and has CPU coverage only. The release note is attached to this PR.

How was this patch tested?

GLM-5.3-Flash A5 performance

Both arms used Ascend 84f4196d5, official Core c410543d, the W8A8 MXFP8 checkpoint and 8 × 950DT on one node. The current head adds only test fixtures after the measured runtime. The uninstrumented deployment held the community recipe fixed at TP8/EP, FP8 main and indexer KV, MTP5, prefix caching, FULL_DECODE_ONLY and an 8,192-token chunked-prefill limit. The ordered GSM8K-derived workload used 32,768 input and 1,024 generated tokens. Three rounds of eight requests per arm and concurrency yielded 96/96 completed requests.

Latency and throughput are three-round medians. ITL measures token-bearing streaming intervals. TPOT divides first-to-last token time by the generated token count minus one. MTP acceptance length is one plus accepted draft tokens divided by verifier steps, with counts summed across the three rounds.

Metric C1 OFF C1 ON C1 change C8 OFF C8 ON C8 change
Mean ITL (ms) 19.172 19.142 -0.16% 51.370 52.527 +2.25%
P95 ITL (ms) 19.813 19.956 +0.72% 423.641 434.112 +2.47%
Mean TPOT (ms) 3.990 3.983 -0.16% 11.217 11.546 +2.94%
Output throughput (tokens/s) 170.584 169.529 -0.62% 377.955 368.492 -2.50%
MTP mean acceptance length (tokens) 4.8168 4.8168 +0.00% 4.5865 4.5433 -0.94%
Mean TTFT (ms) 1,920.099 1,965.085 +2.34% 8,809.848 9,033.270 +2.54%

The largest median degradation was 2.34% at C1 and 2.94% at C8. The synthetic answer check scored 18/24 in both C1 arms and 21/24 in both C8 arms, with zero correct-to-incorrect transitions. The timed runs recorded zero HiSparse misses, Host reads and preemptions.

Independent GSM8K accuracy

Two uninstrumented OFF/ON pairs used the same ordered 128 test questions at C8, greedy sampling, seed 1024 and the original exact-match scorer. All requests completed.

Pair OFF ON Correct to incorrect
1 117/128 (91.41%) 118/128 (92.19%) q951 (300 → 150)
2 118/128 (92.19%) 118/128 (92.19%) q951 (300 → 150)

Both ON repeats answered q287 and q505 correctly. The strict per-question gate remains open because q951 changed from correct to wrong in both pairs. Earlier OFF repeats also produced the identical 150 response. The same-mode verifier trace associated q951's first logit differences with different realized batches and located raw mHC divergence between sampled boundaries 8 and 16. The first contributing operator has yet to be isolated.

The earlier two losses were investigated separately. OFF reproduced q287's entire missing-marker completion byte for byte. The output computes 8, then repeats the problem until the 1,024-token limit. For q505, a diagnostic pinned the first 61 generated tokens before allowing the verifier to choose normally. Both arms reproduced 1600 and 1200 with the same target Q6 input and 8 × Q6 FULL shape. The two 1200 responses both selected token 41812 at logit 21.375 over token 220 at 21.250. The peer positions and execution histories differed. The verifier intervention was confined to the diagnostic deployment. Fixed-input A5 QSFA comparisons across paged and physical TND layouts produced bitwise-identical outputs for the tested shapes. These results did not establish an ON-only defect or warrant a production code change.

Prefix hits, cold pages and regression tests

  • OFF and ON returned identical token sequences across four prefix boundaries. At prompt lengths 32,257 and 32,768, both modes reused 32,256 local tokens. Decode TPOT increased by 1.77% and 2.26% on those hits.
  • A prior MTP5 pressure run on the same production code at 32,768 input, 512 output and 512 cache blocks recorded 1,058,848 misses, 559,071,744 Host-to-device bytes and zero preemptions. All eight ranks passed sampled 528-byte row checks for 1,168 rows each. The cold request ran 90 verifications and accepted 424 draft tokens.
  • Community pre-commit and both full CPU suites passed on the current PR head with the verified Core pin and vLLM v0.34.0. The pooled budget and Prefill checkpoint overrides are scoped to the qualified layout. The two new hybrid layouts require Core Mamba cache fitting. Full-model native hybrid NPU coverage remains pending.

Checklist

Testing

  • Boundary / edge-case coverage: Native page geometry, packed width, padding and recurrent-state cases.
  • Regression test: Existing and new tests cover worker spec collection and cache placement.
  • Error / failure path coverage: Invalid pooled layouts and speculative native hybrid configurations are rejected.
  • Meaningful & reliable tests: Tests check real planner and binder behavior.
  • Performance impact: Paired hardware data is above. A dedicated automated benchmark gate is pending.

AI assistance was used and is recorded in the relevant commit trailers.

@github-actions github-actions Bot added documentation Improvements or additions to documentation module:tests module:ops labels Nov 25, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces opt-in HiSparse support for single-node GLM-5.3-Flash inference on Ascend 950DT with FP8 KV cache, implementing layout planning, Flash compatibility adapters, and Triton operator updates. The review feedback focuses on enhancing robustness and memory safety: it recommends consistently using safe getattr calls when accessing attention_config to prevent potential AttributeErrors, defensively guarding against missing builder methods, and utilizing weakref.finalize to avoid potential memory leaks of KVCacheBlocks.

Comment on lines +17 to +19
pool_bytes = builder._get_pool_bytes_per_block(vllm_config, kv_cache_groups)
if pool_bytes is not None:
return pool_bytes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Defensively guard against AttributeError by using getattr to retrieve _get_pool_bytes_per_block from the builder, as the builder class might vary or not implement this method in all contexts.

        pool_bytes_fn = getattr(builder, "_get_pool_bytes_per_block", None)\n        if pool_bytes_fn is not None:\n            pool_bytes = pool_bytes_fn(vllm_config, kv_cache_groups)\n            if pool_bytes is not None:\n                return pool_bytes

Comment on lines +41 to +42
copies = self._terminal_spill_copies.setdefault(id(publication), {})
copies[page_idx] = pending.resident_blocks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Using id(publication) as a key in self._terminal_spill_copies can lead to memory leaks of KVCacheBlocks if the publication object is garbage collected before _publish_detached_blocks is called. Use weakref.finalize to ensure the entry is cleaned up automatically when the publication object is garbage collected.

                import weakref\n                copies = self._terminal_spill_copies.setdefault(id(publication), {})\n                copies[page_idx] = pending.resident_blocks\n                weakref.finalize(publication, self._terminal_spill_copies.pop, id(publication), None)

Comment on lines +258 to +260
if vllm_config.attention_config.hisparse_config is not None and (
pages := _compact_hisparse_kpool_pages(kv_cache_groups)
):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Avoid direct attribute access on vllm_config.attention_config to prevent potential AttributeErrors if attention_config is None or if hisparse_config is missing. Use the safe getattr pattern consistently.

        if getattr(getattr(vllm_config, "attention_config", None), "hisparse_config", None) is not None and (\n            pages := _compact_hisparse_kpool_pages(kv_cache_groups)\n        ):

kv_cache_groups: list[KVCacheGroupSpec],
) -> int | None:
"""Return the device memory cost per global block ID."""
if vllm_config.attention_config.hisparse_config is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Avoid direct attribute access on vllm_config.attention_config to prevent potential AttributeErrors. Use the safe getattr pattern consistently.

Suggested change
if vllm_config.attention_config.hisparse_config is not None:
if getattr(getattr(vllm_config, "attention_config", None), "hisparse_config", None) is not None:

kv_cache_spec: dict[str, KVCacheSpec] = {}
attention_layer_names: list[str] = []
mamba_specs: dict[str, MambaSpec] = {}
hisparse_enabled = vllm_config.attention_config.hisparse_config is not None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Avoid direct attribute access on vllm_config.attention_config to prevent potential AttributeErrors. Use the safe getattr pattern consistently.

Suggested change
hisparse_enabled = vllm_config.attention_config.hisparse_config is not None
hisparse_enabled = getattr(getattr(vllm_config, "attention_config", None), "hisparse_config", None) is not None

not dummy_run
and not is_profile
and isinstance(graph_manager, ModelAclGraphManager)
and self.vllm_config.attention_config.hisparse_config is not None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Avoid direct attribute access on self.vllm_config.attention_config to prevent potential AttributeErrors. Use the safe getattr pattern consistently.

Suggested change
and self.vllm_config.attention_config.hisparse_config is not None
and getattr(getattr(self.vllm_config, "attention_config", None), "hisparse_config", None) is not None

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:‌‌

  • A PR should do only one thing, smaller PRs enable faster reviews.
  • Every PR should include unit tests and end-to-end tests ‌to ensure it works and is not broken by other future PRs.
  • Write the commit message by fulfilling the PR description to help reviewer and future developers understand.

If CI fails, you can run linting and testing checks locally according Contributing and Testing.

🤖 How to trigger CI

CI runs automatically when the PR is opened or reopened. Pushing a new commit no longer re-runs the E2E CI (to save NPU runner resources), so use the comment commands below when needed. They are available to the PR author and users with triage permission or above:

  • /run — run the full PR CI gate on the latest commit.
  • /rerun — re-run the failed CI jobs (e.g. after a flaky failure).
  • /e2e — run selected E2E tests instead of the full gate.
  • /nightly / /presmoke / /weekly — run the corresponding large-scale tests (triage permission or above; blocked during the nightly maintenance window).
  • /cancel — cancel a running CI on this PR.

Note

Until the CI gate has run on a commit, the required ci-gate check stays pending and the PR cannot merge — remember to comment /run after pushing.


Tip

💡 Consider Linking a Related Issue or RFC

Your PR title contains the [Feature] tag, indicating a bug fix or new feature.

Linking a related issue or RFC in the PR description is strongly encouraged — it gives reviewers helpful context and speeds up the review. You can use any of these keywords:

  • Fixes #<issue_number>
  • Closes #<issue_number>
  • Resolves #<issue_number>
  • Refs #<rfc_or_issue_number> (for RFCs)

🙏 Thanks for helping us keep the project well-organized!

@LZZhang-HW LZZhang-HW changed the title [Feature][HiSparse] Select Ascend sparse KV layouts by capability [Feature][HiSparse] Unify Ascend HiSparse across models with GLM-5.3-Flash Nov 25, 2026
@LZZhang-HW

LZZhang-HW commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit a3a28c1894176fc54d9900f3aaf74e9f201e4a31 of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@vllm-ascend-ci vllm-ascend-ci added the ci-run E2E requested manually on the latest commit label Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Last updated: 2026-11-25 12:46 UTC+8 for commit 58b5c4d.

ci-gate failed. Reason:

CODEOWNERS approval gate failed: at least one changed file has no approval from its owner(s). Open the 'CODEOWNERS' steps above to see which files are missing approvals and who can approve.
This PR touches source code (src=true, ci_pipeline=false), so precision/full tests are required before merge. Fix: a maintainer adds the 'ready-precise' label; the workflow reruns automatically once the label is added.

See the workflow run for full logs. This comment is updated in place on each new failure and marked as passed once the gate passes (it is kept for history, not deleted).

Missing owner approvals. Every changed file needs one approval from its CODEOWNERS owner(s):

Unclaimed modules touched (10 files). These files have no CODEOWNERS owner yet, so no approval is required for them; maintainers will handle claiming:

  • vllm_ascend/attention/gdn_attn_builder.py
  • vllm_ascend/attention/sfa_hisparse.py
  • vllm_ascend/hisparse/__init__.py
  • vllm_ascend/hisparse/backend.py
  • vllm_ascend/hisparse/binding.py
  • vllm_ascend/hisparse/c8.py
  • vllm_ascend/hisparse/flash_compat.py
  • vllm_ascend/hisparse/flash_terminal_spill.py
  • vllm_ascend/hisparse/host_mirror.py
  • vllm_ascend/hisparse/layout.py

@LZZhang-HW

LZZhang-HW commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 201675ebe6e051feb0fc1ccd87bc9ba14588f8fc of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@vllm-ascend-ci vllm-ascend-ci added ci-run E2E requested manually on the latest commit and removed ci-run E2E requested manually on the latest commit labels Nov 25, 2026
@LZZhang-HW

LZZhang-HW commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 707a342dd393d2070e4ddb92b785c9afabe0858c of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@vllm-ascend-ci vllm-ascend-ci added ci-run E2E requested manually on the latest commit and removed ci-run E2E requested manually on the latest commit labels Nov 25, 2026
Carry over the GLM target implementation and verified Core compatibility from vllm-project#22772.

Assisted-by: OpenAI Codex
Signed-off-by: LZZhang-HW <239167139+LZZhang-HW@users.noreply.github.com>
Describe sparse KV, indexers and recurrent state with cache specs and use the common Core lifecycle.

Assisted-by: OpenAI Codex
Signed-off-by: LZZhang-HW <239167139+LZZhang-HW@users.noreply.github.com>
Scope scheduler and budget adapters to the qualified configuration, require the Core hybrid layout contract, and cover fallback paths and geometry.

Assisted-by: OpenAI Codex
Signed-off-by: LZZhang-HW <239167139+LZZhang-HW@users.noreply.github.com>
@LZZhang-HW
LZZhang-HW force-pushed the hisparse-multimodel-a5 branch from 707a342 to 84f4196 Compare November 25, 2026 03:59
@LZZhang-HW

LZZhang-HW commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 84f4196d5725b92b15f85318d3acb7b6b0cb64c2 of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@vllm-ascend-ci vllm-ascend-ci added ci-run E2E requested manually on the latest commit and removed ci-run E2E requested manually on the latest commit labels Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Total Coverage Diff Coverage
Total 157196 lines 945 lines
Missing 45008 lines 280 lines
Coverage 71% 70%

More info see: Summary

Keep AST-isolated worker and default-layout tests in sync with the graph manager and attention configuration contracts.

Assisted-by: OpenAI Codex
Signed-off-by: LZZhang-HW <239167139+LZZhang-HW@users.noreply.github.com>
@LZZhang-HW

LZZhang-HW commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 58b5c4de9f4a423388592519e7984302f94fe3b8 of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@vllm-ascend-ci vllm-ascend-ci added ci-run E2E requested manually on the latest commit and removed ci-run E2E requested manually on the latest commit labels Nov 25, 2026

@zhenwenqi2024 zhenwenqi2024 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we keep one native-hybrid planner across this PR and #23038? Both add the same layout entry points, but this branch has the stronger Core capability and recurrent-spec checks. I'd keep those here and reuse test_cold_mixed_prefill_masks_padded_topk from #23038 rather than rebuilding that fixture. Please rerun #23038's A3 INT8 C8 host-refill workload on the resulting shared revision before marking Kimi qualified here; its standalone result does not cover this planner.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

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

ci-run E2E requested manually on the latest commit documentation Improvements or additions to documentation merge-conflicts module:ops module:tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants