fix(gemma4-gguf): accept scalar attention.head_count_kv - #190
Open
qxZap wants to merge 1 commit into
Open
Conversation
llama.cpp writes gemma4.attention.head_count_kv as a SCALAR when every layer shares a KV head count, and only as a per-layer array when they differ. The parser assumed the array form unconditionally, so any such checkpoint died at config-parse time: swa_kv = int(kv_per_layer[swa_layer_ids[0]]) ... TypeError: 'int' object is not subscriptable Reproduced with lmstudio-community/gemma-4-E2B-it-GGUF, whose metadata carries head_count_kv=1 (scalar) alongside a genuine 35-element sliding_window_pattern. Normalise to a per-layer list at the read site so both call sites below are unchanged. Note this fixes the crash, not dense gemma-4 support: parse_gguf_config still hardcodes moe_enabled=True and requires expert_count / expert_used_count / expert_feed_forward_length, which dense checkpoints do not carry. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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
parse_gguf_configtreatsgemma4.attention.head_count_kvas a per-layer arrayunconditionally, but llama.cpp writes it as a scalar when every layer shares a
KV head count, emitting an array only when they differ. Any such checkpoint dies
at config-parse time:
The backend worker then exits and the server shuts down, so the user sees only
{"error":"server unavailable: maintenance failed (restart required)"}.Reproducer
lmstudio-community/gemma-4-E2B-it-GGUF. Dumping the metadata the parser reads:So the file mixes both forms, and only
head_count_kvwas mis-typed.Fix
Normalise to a per-layer list at the read site, leaving both consumers below
unchanged.
hasattr(_kv, "__len__")rather thanisinstance(..., list)so numpyarrays from the reader are handled too.
Scope — please read
This fixes the crash, not dense gemma-4 GGUF support. Immediately after, the
same function hits:
because that key is per-layer on E2B (MatFormer). And beyond that,
parse_gguf_confighardcodesmoe_enabled=Trueand requiresexpert_count,expert_used_countandexpert_feed_forward_length, which dense checkpoints donot carry at all.
Auditing every
g(...)call site against a real file:attention.head_count_kvint=1— this PRfeed_forward_lengthlist(len=35)expert_countexpert_used_countexpert_feed_forward_lengthFull dense support looks like a feature, not a bug fix —
ModelConfigtakes asingle
intermediate_size, so per-layer FFN cannot be expressed without a schemachange, and the downstream model code assumes experts. I have kept this PR to the
one unambiguous type bug and am happy to close it if you would rather address the
whole dense path in one go.
Testing
Verified the parser gets past this line on the reproducer above (it then fails at
feed_forward_length, as described). No behaviour change for array-valuedcheckpoints: an input that was already a list takes the same path as before.
🤖 Generated with Claude Code