Repository navigation
Description
Summary
The AWQ GEMV-format and GEMV_FAST CUDA paths (AwqGEMVLinear, AwqGEMVFastLinear, LLMAwqLinear) break the linear-bias / wide-reduction contract in .agents/skills/gptqmodel-torch-oracle-numerics in two places:
gemmv2(GEMV format,rows > 8, i.e. every prefill): the kernel writes each of thesplit_k_iters = 8split-K partials as FP16 (_out_featsis allocated with the input dtype). The host then returns_out_feats.sum(0). Each partial is rounded to FP16, and can overflow, before the reduction finishes. The GEMM-format path already fixed this:gemm_forward_cuda_fp32_reduce/launch_gemm_forward_cuda_fp32_reducekeep FP32 partials and use a fused reduce.- Bias epilogue (GEMV, GEMV_FAST decode and prefill): the native kernels return an FP16 product. The wrapper then does
torch.add(out, self.bias)in FP16. The full reduction is rounded to FP16 first, and only then is the bias added and rounded again. The contract says to add the bias to the wide reduction before the single cast. A partial sum outside the FP16 range turns intoinfeven when the bias brings it back into range.
Impact
- Post-quant accuracy. Severity is low to medium.
- Normal data: about 2x more output error than the single-rounding contract. In the emulation below, relative error is 7.0e-4 for gemmv2 and 5.7e-4 for round-then-bias, against 3.1e-4 for the contract. That is still inside the 2e-3 inference limit.
- Edge case:
infoutput where the contract result is finite. This happens when a split-K partial or the pre-bias sum is greater than 65504.
- Speed is not affected.
Location (@ 85caf6c)
gptqmodel/nn_modules/qlinear/gemv_awq.py:230-253:
if inputs.shape[0] > 8:
out = awq_gemmv2_forward(inputs, self.qweight, self.scales, self.qzeros, self.group_size, self.split_k_iters)
else:
out = awq_gemv_forward(...)
if self.bias is not None:
if input_dtype == torch.float16 and self.bias.dtype == torch.float16:
out = torch.add(out, self.bias) # out is already an FP16-rounded productgptqmodel/nn_modules/qlinear/gemv_fast_awq.py:228-237: the same epilogue afterawq_fast_gemv_forward_decode/awq_fast_gemm_forward_prefill.gptqmodel_ext/awq/quantization/gemm_cuda_gen.cu:1301-1342(gemmv2_forward_cuda):
auto options = torch::TensorOptions().dtype(_in_feats.dtype())...;
at::Tensor _out_feats = torch::empty({split_k_iters, num_in_feats, _kernel.size(0)}, options); // FP16 partials
...
return _out_feats.sum(0);The same pattern appears at :1115/:1156 for the MoE grouped variant.
gptqmodel_ext/awq/quantization/gemv_cuda.cu:272andquantization_new/gemv/gemv_cuda.cu:263: FP16 output allocations, so the epilogue has no FP32 product to add the bias to.
Mechanism
The FP32 accumulators in each CTA are stored as half. For gemmv2 that happens per split-K slice. The reduction and the bias add then run on values that were already rounded, which gives two or more roundings instead of one. A finite partial above 65504 saturates to inf. The comment at gemv_awq.py:245 ("A CUDA FP16 add already accumulates in FP32 and rounds once") is true only for the add itself. The operand out has already been rounded.
Reproduction / Validation
The native kernels need CUDA, so the kernels themselves were not executed. What follows is a pure-torch CPU emulation of the arithmetic, audit_kernels/emulate_awq_gemv_epilogue.py, executed on CPU with torch 2.14 dev. Shape M=16, K=N=4096, split_k=8, FP16, fp64 oracle:
rel err vs fp64: contract 3.06e-04 gemmv2(rows>8) 7.01e-04 gemv(round-then-bias) 5.66e-04
overflow case: contract 49984.0 round-then-bias inf
Suggested fix
- In
gemmv2_forward_cuda: allocate_out_featsaskFloat32, have the kernel storefloatpartials (the template already accumulates in FP32), and reduce with the existingmaybe_fused_reduce_splitk_fp32_to_output. Better, add afp32_outputflag so the wrapper can add the bias in FP32. This mirrorsgemm_forward_cuda_fp32_reduce. - For the GEMV / GEMV_FAST decode kernels: add an FP32-output (or fused-bias) variant and in Python do
out = (out_fp32 + bias.float()).to(input_dtype). Until that exists, the contract's fallback rule applies: route biased layers whose pre-bias sum can leave the FP16 range to a wide path.
Notes
- Emulation only. The exact error depends on the kernel's internal accumulation order, and the overflow case requires partial sums above 65504.
- The AwqGEMVTriton and torch (portable) variants were not reviewed for this; they appear to use FP32 epilogues already.
Found by automated code audit (Claude Code).
Activity
Qubitium commentedon Nov 20, 2026
Agent claim released:
agent-fb5145b84190finished this issue.Pull request: #5947
fix AWQ GEMV/GEMV_FAST FP32 split-K partials and bias epilogue; GB10 sm_121 with venv CUDA 13.5 nvcc
fix(awq): add the bias to the FP32 GEMV reduction and keep split-K pa…
fix(awq): add the bias to the FP32 GEMV reduction and keep split-K pa…
fix(awq): add the bias to the FP32 GEMV reduction and keep split-K pa…