Skip to content

fix(awq): pin Torch forward precision regressions and restore non-half dequantize - #3802

Merged
Qubitium merged 2 commits into
mainfrom
fix/awq-forward-review-followup
Nov 12, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/awq-forward-review-followup

Conversation

@ZX-ModelCloud

@ZX-ModelCloud ZX-ModelCloud commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #3800 (merged as 8cc5ae3d4).

Review findings and fixes

  1. The regression oracle read live module.scales and module.bias. The old bug corrupts those buffers, so the oracle reproduced the corruption. The tests now decode the packed INT4 words independently and compare forwards with the original checkpoint-precision scales and bias before checking stored buffers.
  2. The shared _dequantize_weight_for_inference helper originally asserted that every dequantized weight was half precision. The first revision of this PR avoided the assertion for a ParoQuant FP32 input by dequantizing in FP16 and widening afterward. Review found that this turned a valid FP32 scale of 1e-40 into zero and 65536 into infinity. The helper now dequantizes at the caller's FP32 dtype for that fallback. Torch AWQ forward continues to use FP16/BF16 compute dtype.
  3. The reference page now describes post_init adapter initialization, the BF16 bias behavior after post_init, the FP32 ParoQuant fallback, and the actual adapter/cast order.

Runtime flow

flowchart TD
    A["AwqTorchLinear.forward: FP16 or BF16 compute"] --> H["_dequantize_weight_for_inference"]
    P["ParoLinear._forward_dense: caller FP32 input"] --> H
    H --> S["_scales_for_compute: call-local scales in caller dtype"]
    S --> G["dequantize_gemm: call-local dense weight"]
    G --> D{"weight dtype is FP16, BF16, or FP32?"}
    D -- yes --> M["caller consumes weight and releases reference"]
    D -- no --> X["AssertionError"]
    M -. "stored scales unchanged" .-> K["checkpoint precision retained"]
    classDef failure fill:#fce8e6,stroke:#a33,color:#111
    class X failure
Loading
Path Earlier behavior Current behavior
Regression oracle Read buffers after the bug could mutate them Original source values and independent packed-code decode (tests/kernels/test_awq_torch.py:154)
FP32 ParoQuant fallback FP32 scale narrowed to FP16 before decode, then widened; valid values became 0 or inf FP32 temporary scale and FP32 decode (gptqmodel/nn_modules/qlinear/torch_awq.py:180)
Stored tensors Checkpoint scales and bias remain source dtype Same; temporary dense weight is released after the call

Validation

  • NVIDIA CUDA: 14 AWQ Torch cases passed; 48 focused AWQ, ParoQuant bias, packing, and affine-range cases passed. CPU: all 14 AWQ Torch cases passed. ParoQuant focused cases: 15 passed, 4 skipped, with the two native CUDA-extension tests excluded because this host's nvcc build fails before they run. The original PR head reported 12 AWQ cases passing on AMD ROCm; the two new FP32 boundary cases have not been rerun there.
  • The FP32 boundary cases compare packed-code decode exactly for scales 1, 1e-40, and 65536; the new ParoQuant FP32 forward case checks the 65536 scale and no retained dense weight (rtol=atol=0).
  • PYTHON_GIL=0 AWQ FP32 dequantization probe: 3 separate processes passed, each with 8 threads × 4 iterations across two NVIDIA PG506 GPUs.
  • Direct 128×128 CUDA dequantization microbenchmark on NVIDIA PG506-230, 5 groups × 100 calls, CUDA events: previous half-then-widen median 333.30 μs; FP32 decode median 317.54 μs. Peak allocator delta was 448 KiB vs 512 KiB; both returned a 64 KiB temporary weight and retained 0 B of expanded weight after forward. These figures cover the decode helper, not full model inference.

The earlier head also reported 66 nearby CUDA cases, 137 CUDA bias/fusion cases, and 196 ParoQuant unit cases passing; those larger groups were not rerun after the review commit.

Dequantize at the stored half precision when the compute dtype is not
half, so the ParoQuant dense fallback keeps working instead of raising
the half-weight assertion.

Make the regression oracle use the original checkpoint-precision
scales/bias instead of the live buffers, and run each forward before the
buffer assertions, so the numeric corruption is pinned rather than only
the buffer dtype.

Correct the reference page: post_init also initializes the adapter, and a
BF16 forward after post_init sees the FP16-narrowed -inf bias (the
-65536/0 case only applies to a runtime cast without post_init).
@ZX-ModelCloud
ZX-ModelCloud force-pushed the fix/awq-forward-review-followup branch from ca386fb to 2181b0c Compare November 12, 2026 09:42

Copy link
Copy Markdown
Collaborator

Review of PR #3802 at 9184d10f:

  • The checkpoint-precision oracle now uses the original scales and bias, and decodes the packed INT4 words independently. This makes the -65535 bias cancellation and tiny BF16-scale regressions fail numerically on the old code instead of merely failing dtype assertions.
  • I found and fixed one additional issue in the proposed non-half path: an FP32 ParoQuant input cast FP32 scales through FP16 before widening the weight. The regression reproduced 1e-40 → 0 and 65536 → inf; the helper now dequantizes in FP32 for FP32 inputs. An integrated ParoQuant FP32 forward test checks the finite result and that no dense weight remains attached to the module.
  • The reference page and PR flow now match the implementation, including adapter ordering. No native AWQ backend contracts were changed.
  • Validation on this host: 14/14 AWQ Torch cases passed on CUDA and separately on CPU; 48 focused AWQ/ParoQuant bias/packing/affine cases passed; 15 ParoQuant focused cases passed with 4 architecture skips. The two native CUDA extension tests could not run because this host's nvcc JIT build fails before test execution. Ruff passed. The GIL-disabled FP32 AWQ decode probe passed 3 separate 8-thread runs across two NVIDIA GPUs. The new FP32 boundary cases were not rerun on ROCm.
  • Direct 128×128 CUDA decode microbenchmark (5 × 100 calls): FP32 median 317.54 μs vs 333.30 μs for half-then-widen; peak allocator delta 512 KiB vs 448 KiB. The returned dense weight is 64 KiB and no expanded weight persists after forward. This is a helper benchmark, not model inference.

The remaining GitHub CodeQL check is still in progress; I will merge after it completes successfully.

@Qubitium Qubitium left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the FP32 scale fallback, independent checkpoint oracle, ParoQuant forward regression, storage lifetime, and focused CUDA/CPU tests. The precision gap found during review is fixed in 9184d10; review notes and validation are in the PR discussion.

@Qubitium
Qubitium merged commit 9ce9ddb into main Nov 12, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/awq-forward-review-followup branch November 12, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants