Repository navigation
fix(gptq): fuse CPU low-precision bias epilogue - #3747
Merged
Merged
Conversation
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.
Defect
Packed GPTQ
TorchLinearon CPU rounds FP16/BF16 matmul before adding bias. A 512-channel FP16 dot of 65,536 plus a bias of -65,504 returnedinfinstead of 32. Narrowing an FP32 checkpoint bias to FP16 can also overflow.Fix
Use
torch.addmmfor 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.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 --> ISee the committed logic-flow document, linked from README.
Validation
git diff --checkpassed.No backward compatibility is retained except for
hf_-prefixed APIs.