Instructions to use Xylolabs/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 Xylolabs/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("Xylolabs/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 Settings
- LM Studio
- Pi
How to use Xylolabs/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 "Xylolabs/gemma-4-31B-it-MLX-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": "Xylolabs/gemma-4-31B-it-MLX-4bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- MLX LM
How to use Xylolabs/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 "Xylolabs/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 "Xylolabs/gemma-4-31B-it-MLX-4bit" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8080/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Xylolabs/gemma-4-31B-it-MLX-4bit", "messages": [ {"role": "user", "content": "Hello"} ] }' - Hermes Agent
How to use Xylolabs/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 "Xylolabs/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 Xylolabs/gemma-4-31B-it-MLX-4bit
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use Xylolabs/gemma-4-31B-it-MLX-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 "Xylolabs/gemma-4-31B-it-MLX-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 "Xylolabs/gemma-4-31B-it-MLX-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"
gemma-4-31B-it MLX 4-bit
google/gemma-4-31B-it converted to MLX for mlx-lm, text only: the vision tower is left out. Affine quantization, group size 64, scales and biases in bfloat16. 4-bit: every linear layer, except the token embedding (also the LM head) at 8-bit. Norms and the other unquantized tensors in bfloat16.
How to run
pip install mlx-lm==0.32.2
mlx_lm.generate --model Xylolabs/gemma-4-31B-it-MLX-4bit --prompt "Explain how a heat pump works."
mlx_lm.chat --model Xylolabs/gemma-4-31B-it-MLX-4bit
Accuracy
KL and top-1 against MLX's own unquantized BF16 model on chat-template text (4 English and 4 Korean conversations, 8 x 1006 scored tokens); not against llama.cpp's BF16, which differs from MLX's by a KL of 0.16 to 0.27 on raw text. Raw text (WikiText-2, chat and held-out text, 40/20/20 chunks of 512; last chart) shows much larger KL for this model in every stack, llama.cpp's Q8_0 included.
| Quant | Size | Chat-template KL | top-1 | 7-question answer check |
|---|---|---|---|---|
| MLX 8-bit | 32.62 GB | 0.003032 | 98.36% | 7/7 (BF16: 7/7) |
| MLX 4-bit | 17.97 GB | 0.090060 | 90.52% | 7/7 (BF16: 7/7) |
Which file for your hardware
| Hardware | Memory | File | Context |
|---|---|---|---|
| Mac Studio M5 Max, 32-core GPU | 36 GB unified | Xylolabs/gemma-4-31B-it-MLX-4bit (4-bit, 17.97 GB) |
73K |
| Mac Studio M5 Max, 40-core GPU | 48 GB unified | Xylolabs/gemma-4-31B-it-MLX-4bit (4-bit, 17.97 GB) |
181K |
| Mac Studio M5 Max, 40-core GPU | 64 GB unified | Xylolabs/gemma-4-31B-it-MLX-8bit (8-bit, 32.62 GB) |
149K |
| Mac Studio M5 Ultra | 96 GB unified | Xylolabs/gemma-4-31B-it-MLX-8bit (8-bit, 32.62 GB) |
256K |
| Mac Studio M5 Max, 40-core GPU | 128 GB unified | Xylolabs/gemma-4-31B-it-MLX-8bit (8-bit, 32.62 GB) |
256K |
| Mac Studio M5 Ultra | 256 GB unified | Xylolabs/gemma-4-31B-it-MLX-8bit (8-bit, 32.62 GB) |
256K |
| Mac Studio M5 Ultra, 80-core GPU | 512 GB unified | Xylolabs/gemma-4-31B-it-MLX-8bit (8-bit, 32.62 GB) |
256K |
License and notices
Apache License 2.0, copied in LICENSE. We converted the weights to MLX and quantized them; see NOTICE.
Updates
- 2026-11-27: First release.
- Downloads last month
- 14
4-bit