fix(gemma4): support dense Gemma-4 GGUF checkpoints - #359
Open
Cyber-Marty wants to merge 1 commit into
Open
Conversation
parse_gguf_config unconditionally required gemma4.expert_count and hardcoded moe_enabled=True, so a dense Gemma-4 GGUF (gemma-4-12B-it, gemma-4-31B-it) could not load at all — the GGUF path structurally could not represent a non-MoE checkpoint, while docs/models.md lists dense family members and GGUF is the documented non-safetensors path. Mirror the HF-side parse_config: default the expert fields to 0 when absent from the metadata, derive moe_enabled = num_experts > 0, and gate expert_quant/moe_weight_format on it. MoE GGUFs parse exactly as before. Regression tests build a minimal GGUF header (magic + version + zero counts) so the parser runs against metadata dicts without any model download: MoE keys present -> moe path unchanged; keys absent or zero -> dense path with expert_quant none. Fixes FlashML-org#357
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
parse_gguf_config(python/freetoken/models/gemma4/gguf.py) unconditionally requiredgemma4.expert_countand hardcodedmoe_enabled=True, so a dense Gemma-4 GGUF(
google/gemma-4-12B-it,nvidia/Gemma-4-31B-IT-NVFP4) could not load at all — theGGUF path structurally could not represent a non-MoE checkpoint, while
docs/models.mdlists dense family members and GGUF is the documented non-safetensors path.
Fix
Mirror what the HF side (
gemma4.config.parse_config) already does:path with
expert_quant="none"/moe_weight_format="none";moe_enabled=True,native-Q4_0 expert quant);
expert_count=0in metadata behaves the same as an absent key.Tests
New
tests/models/test_gemma4_gguf_config.py(3 cases). The fixture writes a minimalGGUF file (magic + version 3 + zero kv/tensor counts), so
GGUFReaderopens it and_full_rotary_dimtakes its metadata-only fallback — the config parser runs againstplain metadata dicts with no model download:
moe_enabled=True, q4_0 quant);expert_quant="none", geometry intact;tests/modelsfull run: 76 passed, 112 skipped; the 18 failures intests/models/qwen4_exp/test_weight.pyreproduce on unmodifiedmain(Windowsmmap/threading platform issues) and are unrelated to this change.
Fixes #357