Repository navigation
Description
Residual of #4471. PR #4533 kept the Torch portable reductions and bias epilogues wide (ParoQuant CPU ATen, bias-free FP8 fallback, Mamba selective_state_update), but it explicitly did not touch the MLX QQQ case: no MLX/Metal runtime exists on the Linux validation host, and the existing MLX QQQ tests encode the historical FP16 intermediate as their expected policy. This issue tracks that remaining case so it is not lost.
Contract
Keep the scaled reduction and the bias add wide until exactly one visible output cast. Do not destroy BF16 range, and do not overflow a finite final FP16 linear + bias result.
Two manifestations, one root (epilogue ownership)
Both come from narrowing the scaled product to FP16 before the bias add and the visible-dtype cast:
- (a) BF16 range loss — finite BF16 output
65536becomesinfwhen passed through FP16. - (b) FP16 bias cancellation — pre-bias
67200plus bias-2000should yield finite65216, but it overflows before the cancellation.
Repro (portable CPU IEEE proof, not an MLX forward)
Supported whole-row QQQ INT4 holder, K = N = 64. M=1 uses the fused finalizer; M>=2 uses the Python epilogue — both must be covered.
import torch
torch.set_num_threads(1)
for dtype, x, signed_code, channel, bias in [
(torch.bfloat16, 1024., 1, .0625, 0.),
(torch.float16, 12.5, 7, .75, -2000.),
]:
a = torch.full((2, 64), x, dtype=dtype)
s = a.float().abs().amax(-1, keepdim=True) / 127
q = (a.float() / s).round().clamp(-128, 127)
raw = q @ torch.full((64, 64), signed_code * 16., dtype=torch.float32)
scaled = raw * s * channel
exact = a.double() @ torch.full((64, 64), signed_code * 16 * channel, dtype=torch.float64) + bias
expected = exact.to(dtype)
narrowed = (scaled.half().float() + bias).to(dtype)
print(float(scaled[0, 0]), float(exact[0, 0]), float(expected[0, 0]), bool(torch.isinf(narrowed).all()))Observed output: 65536.0 65536.0 65536.0 True and 67200.0 65200.0 65216.0 True.
Observed vs expected
- BF16: oracle expects finite
65536; current order yieldsinf. - FP16: oracle expects
65200exact →65216visible; current order yieldsinf. - The shipped source encodes that cast order in both row bands, so the existing tests passing does not refute the defect — they assert the historical FP16-intermediate policy.
Validation constraints
- No MLX/Metal runtime on the Linux CI host (
import mlx→ModuleNotFoundError), so the fix cannot be numerically qualified here. - Acceptable evidence: (1) a host-side test that pins the cast order / accumulator dtype at the epilogue boundary (as was done for the MLX NF12 row-dispatch fix in fix(mlx): cover NF12 short-row output tails in dot-product dispatch (#4478) #4523), plus (2) explicit, reproducible Apple-device instructions for M=1 and M=2 using the fixture below. Do not claim MLX numerics that were not executed.
- Fixture:
N=K=64,group_size=64(whole row),bits=4, uint32 words0x99999999/0xffffffff, affine scales16, affine biases-128, channel scales.0625/.75, optional output bias-2000.
Source / history
The premature-FP16 cast order is in the MLX QQQ epilogue for both the fused-finalizer (M=1) and Python-epilogue (M>=2) row bands. Introduced with the MLX QQQ backend; #4471 documented it, #4533 left it unfixed by design.
Software / device info
Linux x86_64 validation host only; no Apple/Metal device available. Torch portable IEEE proof executed with an independent FP64 oracle.
Activity
Qubitium commentedon Nov 17, 2026
Claimed. This issue is now owned by a dedicated worker; a fix PR referencing it will follow.
Qubitium commentedon Nov 17, 2026
Claimed by an AI agent. Will keep the scaled reduction and bias add in a wide accumulator with exactly one visible cast, pin the cast order with a host-side test (no MLX runtime here), and document reproducible Apple-device validation steps.
fix(mlx): keep QQQ scaled reduction and bias wide until one cast (#4534…
test(mlx): repair stale oracles, backend skips, and the EXL3 CPU cont…
fix(mlx): mirror the Torch affine grid fit and pack inference-mode-lo…