Views
No views yet
gemma4_text.py that causes garbage output (repeating tokens). This affects ALL Gemma 4 MLX models.mlx_lm/models/gemma4_text.py, find the Attention.__init__ method, and change:1# BEFORE (broken):
2self.scale = self.head_dim ** -0.5
3
4# AFTER (fixed):
5self.scale = 1.01python3 -c "import mlx_lm; print(mlx_lm.__file__)"
2# Then edit models/gemma4_text.py in that directory1from mlx_lm import load, generate
2
3model, tokenizer = load("Phipper/gemma-4-31b-it-mlx-4bit")
4
5messages = [{"role": "user", "content": "What is the capital of France?"}]
6prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
7response = generate(model, tokenizer, prompt=prompt, max_tokens=200)
8print(response)| Metric | Value |
|---|---|
| Prefill speed | ~100 tok/s |
| Generation speed | ~33 tok/s |
| Peak memory | 17.5 GB |
| Quantization | 4-bit (group 64) |