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](