Repository navigation
Description
Found while verifying FP8 tests on an NVIDIA GB10 (sm_121, torch 2.11.0+cu130, aarch64). TorchFP8Linear with per-token activation quantization (W8A8) produces silently wrong output on this device: torch._scaled_mm accepts the row-wise scale layout but does not apply it.
What is wrong
_can_use_scaled_mm (gptqmodel/nn_modules/qlinear/fp8.py:713) enables the native path whenever
self.activation_quant_method == "per_token" and self.weight_scale_method in {"tensor", "row"}That is the row-wise contract: scale_a is (tokens, 1) and scale_b is (1, out_features). On sm_121 with this torch build, cuBLASLt's rowwise path either refuses or returns a result that does not match (A@B) * scale_a * scale_b:
scale_a |
scale_b |
result |
|---|---|---|
(1,1) |
(1,1) |
correct (rel=0.000) |
(M,1) |
(1,1) |
CUBLAS_STATUS_NOT_SUPPORTED |
(1,1) |
(1,N) |
CUBLAS_STATUS_NOT_SUPPORTED |
(M,1) |
(1,N) |
runs, rel=1063 (wrong output) |
(M,), (1,M) |
any | Invalid scaling configuration |
Only the exception cases are caught (forward() sets _scaled_mm_hard_disabled on a raised error). The (M,1) + (1,N) combination raises nothing and returns wrong values, so the module keeps the path for every later forward.
Probe (CUDA, fp8 e4m3, M=7, K=N=64):
xq = (torch.randn(7, 64, device="cuda") * 0.5).to(torch.float8_e4m3fn)
wq = (torch.randn(64, 64, device="cuda") * 0.5).to(torch.float8_e4m3fn)
sa = torch.linspace(0.5, 1.5, 7, device="cuda").reshape(7, 1)
sb = torch.linspace(0.5, 1.5, 64, device="cuda").reshape(1, 64)
ref = (xq.float() @ wq.t().float()) * sa * sb
out = torch._scaled_mm(xq, wq.t(), scale_a=sa, scale_b=sb, out_dtype=torch.float16)
print(((out.float() - ref).abs() / ref.abs().clamp_min(1e-6)).max()) # ~1063Symptom in the suite
Two tests are red on main on this host (they pass on the maintainer hosts in the issue tracker):
FAILED tests/kernels/test_fp8_kernel.py::test_fp8_scaled_mm_matches_dense_reference[tensor-float8_e4m3fn]
FAILED tests/kernels/test_fp8_kernel.py::test_fp8_scaled_mm_matches_dense_reference[row-float8_e4m3fn]
Greatest absolute difference: 1.3759765625 at index (2, 48) (up to 0.05 allowed)
The test's reference is correct: I checked it against the FP8 operands and both scales directly (dense vs fp8-ref maxabs = 8e-4), while _forward_scaled_mm is off by 1.375.
Severity
Medium-high. It is opt-in (activation_quant_method defaults to "none" = W8A16), but a caller who opts into W8A8 gets plausible-looking, wrong logits with no warning, on the newest NVIDIA hardware. The project's contract is fail-closed for kernels that cannot compute the documented math.
Suggested fix
Make the row-wise _scaled_mm path fail closed on hardware/torch builds that cannot compute it, instead of trusting that it raises:
- Probe once per process (cached next to
_scaled_mm_hard_disabled): a tiny16x16FP8 GEMM withscale_a=(M,1),scale_b=(1,N)compared against(A@B) * scale_a * scale_bin FP32. Disable the path when the call raises or the result is outside a loose tolerance. - Then
_can_use_scaled_mmreturnsFalsefor the per-token branch on this host,forward()takes the existing dequantize + matmul fallback (correct, slower), and the two tests skip instead of failing.
Note: draft PR #5173 edits the same functions (_can_use_scaled_mm, _forward_scaled_mm) for W8A16 decode, so this should land after (or inside) that change to avoid a conflict.
🤖 Found and verified by an automated agent on a GB10 host while verifying the FP8 suites.
Activity
Qubitium commentedon Nov 18, 2026
Agent claim released:
agent-f60b36e15e6dfinished this issue.Pull request: #5178
Adding a fail-closed rowwise _scaled_mm probe so per-token FP8 falls back to the correct dequant path on sm_121
fix(fp8): measure the row-wise `_scaled_mm` contract before using it (M…