Repository navigation
fix(gguf): add C++ backend bias before output rounding - #3739
Merged
Merged
Conversation
This was referenced Nov 9, 2026
Collaborator
Author
|
Clean review found CUDA GGML could overflow before FP32 bias cancellation. Fixed in #3789; the packed Q8_0 GPU oracle and CI pass. |
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.
Problem
GGUFCppKernel.forwardandGGUFCudaKernel.forwardcast a GGML product and the stored bias to the activation dtype before addition. A Q8_0 dot product of 100000 canceled by FP32 bias -100000 can becomeNaNinstead of zero. The CPU Torch fallback also added bias after output rounding.Fix
Add bias to FP32 GGML outputs before casting to the activation dtype. When GGML returns an already rounded FP16/BF16 product, recompute only the biased case from a temporary FP32 decoded weight. Pass bias into the existing CPU Torch fused/dense epilogues. CPU autotuning now times the full biased paths.
flowchart TD A["GGUF C++ CPU or CUDA forward"] --> B["Run GGML matmul"] B --> C{"GGML output low precision and bias exists?"} C -- Yes --> D["Temporary FP32 decode and matmul"] D --> E["Add original bias in FP32"] C -- No --> E E --> F["Round once to activation dtype"] G["CPU Torch fallback"] --> H["Pass bias into fused or dense matmul"] H --> F I["Old product-before-bias cast"] --> X["Overflow or cancellation error"] classDef failure fill:#fdd,stroke:#c33 class X failureCommitted flow page, linked from README.
Validation
tests/kernels/test_gguf_cpp_bias_epilogue.py tests/kernels/test_gguf_cpp.py tests/test_cpu_bias_cancellation.py: 12 passed, 18 skipped on CPU. The new tests compare packed Q8_0 output with an independent FP64 decode and matmul, including repeated calls, both GGML output dtypes, and the Torch fallback.git diff --check: passed.No backward compatibility is retained except for
hf_APIs.