From f414f90601b9ef766017f1fb9398c1bed9bc871a Mon Sep 17 00:00:00 2001 From: JartX Date: Mon, 13 Apr 2026 20:29:45 +0200 Subject: [PATCH] [Bugfix][Kernel][ROCm] Fix triton_w4a16 scales mismatch when BLOCK_K > group_size (#39705) Signed-off-by: JartX --- .../kernels/linear/mixed_precision/triton_w4a16.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vllm/model_executor/kernels/linear/mixed_precision/triton_w4a16.py b/vllm/model_executor/kernels/linear/mixed_precision/triton_w4a16.py index 7bc8ca584c..5cc100b3e1 100644 --- a/vllm/model_executor/kernels/linear/mixed_precision/triton_w4a16.py +++ b/vllm/model_executor/kernels/linear/mixed_precision/triton_w4a16.py @@ -235,6 +235,14 @@ def triton_w4a16_gemm( else: BLOCK_M, BLOCK_N, BLOCK_K = 128, 128, 32 + # The kernel loads scales/zeros for a single group per BLOCK_K tile + # (one g_idx per iteration). If BLOCK_K > group_size, rows at the tail + # of the tile dequantize with the wrong group's scales, silently + # corrupting the output. Clamp BLOCK_K to group_size to keep one + # scale group per tile. + if group_size < BLOCK_K: + BLOCK_K = group_size + grid = (triton.cdiv(M, BLOCK_M), triton.cdiv(N, BLOCK_N)) triton_w4a16_gemm_kernel[grid](