Skip to content

fix(gguf): correct CUDA bias cancellation after native matmul - #3789

Merged
Qubitium merged 1 commit into
mainfrom
fix/gguf-cuda-finite-bias-3739
Nov 12, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/gguf-cuda-finite-bias-3739

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

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 failure
Loading
Path Before After
Biased CUDA, gptqmodel/nn_modules/qlinear/gguf_cpp.py:833 Trusted FP32 GGML output even when product was already inf or rounded Recomputes product and bias in FP32 before output conversion
Unbiased CUDA Native GGML result Native GGML result

Validation: 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.

Copy link
Copy Markdown
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.

@Qubitium
Qubitium merged commit 4540829 into main Nov 12, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/gguf-cuda-finite-bias-3739 branch November 12, 2026 02:48
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