Repository navigation
fix(gguf): preserve FP32 bias range - #3727
Merged
Merged
Conversation
Qubitium
force-pushed
the
codex/fix-gguf-bias-range
branch
3 times, most recently
from
November 9, 2026 18:39
88fcc4b to
2d798e3
Compare
Qubitium
force-pushed
the
codex/fix-gguf-bias-range
branch
from
November 9, 2026 19:07
e0de9f1 to
88b0dbc
Compare
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.
Summary
Preserve FP32 GGUF bias from packing through BF16 checkpoint reload and the public
GGUFTorchLinear.forwardhandoff. The dense path now moves bias to the activation device without narrowing it, and returns the activation dtype after the matmul. No dense weight cache or compatibility shim was added; nohf_API changed.Why
An FP32 GGUF bias survived packing but was rounded to BF16 by Accelerate during BF16 checkpoint load. Public
GGUFTorchLinear.forwardalso cast the bias to the activation dtype before dispatch. For a Q8_0 FP16 case with a100000dot and-100000FP32 bias, the old public output was-infinstead of0. A BF16 case with a99840dot and-100000bias returned0instead of-160.Flow
flowchart TD A["ModelLoader.from_quantized collects GGUFTorchLinear bias names"] --> B["load_checkpoint_in_model_then_tie_weights"] B --> C{"BF16 requested?"} C -- "Yes" --> D["Accelerate loads checkpoint as BF16"] D --> E["_restore_fp32_checkpoint_buffers reads selected source biases"] E -- "Missing source, invalid buffer or shape" --> X["Raise RuntimeError"] E -- "Valid slot" --> F["Store FP32 bias on the loaded device"] C -- "No" --> G["Accelerate load; FP16 keep list applies when needed"] F --> H["GGUFTorchLinear.forward keeps original bias dtype"] G --> H H -- "Dense" --> I["Pass bias to _forward_dequant_matmul"] H -- "Fused" --> J["Pass bias to _forward_fused_k"] I --> K["Return activation dtype"] J --> K classDef failure fill:#fce8e6,stroke:#a33,color:#111 class X failuremodels/loader.py:2364,utils/model.py:2749)keep_in_fp32_modulesdid not prevent Accelerate from narrowing GGUF biasnn_modules/qlinear/gguf.py:1915)_forward_dequant_matmulThe selective reread now matches Accelerate’s directory file preference and errors when any requested bias is absent. Tests cover a missing index entry and a directory containing both whole-file formats.
Reference flow and numerical examples: GGUF dense fallback precision.
Validation
.bin, plus BF16 safetensors key remapping.pytest tests/test_gguf_bias_range.py tests/test_cpu_bias_cancellation.py tests/kernels/test_gguf_torch_cpu.py -q: 38 passed.ruff checkandgit diff --check: passed.llama-cpp-pythonis absent for those quantizers. CUDA, ROCm, and native llama.cpp output were not validated on this CPU host.Scope and #3728 follow-up
Merged #3728 widened the CPU dense reduction inside
_forward_dequant_matmul. This PR leaves that reduction and CPU autocast handling unchanged. Preserving FP32 bias through publicforwardalso removes pre-dispatch narrowing that affected #3728's public path. A distinct cancellation defect remains under CPU BF16 autocast: the FP16 Q8_0100000 + (-100000)case should return0but currently returns-160. That reduction/autocast fix belongs in a separate follow-up PR.