Repository navigation
fix(numerics): keep portable Torch reductions and bias epilogues wide (#4471) - #4533
Merged
Merged
Conversation
This was referenced Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4471
Root cause
Three portable Torch inference paths narrowed to the activation dtype before a
finite reduction or bias epilogue:
ParoLinear._forward_cpu_atenbuilds a biaslessTorchAtenAwqLinearchild, so_fused_op_forwardasked_cpu_int4pack_mmforout_dtype=Noneand narrowed the native product toFP16/BF16. The parent then added its bias in FP32, but the pre-bias product
had already overflowed.
TorchFP8Linear._forward_dequant_matmulonlydecoded the weight in FP32 when a bias was present. With
bias=False, astored weight outside the activation range (e.g. 65536 decoded from an FP8
row scale) was rounded to FP16 before the reduction, turning an exactly zero
dot product into NaN.
selective_state_updateformeddt * BanddB * xin FP16, then narrowed the FP32updated_statetoC.dtypebefore the readout. Half intermediates overflowed before theyreached the FP32 state/reduction.
Fix
TorchAtenAwqLinear._fused_op_forward(x, out_dtype=None)now accepts anexplicit product dtype. Its default behavior is unchanged for standalone
biased layers.
ParoLinearpassesout_dtype=torch.float32when the parentowns a bias, so the wide product crosses the child/parent boundary and the
bias is added in FP32 before one visible cast.
TorchFP8Linear._forward_dequant_matmuluses the existing temporary FP32decode + FP32 matmul path for all half activations, with or without a bias,
and adds an optional bias in FP32 before the single output cast.
selective_state_updatecomputesdt * B,dB * x, the FP32 state readout,and the optional D term in FP32; the final visible output cast is unchanged.
All widened operands are local temporaries for the current call; no dense or
expanded weight is cached.
Error vs independent FP64 oracle
Max absolute / relative error over the complete output tensor:
inf/inf(non-finite)0.0/0.0nan/nan(non-finite)0.0/0.0inf/inf(non-finite)0.0/0.0inf/inf(non-finite)0.0/0.0The oracle is independent float64 arithmetic over the decoded/represented
weights; it does not call the implementation under test.
Regression tests
tests/test_portable_wide_epilogues_4471.py— ParoQuant CPU ATen outer-biascase and Mamba incremental state/output case.
tests/test_fp8_bias_range.py::test_fp8_bias_free_fallback_keeps_decoded_weight_range— bias-free FP8 fallback case.
Before fix (source fixes stashed, tests kept): 3 failed.
After fix: 3 passed.
Tests run
CUDA venv (Python 3.14t, torch 2.16.0.dev20261102+cu130), thread caps = 4:
ROCm venv (torch 2.16.0.dev20261025+rocm10.1),
HIP_VISIBLE_DEVICES=3, thread caps = 4:Lint:
Final test/lint run was after
git fetch origin main && git merge --no-edit origin/main(
88cd6d75b).Hardware
CPU-only numeric verification; AMD Eng Sample
100-000001458-01. The two ROCmskips are the existing GPU-only FP8 tests in
tests/test_fp8_bias_range.py.Limitations
sub-case is not changed here: no MLX/Metal runtime is available on this Linux
host, and its existing tests encode the historical FP16 intermediate, so it
needs an Apple-host change with independent Metal numerics.
in this validation; only the CPU fallback was measured.
temporary and was not benchmarked.