Repository navigation
Integrate Qwen3.8-Next A3 operator optimizations - #23914
Lethobenthos20 wants to merge 1 commit into
Conversation
|
👋 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 |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces significant performance optimizations for Qwen models on Ascend NPUs, including in-place GBSA attention outputs, decomposed TextGR projections with prepacked BF16 NZ weights, fused Triton kernels for final combine and RMSNorm, a fused shared-expert gate-and-add kernel, and shared INT8 activation quantization. The review feedback highlights several critical issues that must be addressed, such as a runtime NameError in the QSA indexer, potential out-of-bounds memory accesses in multiple Triton kernels due to un-clamped indices or negative offsets, and opportunities to optimize C++ string allocations and modernise pointer casting in the PyTorch bindings.
| q = upstream_indexer.apply_qsa_rmsnorm(self.q_layernorm, q.reshape(-1, self.index_head_dim)).reshape_as(q) | ||
| q = upstream_indexer.apply_qsa_rope(self.rotary_emb, positions, q) |
There was a problem hiding this comment.
The variable upstream_indexer is used here but it is not defined or imported in this file. This will raise a NameError at runtime. It should be replaced with upstream_qsa, which is imported at the top of the file.
| q = upstream_indexer.apply_qsa_rmsnorm(self.q_layernorm, q.reshape(-1, self.index_head_dim)).reshape_as(q) | |
| q = upstream_indexer.apply_qsa_rope(self.rotary_emb, positions, q) | |
| q = upstream_qsa.apply_qsa_rmsnorm(self.q_layernorm, q.reshape(-1, self.index_head_dim)).reshape_as(q) | |
| q = upstream_qsa.apply_qsa_rope(self.rotary_emb, positions, q) |
| tl.store( | ||
| injection + row * HC_COUNT + column - LOWRANK, | ||
| 2.0 * sigmoid, | ||
| (column >= LOWRANK) & (column < LOWRANK + HC_COUNT), | ||
| ) |
There was a problem hiding this comment.
In _hc_down_silu_inject_kernel, the pointer offset column - LOWRANK can be negative when column < LOWRANK. Performing pointer arithmetic with negative offsets on a tensor pointer can lead to out-of-bounds memory access or undefined behavior on some platforms, even if the store is masked. Clamping the offset to a minimum of 0 using tl.maximum ensures safe address generation.
| tl.store( | |
| injection + row * HC_COUNT + column - LOWRANK, | |
| 2.0 * sigmoid, | |
| (column >= LOWRANK) & (column < LOWRANK + HC_COUNT), | |
| ) | |
| tl.store( | |
| injection + row * HC_COUNT + tl.maximum(0, column - LOWRANK), | |
| 2.0 * sigmoid, | |
| (column >= LOWRANK) & (column < LOWRANK + HC_COUNT), | |
| ) |
| gate_columns = tl.arange(0, 16) | ||
| gates = tl.load(injection_ptr + row * stride_injection_row + gate_columns, gate_columns < HC_COUNT, 0.0) |
There was a problem hiding this comment.
In _hc_combine_final_norm_segmented_kernel, gate_columns is initialized with a block size of 16 (tl.arange(0, 16)). If HC_COUNT is less than 16 (e.g., 4 or 8), loading from injection_ptr with gate_columns can result in out-of-bounds memory access on the right side of the row, even if masked. Clamping the columns to HC_COUNT - 1 prevents illegal memory access.
| gate_columns = tl.arange(0, 16) | |
| gates = tl.load(injection_ptr + row * stride_injection_row + gate_columns, gate_columns < HC_COUNT, 0.0) | |
| gate_columns = tl.arange(0, 16) | |
| safe_gate_columns = tl.minimum(gate_columns, HC_COUNT - 1) | |
| gates = tl.load(injection_ptr + row * stride_injection_row + safe_gate_columns, gate_columns < HC_COUNT, 0.0) |
| s = tl.load(shared + row[:, None] * shared_stride + col[None, :], mask, 0).to(tl.float32) | ||
| r = tl.load(routed + row[:, None] * routed_stride + col[None, :], mask, 0).to(tl.float32) | ||
| g = tl.load(gate + row * gate_stride, row < rows, 0).to(tl.float32) |
There was a problem hiding this comment.
In _shared_expert_gate_add_rows_kernel, the row and column indices can exceed rows and width respectively when BLOCK_M or BLOCK_N does not perfectly divide the dimensions. Loading from shared, routed, or gate with out-of-bounds indices can cause memory faults or undefined behavior, even if masked. Clamping the indices to rows - 1 and width - 1 ensures safe memory access.
| s = tl.load(shared + row[:, None] * shared_stride + col[None, :], mask, 0).to(tl.float32) | |
| r = tl.load(routed + row[:, None] * routed_stride + col[None, :], mask, 0).to(tl.float32) | |
| g = tl.load(gate + row * gate_stride, row < rows, 0).to(tl.float32) | |
| safe_row = tl.minimum(row, rows - 1) | |
| safe_col = tl.minimum(col, width - 1) | |
| s = tl.load(shared + safe_row[:, None] * shared_stride + safe_col[None, :], mask, 0).to(tl.float32) | |
| r = tl.load(routed + safe_row[:, None] * routed_stride + safe_col[None, :], mask, 0).to(tl.float32) | |
| g = tl.load(gate + safe_row * gate_stride, row < rows, 0).to(tl.float32) |
| char *layout_q_ptr = const_cast<char *>(layout_q_str.c_str()); | ||
| char *layout_kv_ptr = const_cast<char *>(layout_kv_str.c_str()); |
There was a problem hiding this comment.
| std::vector<int64_t> lse_shape{0}; | ||
| if (return_softmax_lse) { | ||
| const auto layout_q_str = std::string(layout_q); | ||
| if (layout_q_str == "TND") { | ||
| lse_shape = {q.size(0), q.size(1), 1}; | ||
| } else if (layout_q_str == "BNSD") { | ||
| lse_shape = {q.size(0), q.size(1), q.size(2), 1}; | ||
| } else { | ||
| lse_shape = {q.size(0), q.size(2), q.size(1), 1}; | ||
| } | ||
| } | ||
| auto softmax_lse = at::empty(lse_shape, q.options().dtype(at::kFloat)); | ||
|
|
||
| std::string layout_q_str(layout_q); | ||
| std::string layout_kv_str(layout_kv); |
There was a problem hiding this comment.
layout_q_str is constructed twice from layout_q (once inside the if (return_softmax_lse) block and once in the outer block). We can construct it once at the beginning of the function and reuse it to avoid redundant string allocations and constructions.
std::string layout_q_str(layout_q);
std::vector<int64_t> lse_shape{0};
if (return_softmax_lse) {
if (layout_q_str == "TND") {
lse_shape = {q.size(0), q.size(1), 1};
} else if (layout_q_str == "BNSD") {
lse_shape = {q.size(0), q.size(1), q.size(2), 1};
} else {
lse_shape = {q.size(0), q.size(2), q.size(1), 1};
}
}
auto softmax_lse = at::empty(lse_shape, q.options().dtype(at::kFloat));
std::string layout_kv_str(layout_kv);42a4ff6 to
6b8a9fa
Compare
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Rebase the combined stack onto source PR vllm-project#23914 at 4886362 and fork PR vllm-project#17 at e52ce81. Retain the norm-scatter regression cases, interface documentation and release note from the previous integration merge, and remove an unused GDN local restored by the newer base. Pinned Ruff checks and formatting pass; DP4 TP2 real-weight profiling validation follows on r207. Signed-off-by: yincaiming <y00913110@china.huawei.com>
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
d5bb438 to
744a0f8
Compare
Preserve the validated QSA, GDN, MoE, HC, and W4A8 operator paths while resolving the upstream GDN preparation overlap. Signed-off-by: Lethobenthos20 <167174511+Lethobenthos20@users.noreply.github.com>
301d0f5 to
c9cb0b5
Compare
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Summary
This PR rebases the validated Qwen3.8-Next A3 optimization stack onto the latest vLLM Ascend
mainbranch.Included work
Additional integration fixes:
fused_gdn_projection_prepare_kernel, distinguishing it from the separate ChunkGDN fused prepare path.Validation
mainand resolved the GDN recurrent-fusion conflict.git diff --checkpassed.vLLM baseline:
c410543d9ffff03f5f6c4a8c0ae1d3ad082c4a15