Repository navigation
fix(paroquant): keep fp32 reduction and bias epilogue (#3866) - #3893
Merged
Merged
Conversation
ParoLinear._forward_dense decoded the AWQ grid to the activation dtype, ran the matmul there and added the bias in that dtype, so a finite FP16 result overflowed before the bias could cancel it (inf instead of 65024). The CUDA AWQ path had the same epilogue: the split-K reduction is float32, but the kernel rounded its result to the activation dtype before Python added the bias. The dense fallback now reconstructs the grid in float32 and uses linear_wide_bias, which keeps the reduction and the stored bias in float32 and casts once. The CUDA path asks the existing fp32 split-K reducer for a float32 result, adds the stored bias in float32 and casts once; the no-bias path is unchanged. The AWQ binding gains an optional fp32_output flag (default false, so existing callers are unchanged). The existing ParoQuant dense and upstream-contract references now reconstruct the grid with float32 scales and apply the bias before the single cast, matching the corrected visible contract.
Qubitium
added a commit
that referenced
this pull request
Nov 14, 2026
The fp32 bias epilogue change (#3893) added `from ._numerics import linear_wide_bias` after `from ._runtime_cache import tensor_cache_key`, so `format/check.sh` (ruff I001) fails on main. Reorder the two local imports; no behavior change.
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 #3866
Root cause
ParoLinear._forward_densecalled_dequantize_weight_for_inference(x_flat, dtype=x_flat.dtype), rantorch.matmulin that dtype, then added the bias in that dtype. For theissue's layer the finite FP16 result is
65024, but the FP16 dot reaches66048first and rounds toinf, so the bias can no longer cancel it.The CUDA AWQ path had the same epilogue in a different place:
gemm_forward_cuda_fp32_reducealready reduces split-K partials in FP32, butgemm_forward_cuda_fp32_reduce()casts the result to the activation dtypebefore returning it, and
_forward_cuda_awq_kernelthen adds a bias narrowedto that dtype. The same finite result therefore came back as
infon thenative kernel too.
Fix
ParoLinear._forward_densereconstructs the grid in FP32 and callslinear_wide_bias, which keeps the reduction and the stored bias in FP32 andcasts once.
fp32_outputflag (defaultfalse, so every existing caller keeps the activation-dtype result). ThePython wrapper
awq_gemm_forward_fp32_reducepassesTrue.ParoLinear._forward_cuda_awq_kerneluses that float32 result, adds thestored bias in float32 and casts once. The no-bias path and the
fp32_accum=Falseopt-out path are unchanged.and apply the bias before the single visible cast; the upstream-contract test
feeds the same rotated input to both sides so it measures the GEMM, not the
separate fused-rotation implementation.
No
GPTQMODEL_*behaviour switches were added. The dense fallback stillreleases its temporary weight at the end of the call; the native path still
reads packed codes and retains no dense weight.
Before / after
Exact issue geometry (
bits=4,group_size=16, grid weight8, bias-1024), and a kernel-supported native geometry (group_size=32,in=32,out=64,x=258). "Before" was captured from cleanorigin/main(
daa5dae).inf6502465024inf6502465024Tests
New regression tests in
tests/kernels/test_paroquant.py(both fail ondaa5daewithinf):test_paroquant_dense_fallback_accumulates_reduction_and_bias_in_fp32test_paroquant_cuda_kernel_adds_bias_after_the_fp32_reduction(fails if thenative path delegates to the dense fallback)
Both compare against
_fp32_awq_oracle, an independent FP32 reconstruction ofthe packed AWQ layout.
Before/after on the pre-fix worktree (
origin/main+ the new test file):both new tests fail with
tensor([[inf, ...]]).Hardware / environment
CUDA_VISIBLE_DEVICES=GPU-d458708b-c760-bbf1-08fb-8b8803a2157d, torch 2.16.0.dev+cu130HIP_VISIBLE_DEVICES=2, torch 2.16.0.dev+rocm10.1Reviewer notes
No logic-flow diagrams: this is a localized numerical fix in one fallback and
one binding epilogue, which the logic-flow skill lists as not required.
The AWQ op schema change is additive (
fp32_output=Falsedefault). Thenative fix is gated on
self.bias is not None and self.fp32_accum, so a userwho explicitly opts out of FP32 accumulation keeps the previous kernel and
epilogue.