Repository navigation
Description
Summary
#5606 made the TorchLinear decode range-safe. When decoded weights do not fit the activation dtype, it decodes in a wide dtype and reduces with linear_wide_bias, and the fused ROCm/Ada kernels are gated by _decoded_weight_fits(x.dtype). The issue said "Check the separate streaming/Triton paths before claiming parity there". TritonV2Linear.forward (BACKEND.GPTQ_TRITON, AUTO priority 40 on CUDA) never makes that check. It calls QuantLinearFunction → quant_matmul → dequant(input.dtype, ...), and that always narrows the FP32-decoded weight to the activation dtype. For FP16 activations, any decoded weight |(q - z) * s| > 65504 becomes inf, and 0 * inf gives NaN in the GEMM. The same checkpoint gives a finite, correct output on BACKEND.TORCH.
Impact
- Post-quant accuracy. Severity is low: only checkpoints with large per-group scales are affected (for 4-bit,
s * 15 > 65504, i.e.s > ~4367in FP16). The failure is NaN/inf output, where the Torch backend returns the correct value. - BF16 activations are not affected, because the kernel decodes in FP32 and BF16 has FP32's range.
Location (@ 85caf6c)
gptqmodel/nn_modules/qlinear/tritonv2.py:185:out = QuantLinearFunction.apply(x, self.qweight, self.scales, ...), with no_decoded_weight_fitscheck. The class inherits that method fromTorchLinear.gptqmodel/nn_modules/triton_utils/dequant.py:352:W = dequant(input.dtype, qweight, scales, qzeros, g_idx, bits, pack_bits, maxq). The kernel computes in FP32, thentl.cast(weights, out_dtype).- For comparison, the gated paths are
torch.py:740(and self._decoded_weight_fits(x.dtype)on the fused kernels), the_forward_eagerwide branch, and_dequantize_weight_triton(which asks forself._decode_dtype()).
Mechanism
The decode dtype is taken from the activation, not from the stored scale range, so the overflow happens inside the decoder before any FP32 reduction can help. This is the same failure #5606 fixed for TorchLinear.
Reproduction / Validation
audit_kernels/repro_tritonv2_range.py, executed on CPU. It uses the #5606 recipe (4-bit, asym, code 15, zero 0, FP16 scale 8192) with FP16 activations. The TorchLinear output is real. The TritonV2 result is a torch emulation of dequant_kernel (FP32 decode, then cast to input.dtype) followed by the same matmul_fp32_reduce that quant_matmul calls. The Triton kernel itself was not executed: requires CUDA.
TorchLinear fp16 out[0,0] = 30720.0 (expected 0.25*15*8192 = 30720)
TritonV2 emulated out[0,0] = nan
Suggested fix
In TritonV2Linear.forward, route to the already range-safe parent path when the decode does not fit:
if self.training or not self._decoded_weight_fits(x.dtype):
return super().forward(x) # TorchLinear: wide decode + linear_wide_biasAlternatively, pass self._decode_dtype() into quant_matmul/dequant and reduce with linear_wide_bias when it differs from x.dtype. _decoded_weight_fits reads an eagerly precomputed answer, so the check adds no host sync per forward.
Notes
- The overflow requires unusually large scales. Normal LLM checkpoints are unaffected.
- The repo treats this class as a bug ([BUG] GPTQ_TORCH eval decode bypasses the range-safe base decoder: BF16 linear returns NaN and embedding returns inf #5606, [BUG] #5495 (fix of #5367) incomplete: FP16 grad forward still NaN after the CPU int4pack warm-up (runtime decode has no range-safe dtype) and on the GPTQ TorchFused/TorchAten fallbacks #5577), and TritonV2 is the remaining GPTQ dense-decode path without the gate.
Found by automated code audit (Claude Code).
Activity
Qubitium commentedon Nov 20, 2026
Agent claim released:
agent-4e3a0639ecaffinished this issue.Pull request: #5920
Fixing TritonV2Linear's missing range-safe decode so FP16 forwards stop returning NaN
fix(tritonv2): keep the range-safe decode in eval (#5738) (#5920)