Repository navigation
Description
Summary
MacheteLinear, AwqMacheteLinear and QQQLinear add the linear bias after the native kernel has already rounded its FP32 accumulator to the 16-bit output dtype. This breaks the repository bias contract (AGENTS.md and gptqmodel-torch-oracle-numerics § Linear bias: "add the bias once to the complete reduction before the single cast"). Marlin, AllSpark and ExLlamaV2 were already changed to follow it (#4657, #3794).
There are two consequences:
- A pre-bias partial sum above 65504 becomes
infin FP16 and staysinf, even when the biased result is finite. The AllSpark wrapper comment describes exactly this case (allspark.py:299-301). - When nothing overflows, every biased output is still rounded twice.
Machete is the AUTO choice for GPTQ and AWQ (priority 100, above Marlin's 90) on SM90, so this affects every biased projection on H100/H200 by default (for example Qwen2/2.5 q/k/v).
Impact
- Post-quant accuracy. FP16 near the range limit:
infinstead of a finite value (high severity for the affected rows, but rare). Elsewhere: double rounding, up to 1 ulp instead of 0.5 ulp. In BF16 that can use up most of the 2e-3 inference tolerance. - QQQ is FP16-only, so the overflow case applies to every biased QQQ layer.
Location (@ 85caf6c)
gptqmodel/nn_modules/qlinear/machete.py:347-357output = machete_mm(a=input_2d, b_q=self.qweight, ..., b_group_size=self.group_size) if self.bias is not None: output.add_(self.bias)
gptqmodel/nn_modules/qlinear/machete_awq.py:230-240: same pattern.gptqmodel/nn_modules/qlinear/qqq.py:735-756:Dis an FP16 buffer written byqqq_gemm(gptqmodel_ext/qqq/qqq_gemm.cu:135-136cvt.rn.f16.f32,:749). The wrapper then runsD = (D.float() + self.bias.float()).to(A_dtype). The comment says "the visible cast is the only rounding after the reduction", but the kernel has already rounded to FP16 (or producedinf) before this line runs.- The root cause in Machete: every generated
TypeConfighasout=a(gptqmodel_ext/machete/generate.py:605-640), andmachete_mmtakes no bias operand. So the wrapper can only get a 16-bit result.
Mechanism
The CUTLASS epilogue (and QQQ's cvt.rn.f16.f32) converts the FP32 accumulator to the activation dtype. The wrapper adds the bias to that narrowed tensor, so the order is round(acc) + bias → round again, not round(acc + bias).
Reproduction / Validation
The native kernels need SM90 (Machete) or CUDA (QQQ), so the ops are replaced with stand-ins that do what the epilogues do: FP32 accumulate, one cast to the output dtype, no bias. Each wrapper's real forward() then runs. Script: narrow_bias_epilogue.py. Inputs: K=N=128, x=8, W=70, so x@W = 71680; bias = -20000; oracle = 51680, which fits in FP16. Output on CPU:
oracle (fp32) : 51680.0 -> fp16 51680.0
MacheteLinear : inf
AwqMacheteLinear : inf
QQQLinear : inf
Not executed on SM90 hardware. The double-rounding magnitude on real checkpoints was not measured.
Suggested fix
- Machete: add FP32-output impl configs (
out=DataType.f32) for the GPTQ/AWQ type configs ingenerate.py. When a bias is present, callmachete_mm(..., out_type=torch.float32)and finish with(out + self.bias.float()).to(x.dtype). Bias-free layers keep the current 16-bit output. A better option is a bias operand in the CUTLASS epilogue (LinearCombinationBias), which avoids the extra output traffic.if self.bias is not None: out = machete_mm(..., out_type=torch.float32) out = (out + self.bias.to(device=out.device, dtype=torch.float32)).to(input_2d.dtype) else: out = machete_mm(...)
- QQQ: write
Din FP32 when a bias is present (template the finalcvt.rn.f16.f32store on the output type), or add the bias inside the kernel epilogue before thecvt. Then remove the misleading comment atqqq.py:751-753. - Add oracle tests near the overflow boundary (partial sum > 65504, biased result < 65504), following the existing Marlin/AllSpark bias tests.
Notes
- The repro shows only the wrapper's epilogue order. It assumes the native epilogues cast to the output dtype, which follows from
out=aingenerate.pyand thecvt.rn.f16.f32store inqqq_gemm.cu. - BitBLAS has the same pattern (
bitblas.py:907-908,out_2d + self.biason the FP16 operator output). It is not part of this issue because BitBLAS computes in FP16 for BF16 models anyway.
Found by automated code audit (Claude Code).
Activity
Qubitium commentedon Nov 20, 2026
Agent claim released:
agent-f7b500b8ed4cfinished this issue.Pull request: #5952
Implementing the FP32-output epilogue path for biased Machete/QQQ layers and adding an overflow-boundary regression test. QQQ fix verified on GPU (finite 51680 vs inf; single cast); Machete fp32-out variants compile for sm_90a; publishing the branch and opening the PR.
test(kernels): use one import style for the Machete modules (#5725)
fix(kernels): add bias to the FP32 accumulator for Machete/AWQ-Machet…
Merge origin/main into feat/anytorch-stable-abi