feat(tools): canonical Gemma 4 Unified .tern-model PPL loader - #59
Open
synapticode-ai wants to merge 1 commit into
Open
feat(tools): canonical Gemma 4 Unified .tern-model PPL loader#59synapticode-ai wants to merge 1 commit into
synapticode-ai wants to merge 1 commit into
Conversation
The stock tern_ppl_bench --tern-model-path path drives TernModelReader.load_packed_model, whose module-tree walker raises on the Gemma 4 Unified manifest: text-tower tensors are stored under logical Gemma names (model.layers.*) while transformers 5.10 nests the decoder under model.language_model.*, and the FP16 inline multimodal projectors (embed_vision/embed_audio/vision_embedder) have no submodule on a text AutoModelForCausalLM. This adds tools/gemma4_unified_ppl.py: a tolerant streaming overlay that (1) bridges logical names to the transformers-5.10 tree via the canonical GEMMA4_MULTIMODAL_TRANSFORMERS_5_5 preset, (2) places reconstructed weights by flat state-dict key one layer at a time (bounded memory), (3) skips text-irrelevant multimodal keys while HARD-FAILING if any ternary/INT4 entry fails to place, then (4) computes PPL with the harness's canonical R7-A evaluate_ppl so the number is methodology-identical to the FP baseline. Validated on google/gemma-4-12B base (Q15): BF16 8.4638 -> t0.7 ternary 1.44e9, overlay placed=667/fail=0 (only 10 vision projectors skipped). Adds tests/test_gemma4_unified_ppl_loader.py — name-bridge + strict-quant gate (placement, multimodal skip, missing-quant abort, shape mismatch), lightweight fakes, no model download. 5/5 pass. Co-Authored-By: Claude Opus 4.8 (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.
What
Adds
tools/gemma4_unified_ppl.py— the canonical text-only WikiText-2 PPL path for Gemma 4 Unified (gemma4_unified/Gemma4UnifiedForConditionalGeneration).tern-modelartefacts.Why
tern_ppl_bench --tern-model-pathdrivesTernModelReader.load_packed_model, whose module-tree walker raises on the Unified manifest:model.layers.*,model.embed_tokens.*,model.norm.*) while transformers 5.10 nests the decoder undermodel.language_model.*;embed_vision/embed_audio/vision_embedder) have no submodule when the checkpoint is loaded as a textAutoModelForCausalLM, and are irrelevant to a text-only forward.How
A tolerant streaming overlay:
GEMMA4_MULTIMODAL_TRANSFORMERS_5_5preset;evaluate_ppl— methodology-identical to the FP baseline.Validation
google/gemma-4-12B base (Q15 quality leg): BF16 PPL 8.4638 → t0.7 ternary 1.44e9 (overlay
placed=667 / fail=0, only the 10 vision projectors skipped). Evidence onecc-ternaryresultsbranch (compression-quality/GEMMA4_12B_BASE_QUALITY_20260610T235557Z).Tests
tests/test_gemma4_unified_ppl_loader.py— name-bridge + strict-quant gate (placement, multimodal skip, missing-quant abort, shape mismatch) with lightweight fakes, no model download. 5/5 pass locally.🤖 Generated with Claude Code