Repository navigation
[Feature][HiSparse] Unify Ascend HiSparse across models with GLM-5.3-Flash - #23142
LZZhang-HW wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
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.
| pool_bytes = builder._get_pool_bytes_per_block(vllm_config, kv_cache_groups) | ||
| if pool_bytes is not None: | ||
| return pool_bytes |
There was a problem hiding this comment.
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| copies = self._terminal_spill_copies.setdefault(id(publication), {}) | ||
| copies[page_idx] = pending.resident_blocks |
There was a problem hiding this comment.
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)| if vllm_config.attention_config.hisparse_config is not None and ( | ||
| pages := _compact_hisparse_kpool_pages(kv_cache_groups) | ||
| ): |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Avoid direct attribute access on vllm_config.attention_config to prevent potential AttributeErrors. Use the safe getattr pattern consistently.
| 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 |
There was a problem hiding this comment.
Avoid direct attribute access on vllm_config.attention_config to prevent potential AttributeErrors. Use the safe getattr pattern consistently.
| 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 |
There was a problem hiding this comment.
Avoid direct attribute access on self.vllm_config.attention_config to prevent potential AttributeErrors. Use the safe getattr pattern consistently.
| 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 |
|
👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:
If CI fails, you can run linting and testing checks locally according Contributing and Testing. 🤖 How to trigger CI
Note Until the CI gate has run on a commit, the required Tip 💡 Consider Linking a Related Issue or RFCYour 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:
🙏 Thanks for helping us keep the project well-organized! |
|
/run |
|
Last updated: 2026-11-25 12:46 UTC+8 for commit ci-gate failed. Reason:
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:
|
|
/run |
|
/run |
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>
707a342 to
84f4196
Compare
|
/run |
Coverage
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>
|
/run |
zhenwenqi2024
left a comment
There was a problem hiding this comment.
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.
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
1 similar comment
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
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
maindirectly. 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"]c410543dpin, 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.Onboarding another model, using Kimi K3.1 as an example
INDEXERrole, declare the MLA cache asSPARSE, and describe recurrent state withMambaSpec. The attention backend supplies the packed row width. These declarations select the existing native-hybrid layout.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_configandHiSparseConnector. 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 Corec410543d, 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_ONLYand 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.
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.
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
Checklist
Testing
AI assistance was used and is recorded in the relevant commit trailers.