Repository navigation
fix(gguf): honour a per-module ggml type in dynamic - #3562
Merged
Merged
Conversation
`GGUFConfig` stores a per-module width and ggml type in separate fields,
because one width maps to several types: width 4 is `q4_0`/`q4_1`/`q4_k`,
width 2 is `q2_0`/`q2_k`, width 5 is `q5_0`/`q5_k_m`. `create_quant_module`
read only the digits and let `_GGUF_DEFAULT_BITS_ALIAS_BY_WIDTH` pick the
type, so a mixed-type checkpoint silently reloaded every module at the
*default* type for its width and discarded the requested one.
Fold the `format` override back into the structured spec before the module
is constructed, so `{"bits": 4, "format": "q4_k"}` builds a `Q4_K` module
rather than a `Q4_0` one.
Measured on a q3_k/q4_k mixed checkpoint: 7 of 14 modules reloaded as
`Q4_0` before this change, 0 after.
Resolve dynamic widths and formats independently to match the per-module quantization config. Inherit the base subtype for width-only overrides and only the base width for raw format-only overrides. Use GGUFTorchLinear for regression tests so they run without the optional llama-cpp-python runtime. Cover config serialization, packed state loading, explicit formats, inherited formats, unmatched patterns, and exclusions. Validation: 98 targeted tests passed; Ruff and git diff --check passed. Four new regression cases fail on the previous PR head.
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.
Bug
GGUFConfigaccepts a per-module width and a per-module ggml type:Two fields are needed because a width maps to several types — width 4 is
q4_0/q4_1/q4_k, width 2 isq2_0/q2_k, width 5 isq5_0/q5_k_m.create_quant_moduleread only the digits and let_GGUF_DEFAULT_BITS_ALIAS_BY_WIDTHchoose the type. A mixed-type checkpointtherefore reloaded every module at the default type for its width and
discarded the requested one.
Measured on a real q3_k/q4_k mixed checkpoint: 7 of 14 modules reloaded as
Q4_0instead of their assigned type. Silent — no warning, no error.Fix
Fold the
formatoverride back into the structured spec before the module isconstructed, so
{"bits": 4, "format": "q4_k"}builds aQ4_Kmodule ratherthan a
Q4_0one.Mirrors the existing FP8 / bitsandbytes override branches a few lines above,
which already resolve their format field the same way.
Test
tests/test_gguf_dynamic_format.py— the cases are chosen so the requestedtype is never the default for its width, which is what makes them catch the
bug:
q4_kq4_0Q4_0Q4_Kq4_1q4_0Q4_0Q4_1q2_kq2_0Q2_0Q2_Kq5_0q5_k_mQ5_K_MQ5_0A guard test asserts the table really is non-default, so a future change to the
default mapping cannot silently turn these into no-ops.
5 passed with the fix; 4 of 5 fail on unmodified
upstream/main. Ruff clean.