Repository navigation
fix(gguf): correct CUDA bias cancellation after native matmul - #3789
Merged
Merged
Conversation
Collaborator
Author
|
Reviewed: the CUDA FP32 cancellation case now matches the independent packed-weight oracle. All 8 focused GPU/CPU tests and CI pass; no dense weight remains after forward. |
This was referenced Nov 12, 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.
Fix
GGML CUDA can return an FP32 container after its product has already rounded or overflowed. For biased CUDA forwards, recompute the product from a temporary FP32 decoded weight, add the stored FP32 bias, then round once. Unbiased forwards keep the native result. The temporary weight is released after the call.
flowchart TD A["GGUF CUDA forward"] --> B["Run GGML matmul"] B --> C{"Stored bias?"} C -- "No" --> D["Return native output"] C -- "Yes" --> E["Decode packed weight temporarily to FP32"] E --> F["FP32 matmul plus FP32 bias"] F --> G["Round once to activation dtype"] H["Old FP32 native product"] --> I["Overflow or rounded cancellation"] classDef failure fill:#fdd,stroke:#c33 class I failuregptqmodel/nn_modules/qlinear/gguf_cpp.py:833infor roundedValidation: 8 focused CUDA/CPU cases and 96 broader cases passed. Packed Q8_0 FP16/BF16/FP32 cancellation matches an independent FP64 oracle; repeated forwards retain no dense weight. On RTX 4090, synthetic Q8_0 1×1024×1024 biased forward median was 0.118 ms versus 0.050 ms before (+4 MiB transient weight). Reference:
docs/gguf-cpp-bias-epilogue.md.Fixes #3739.