Instructions to use mlx-community/gemma-4-31B-it-qat-OptiQ-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use mlx-community/gemma-4-31B-it-qat-OptiQ-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("mlx-community/gemma-4-31B-it-qat-OptiQ-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 Settings
- LM Studio
- Pi
How to use mlx-community/gemma-4-31B-it-qat-OptiQ-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 "mlx-community/gemma-4-31B-it-qat-OptiQ-4bit"
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "mlx-community/gemma-4-31B-it-qat-OptiQ-4bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- MLX LM
How to use mlx-community/gemma-4-31B-it-qat-OptiQ-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 "mlx-community/gemma-4-31B-it-qat-OptiQ-4bit"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "mlx-community/gemma-4-31B-it-qat-OptiQ-4bit" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlx-community/gemma-4-31B-it-qat-OptiQ-4bit", "messages": [ {"role": "user", "content": "Hello"} ] }' - Hermes Agent
How to use mlx-community/gemma-4-31B-it-qat-OptiQ-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 "mlx-community/gemma-4-31B-it-qat-OptiQ-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 mlx-community/gemma-4-31B-it-qat-OptiQ-4bit
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use mlx-community/gemma-4-31B-it-qat-OptiQ-4bit with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/gemma-4-31B-it-qat-OptiQ-4bit"
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "mlx-community/gemma-4-31B-it-qat-OptiQ-4bit" \ --custom-provider-id mlx-lm \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
mlx-community/gemma-4-31B-it-qat-OptiQ-4bit
Built with mlx-optiq, the MLX-native toolkit to quantize, fine-tune, and serve LLMs locally on Apple Silicon, no PyTorch and no cloud. Try the Lab · All OptiQ quants · Docs
A 4-bit mixed-precision MLX quant produced by mlx-optiq, built on Google's quantization-aware-trained (QAT) Gemma-4 base. This is the flagship of the family: the 31B dense Gemma-4, and the strongest OptiQ quant on the Capability Score. OptiQ's sensitivity-guided per-layer bit allocation is applied on top of weights already trained to survive low-bit quantization, and it still beats a uniform 4-bit quant of the same QAT base by +1.65 Capability Score points.
This is a quant of google/gemma-4-31B-it-qat-q4_0-unquantized. Per-layer bit-widths come from a KL-divergence sensitivity pass on a six-domain calibration mix (prose, reasoning, code, agent, tool-call, constraint-bearing instructions). Sensitive layers go to 8-bit, robust ones stay at 4-bit.
Quantization details
| Property | Value |
|---|---|
| Base | google/gemma-4-31B-it-qat-q4_0-unquantized (QAT, dense) |
| Predominant precision | 4-bit |
| Components at 8-bit (sensitive) | 186 |
| Components at 4-bit (robust) | 224 |
| Total quantized components | 410 |
| Achieved bits-per-weight | 5.20 |
| Group size | 64 |
| Reference for sensitivity | uniform 4-bit (streamed) |
| Calibration mix | six-domain mix |
| Vision | bf16 sidecar (optiq_vision.safetensors), image+text via optiq |
| Speculative drafter | google/gemma-4-31B-it-qat-q4_0-unquantized-assistant via optiq serve --drafter |
Capability Score
Six-metric mean (MMLU, GSM8K, IFEval, BFCL, HumanEval, HashHop), scored against a uniform 4-bit quant of the same QAT base. That comparison isolates what the mixed-precision allocation adds, holding the base fixed.
| Benchmark | This model (OptiQ, QAT base) | Uniform-4 (QAT base) | Delta |
|---|---|---|---|
| MMLU (5-shot, 1000) | 72.7% | 72.4% | +0.3 |
| GSM8K (1000) | 96.3% | 96.6% | -0.3 |
| IFEval (full, strict) | 77.8% | 77.4% | +0.4 |
| BFCL-V3 simple (200) | 93.0% | 93.0% | +0.0 |
| HumanEval (pass@1, 164) | 93.3% | 92.7% | +0.6 |
| HashHop (long-context) | 59.0% | 50.0% | +9.0 |
| Capability Score (mean) | 82.01 | 80.36 | +1.65 |
OptiQ adds +1.65 points over uniform 4-bit on this QAT base, the largest margin in the Gemma-4 family alongside the small QAT models (E2B +2.09, E4B +1.19, 12B +1.37). The gain concentrates in long-context retrieval (HashHop +9.0): the per-layer allocation puts 8-bit on the attention and projection layers that carry the retrieval signal, which the larger model leans on most. The mixed quant is 5.20 bits-per-weight (about 20.8 GB on disk) versus 4.0 bits-per-weight (about 16.1 GB) for uniform 4-bit, with the extra budget spent on the layers that need it.
Usage
This is a Gemma-4 (model_type: gemma4, gemma4_text), so it needs mlx-lm from main and import optiq (the Gemma-4 text tower is not in the 0.31.3 PyPI release; the main build also reports 0.31.3, so install from git, not a version pin):
pip install -U mlx-optiq "mlx-lm @ git+https://github.com/ml-explore/mlx-lm.git"
import optiq # registers the OptiQ model paths
from mlx_lm import load, generate
model, tokenizer = load("mlx-community/gemma-4-31B-it-qat-OptiQ-4bit")
print(generate(model, tokenizer, "Explain mixed-precision quantization.", max_tokens=256))
Image+text input and the speculative drafter run through mlx-optiq:
pip install mlx-optiq
optiq serve --model mlx-community/gemma-4-31B-it-qat-OptiQ-4bit \
--drafter google/gemma-4-31B-it-qat-q4_0-unquantized-assistant
The language and image+text paths both run through optiq. The bf16 vision tower rides in optiq_vision.safetensors, which mlx-lm ignores (it globs model*.safetensors), so both paths work from one artifact.
- Downloads last month
- 2,016
4-bit
Model tree for mlx-community/gemma-4-31B-it-qat-OptiQ-4bit
Base model
google/gemma-4-31B