Repository navigation
Conversation
…r GLM 5.2/5.3 Signed-off-by: gcw_DTa4OOyR <akIbL05P0REysxO0.gcw_DTa4OOyR@noreply.gitcode.com>
…iews Signed-off-by: gcw_DTa4OOyR <akIbL05P0REysxO0.gcw_DTa4OOyR@noreply.gitcode.com>
|
👋 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 |
|
Last updated: 2026-11-26 17:42 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). |
There was a problem hiding this comment.
Code Review
This pull request introduces unified KV cache allocation support for GLM models (glm_moe_dsa) by implementing contiguous cache component views and refactoring AscendMLAAttentionSpec to use num_query_heads instead of shadowing num_heads. While the changes are well-covered by updated unit tests, several issues need to be addressed: first, part.numel() should be replaced with part.nbytes in attn_utils.py to robustly calculate byte sizes across different data types; second, the strict=True argument in zip() must be removed from both source and test files to maintain compatibility with Python 3.9; and finally, the missing import of get_dtype_size must be added to indexer.py and sfa_v1.py to prevent runtime NameError exceptions.
| num_kernel_blocks = num_blocks * group_spec.block_size // kernel_block_size | ||
|
|
||
| raw_parts = raw_cache if isinstance(raw_cache, tuple) else (raw_cache,) | ||
| total_bytes = sum(part.numel() for part in raw_parts) |
There was a problem hiding this comment.
Using part.numel() to calculate total_bytes assumes that the raw cache tensors are always of a 1-byte data type (like torch.int8). If any of the raw parts are allocated with their actual data types (e.g., torch.float16 for scales), part.numel() will return the number of elements instead of the byte size, leading to an incorrect total_bytes calculation and assertion failures.\n\nPlease use part.nbytes instead, which correctly and robustly returns the byte size of the tensor regardless of its data type.
| total_bytes = sum(part.numel() for part in raw_parts) | |
| total_bytes = sum(part.nbytes for part in raw_parts) |
| (blocks, tokens, heads, content_bytes // get_dtype_size(dtype)) | ||
| for (blocks, heads, tokens, content_bytes), dtype in zip(shapes, dtypes) | ||
| (blocks, tokens, heads, *inner, content_bytes // get_dtype_size(dtype)) | ||
| for (blocks, heads, tokens, *inner, content_bytes), dtype in zip(shapes, dtypes, strict=True) |
There was a problem hiding this comment.
The strict keyword argument in zip() was introduced in Python 3.10 (PEP 618). Since vLLM supports Python 3.9 (python_requires >= 3.9), using strict=True will cause a TypeError at runtime on Python 3.9 environments.\n\nPlease remove strict=True to maintain compatibility with Python 3.9. If length validation is desired, you can perform an explicit length check beforehand.
| for (blocks, heads, tokens, *inner, content_bytes), dtype in zip(shapes, dtypes, strict=True) | |
| for (blocks, heads, tokens, *inner, content_bytes), dtype in zip(shapes, dtypes) |
|
|
||
| kv_caches[layer_name] = tuple( | ||
| part.view(dtype).view(shape) | ||
| for part, dtype, shape in zip(raw_parts, dtypes, shapes, strict=True) |
There was a problem hiding this comment.
The strict keyword argument in zip() is a Python 3.10+ feature. To prevent runtime TypeError crashes on Python 3.9 (which is supported by vLLM), please remove strict=True.
| for part, dtype, shape in zip(raw_parts, dtypes, shapes, strict=True) | |
| for part, dtype, shape in zip(raw_parts, dtypes, shapes) |
| assert local_addrs == [key[dst_block].data_ptr(), scale[dst_block].data_ptr()] | ||
| assert remote_addrs == [prefill_key[1].data_ptr(), prefill_scale[1].data_ptr()] | ||
| assert lengths == [key[dst_block].nbytes, scale[dst_block].nbytes] | ||
| for local, source, length in zip(local_addrs, remote_addrs, lengths, strict=True): |
There was a problem hiding this comment.
The strict keyword argument in zip() is not supported in Python 3.9. Please remove strict=True to ensure the unit tests can run successfully on Python 3.9 environments.
| for local, source, length in zip(local_addrs, remote_addrs, lengths, strict=True): | |
| for local, source, length in zip(local_addrs, remote_addrs, lengths): |
| tokens = kernel_block_size or spec.block_size | ||
| blocks = num_blocks * spec.sfa_dcp_replicated_indexer_size * (spec.block_size // tokens) | ||
| prefix = (blocks, spec.num_kv_heads, tokens) | ||
| key_shape: RuntimeComponentShape = (*prefix, spec.head_size * get_dtype_size(spec.dtype)) |
| f"Invalid split SFA cache widths: nope={nope_dim}, rope={rope_dim}, head_size={spec.head_size}." | ||
| ) | ||
| widths = (nope_dim, rope_dim) | ||
| elem_size = get_dtype_size(spec.dtype) |
What this PR does / why we need it?
Part of RFC: #21053 (stacked follow-up on top of #22440).
This PR extends GLM-5.2 / GLM-5.3 (glm_moe_dsa) unified KV cache allocation (unified_allocate_kv_cache / create_kv_cache_runtime_views) to cover two additional production paths:
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Checklist
Testing
Boundary / edge-case coverage: Covered asymmetric head_size_v, kernel-block splitting, subclass/HND rejection, and multi-group / padded-page fallback boundaries.
Regression test: Locked down GLM layerwise reuse routing and FullAttentionSpec draft byte isolation in unit tests.
Error / failure path coverage: Verified NotImplementedError on derived backends and ValueError on HND layout.
Meaningful & reliable tests: Tests assert real storage sharing, layout contiguity, and byte-exact isolation.
Performance impact: N/A (allocation-time refactor only).
vLLM main: vllm-project/vllm@c410543