Skip to content

fix(gptq): fuse CPU low-precision bias epilogue - #3747

Merged
Qubitium merged 1 commit into
mainfrom
codex/fix-gptq-torch-cpu-bias
Nov 9, 2026
Merged

Qubitium merged 1 commit into
mainfrom
codex/fix-gptq-torch-cpu-bias

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Defect

Packed GPTQ TorchLinear on CPU rounds FP16/BF16 matmul before adding bias. A 512-channel FP16 dot of 65,536 plus a bias of -65,504 returned inf instead of 32. Narrowing an FP32 checkpoint bias to FP16 can also overflow.

Fix

Use torch.addmm for CPU FP16/BF16 biased forwards, with CPU autocast disabled for this call. Matching low-precision operands use the fused epilogue directly; wider checkpoint metadata uses an FP32 addmm and one final cast. Packed checkpoint buffers stay unchanged; the dequantized weight remains a temporary.

Path Before After
CPU FP16/BF16 bias Matmul rounds before bias One addmm epilogue
FP32 checkpoint bias Bias narrows to input dtype FP32 addmm then final cast
Other paths Existing dispatch Existing dispatch
flowchart TD
    A["TorchLinear._forward_eager"] --> B["Decode temporary packed weight"]
    B --> C{"CPU FP16/BF16 and bias?"}
    C -- No --> D["Existing matmul_fp32_reduce"]
    C -- Yes --> E["Disable CPU autocast"]
    E --> F{"Metadata matches input dtype?"}
    F -- Yes --> G["Low-precision addmm with bias"]
    F -- No --> H["FP32 addmm, then cast once"]
    G --> I["Return output"]
    H --> I
    D --> I
Loading

See the committed logic-flow document, linked from README.

Validation

  • 7 new packed CPU oracle/gradient cases passed.
  • Broader packed storage selection: 161 passed, 32 deselected.
  • Ruff and git diff --check passed.
  • Tests cover FP16 overflow cancellation, BF16 rounding residual, FP32 bias range, autocast, repeated forwards, packed-state stability, temporary-weight release, and input gradient.
  • CPU one-thread op microbenchmarks were roughly 0.39 ms for both old matmul-plus-bias and low-precision addmm at this shape; host noise limits interpretation. CUDA/ROCm were not available for this CPU-specific case.

No backward compatibility is retained except for hf_-prefixed APIs.

@Qubitium
Qubitium merged commit 84c8e59 into main Nov 9, 2026
6 checks passed
@Qubitium
Qubitium deleted the codex/fix-gptq-torch-cpu-bias branch November 9, 2026 19:44
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.

1 participant