Instructions to use Phipper/gemma-4-31b-it-mlx-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use Phipper/gemma-4-31b-it-mlx-4bit with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("Phipper/gemma-4-31b-it-mlx-4bit") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- LM Studio
- Pi new
How to use Phipper/gemma-4-31b-it-mlx-4bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "Phipper/gemma-4-31b-it-mlx-4bit"
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "Phipper/gemma-4-31b-it-mlx-4bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use Phipper/gemma-4-31b-it-mlx-4bit with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "Phipper/gemma-4-31b-it-mlx-4bit"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default Phipper/gemma-4-31b-it-mlx-4bit
Run Hermes
hermes
- MLX LM
How to use Phipper/gemma-4-31b-it-mlx-4bit with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "Phipper/gemma-4-31b-it-mlx-4bit"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "Phipper/gemma-4-31b-it-mlx-4bit" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Phipper/gemma-4-31b-it-mlx-4bit", "messages": [ {"role": "user", "content": "Hello"} ] }'
Gemma 4 31B-IT (MLX, 4-bit)
Gemma 4 31B Instruct quantized to 4-bit for Apple Silicon using MLX.
- Base model: google/gemma-4-31B-it
- Quantization: 4-bit, group size 64, affine mode
- Memory: ~17.5 GB
- Speed: ~33 tok/s generation, ~100 tok/s prefill (M3 Ultra)
Important: mlx-lm Bug Fix Required
mlx-lm 0.31.1 has a bug in gemma4_text.py that causes garbage output (repeating tokens). This affects ALL Gemma 4 MLX models.
One-line fix
In your mlx-lm installation, edit mlx_lm/models/gemma4_text.py, find the Attention.__init__ method, and change:
# BEFORE (broken):
self.scale = self.head_dim ** -0.5
# AFTER (fixed):
self.scale = 1.0
Gemma 4 uses Q/K norms instead of scaled dot-product attention, so the attention scale should be 1.0.
To find the file:
python3 -c "import mlx_lm; print(mlx_lm.__file__)"
# Then edit models/gemma4_text.py in that directory
This fix is tracked in PR #1093 on ml-explore/mlx-lm.
Usage
from mlx_lm import load, generate
model, tokenizer = load("Phipper/gemma-4-31b-it-mlx-4bit")
messages = [{"role": "user", "content": "What is the capital of France?"}]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
response = generate(model, tokenizer, prompt=prompt, max_tokens=200)
print(response)
Benchmarks (M3 Ultra, 96GB)
| Metric | Value |
|---|---|
| Prefill speed | ~100 tok/s |
| Generation speed | ~33 tok/s |
| Peak memory | 17.5 GB |
| Quantization | 4-bit (group 64) |
Model Details
Gemma 4 31B features:
- 60 transformer layers with sliding + full attention pattern
- 32 attention heads, 16 KV heads (sliding), 4 global KV heads
- Head dim 256 (sliding), 512 (global)
- K-eq-V attention for global layers
- 262K vocabulary, up to 256K token context
- Built-in reasoning mode (thinking channel)
Credits
- Created by Nate Baranski (@Phipper)
- Model by Google DeepMind
- MLX architecture support by Prince Canuma
- Bug fix, quantization & evaluation: Nate Baranski + Bessemer (Claude Code agent)
- Downloads last month
- 389
Model size
5B params
Tensor type
BF16
·
U32 ·
Hardware compatibility
Log In to add your hardware
4-bit