Views
No views yet
gemma4_unified architecture, useful for:Gemma4UnifiedForConditionalGeneration model path| Parameter | Original | Tiny |
|---|---|---|
| text_config.num_hidden_layers | 48 | 6 |
| text_config.hidden_size | 3840 | 2048 |
| text_config.intermediate_size | 15360 | 1536 |
sliding_attention + 1× full_attention. Attention shape is unchanged
(16 heads, 8 KV heads, head_dim 256), and the full 262,144-token vocabulary is
retained. The vision (gemma4_unified_vision) and audio towers are left at base
size; they are small relative to the shared token embedding.model.safetensors). Key naming matches the original
checkpoint format (model.language_model.*, model.embed_vision.*,
model.embed_audio.*, model.vision_embedder.*). Module-path structure was
verified equal to the base checkpoint's safetensors header.1from transformers import AutoModelForImageTextToText, AutoProcessor
2
3model = AutoModelForImageTextToText.from_pretrained(
4 "soyrsoyr/gemma-4-unified-0.8B-tiny", device_map="auto"
5)
6processor = AutoProcessor.from_pretrained("soyrsoyr/gemma-4-unified-0.8B-tiny")
7
8input_ids = processor.tokenizer("According to all known laws", return_tensors="pt").input_ids.to(model.device)
9output = model.generate(input_ids, max_new_tokens=20)
10print(processor.tokenizer.decode(output[0]))AutoModelForCausalLM resolves this architecture (transformers maps
gemma4_unified into the causal-LM auto-class), so the default
load_offloaded_model() pattern works directly:1from transformers import AutoModelForCausalLM
2from compressed_tensors.offload import load_offloaded_model
3from compressed_tensors.distributed import init_dist
4
5init_dist()
6with load_offloaded_model(): # patches AutoModelForCausalLM
7 model = AutoModelForCausalLM.from_pretrained(
8 "soyrsoyr/gemma-4-unified-0.8B-tiny",
9 device_map="auto_offload", # weights on CPU/disk, GPU for activations
10 )inspect_config.pysave_tiny_model.py, adapted for the
multimodal class (AutoModelForImageTextToText.from_config); only the text
tower was shrunk and any all-zero / non-finite / extreme param was fixed after
init_weights()validate_tiny_model.pyembed_vision.multimodal_embedder.embedding_projection) reads
text_config.hidden_size for its output dim, so it auto-aligns to the reduced
2048 hidden. vision_config.output_proj_dims / mm_embed_dim are
intentionally left unchanged — editing them flips the modeling code to a
different (flattened vision_embedder) module tree that no longer matches the
original checkpoint layout.tie_word_embeddings=True: lm_head shares embed_tokens and is not stored
as a separate tensor.Success: 1.0278589725494385 <= 10.0