Skip to content

[Audit][machete/qqq] Bias added after the kernel narrows to FP16/BF16: pre-bias overflow becomes inf, double rounding otherwise #5725

Closed

Description

@Qubitium

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 inf in FP16 and stays inf, 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: inf instead 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-357
    output = 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: D is an FP16 buffer written by qqq_gemm (gptqmodel_ext/qqq/qqq_gemm.cu:135-136 cvt.rn.f16.f32, :749). The wrapper then runs D = (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 produced inf) before this line runs.
  • The root cause in Machete: every generated TypeConfig has out=a (gptqmodel_ext/machete/generate.py:605-640), and machete_mm takes 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 in generate.py. When a bias is present, call machete_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 D in FP32 when a bias is present (template the final cvt.rn.f16.f32 store on the output type), or add the bias inside the kernel epilogue before the cvt. Then remove the misleading comment at qqq.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=a in generate.py and the cvt.rn.f16.f32 store in qqq_gemm.cu.
  • BitBLAS has the same pattern (bitblas.py:907-908, out_2d + self.bias on 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

  1. added
    bug
    on Nov 20, 2026
  2. added
    scanned
    safe
    on Nov 20, 2026
  3. Qubitium commented on Nov 20, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-f7b500b8ed4c finished 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsafescanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions