Text-only: Vision and audio towers are stripped. Image/audio inputs are not supported.
RMSNorm convention: MLX's nn.RMSNorm uses (1 + weight) * x internally via mx.fast.rms_norm.
This matches how mlx-lm handles Gemma 3, so weight loading should be consistent.
Quantization differences: Q4-quantized models may produce slightly different outputs compared to bf16.
Troubleshooting
"Model type gemma4 not supported"
Ensure gemma4.py and gemma4_text.py are correctly copied into mlx_lm/models/.
"Model type gemma4_text not supported"
Some text-only checkpoints set model_type to gemma4_text in config.json. Both files must be installed.
Output is garbled or repetitive
Check the RMSNorm weight convention. Run validate_gemma4.py --numerical for numerical verification.
Out of memory
Use --max-kv-size 512 to limit KV cache size.
File Structure
gemma4_text.py # Core text model (Attention, MLP, MoE, PLE, etc.)
gemma4.py # Multimodal wrapper (text_config extraction, weight sanitization)
validate_gemma4.py # Validation script
install.sh # One-command installer
README.md # This file
Tested Environments
Hardware
Machine
Chip
Unified Memory
Model
Quant
Peak Memory
Generation Speed
MacBook Air M5
Apple M5
24 GB
gemma-4-E2B-it
Q4
2.66 GB
~80 tok/s
MacBook Pro M5
Apple M5 Pro
36 GB
gemma-4-E2B-it
Q4
—
—
Software
macOS 25 (Tahoe) / macOS 15.3+ (Sequoia)
Python 3.11+
mlx >= 0.22.0
mlx-lm >= 0.31.0
License
This implementation is licensed under the Apache License 2.0.
The Gemma 4 model weights are subject to Google's Gemma license.