Instructions to use Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx 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("Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx") 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 Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx"
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": "Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx" } ] } } }Run Pi
# Start Pi in your project directory: pi
- MLX LM
How to use Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx", "messages": [ {"role": "user", "content": "Hello"} ] }' - Hermes Agent
How to use Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx 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 "Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx"
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 Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx"
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 "Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx" \ --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"
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 "Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx" \
--custom-provider-id mlx-lm \
--custom-compatibility openai \
--custom-text-input \
--accept-risk \
--skip-healthRun OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"Gemma-4-31B-IT — UD-Q8_K_XL (mlx-node)
8-bit affine quantization of google/gemma-4-31b-it for Apple Silicon, using the Unsloth Dynamic quantization strategy via mlx-node.
| Original (BF16) | UD-Q8_K_XL (this model) | |
|---|---|---|
| Size | ~62 GB | 35 GB |
| Format | SafeTensors | SafeTensors |
| Precision | BF16 uniform | 8-bit affine + BF16 |
| FFN group size | — | 64 |
| Biases | — | yes |
All Variants
| Repo | Bit budget | Size | Decode (tok/s) |
|---|---|---|---|
| Brooooooklyn/Gemma-4-31B-IT-UD-Q2_K_XL-mlx | 2-bit base | 18 GB | 12.1 |
| Brooooooklyn/Gemma-4-31B-IT-UD-Q3_K_XL-mlx | 3-bit base | 21 GB | 10.4 |
| Brooooooklyn/Gemma-4-31B-IT-UD-Q4_K_XL-mlx | 4-bit base | 24 GB | 9.2 |
| Brooooooklyn/Gemma-4-31B-IT-UD-MXFP4_K_XL-mlx | mxfp4 | 24 GB | 10.6 |
| Brooooooklyn/Gemma-4-31B-IT-UD-NVFP4_K_XL-mlx | nvfp4 | 24 GB | 9.9 |
| Brooooooklyn/Gemma-4-31B-IT-UD-Q5_K_XL-mlx | 5-bit base | 28 GB | 6.8 |
| Brooooooklyn/Gemma-4-31B-IT-UD-Q6_K_XL-mlx | 6-bit base | 31 GB | 7.2 |
| Brooooooklyn/Gemma-4-31B-IT-UD-MXFP8_K_XL-mlx | mxfp8 | 34 GB | 7.8 |
| Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx (this model) | 8-bit base | 35 GB | 7.2 |
Benchmarked on Apple M3 Max 128GB via examples/lm.ts (best decode tok/s across turns 2–4, steady-state, capitals chat with reasoningEffort: 'low').
Performance
Steady-state decode: 7.2 tok/s on Apple M3 Max 128GB (best of turns 2–4, examples/lm.ts capitals chat with reasoningEffort: 'low'). Decode is memory-bandwidth bound on Apple Silicon — fewer bytes per token directly translates to higher throughput. Gemma-4-31B is fully dense (all 31B parameters active per token), so each decoded token must stream the entire quantized weight footprint from unified memory.
Per-Tensor Bit Assignments (N=8)
| Weight | Mode | Bits | Group | Rationale |
|---|---|---|---|---|
mlp.gate_proj |
8-bit affine | 8 | 64 | Dense MLP (top-level default) (top-level default) |
mlp.up_proj |
8-bit affine | 8 | 64 | Dense MLP (top-level default) (top-level default) |
self_attn.o_proj |
bf16 | — | — | NOT AWQ-correctable; kept full-precision |
Quantization Strategy
Built on Unsloth Dynamic 2.0 per-tensor KLD analysis. At --q-bits 8 the unsloth recipe assigns the base bits to MLP gate/up projections (the bulk of the parameter budget), base+1 to down_proj (slightly more sensitive), base+2 (snapped to a valid bit width) + AWQ pre-scaling to attention q/k/v projections, base+2 to embed_tokens / lm_head (tied weights), and keeps self_attn.o_proj as bf16 (AWQ-uncorrectable — its inputs come from the attention compute, not from a norm layer).
imatrix AWQ pre-scaling amplifies important weight channels and fuses inverse scales into preceding layer norms (zero inference overhead).
Architecture
| Parameter | Value |
|---|---|
| Total parameters | ~31B (fully dense — all parameters active per token) |
| Hidden size | 5,376 |
| Layers | 60 (sliding-window attention) |
| Attention heads | 32 (16 KV heads, GQA 2:1) |
| Head dimension | 256 |
| MLP intermediate size | 21,504 |
| Vocab size | 262,144 |
| Max context | 131,072 tokens |
| Vision | yes (Gemma4ForConditionalGeneration) |
Usage
import { loadSession } from '@mlx-node/lm';
const session = await loadSession('./Gemma-4-31B-IT-UD-Q8_K_XL-mlx');
for await (const event of session.sendStream('Explain the sliding-window attention design in Gemma-4.', {
config: { maxNewTokens: 2048, temperature: 0.6, reasoningEffort: 'low' },
})) {
if (!event.done) process.stdout.write(event.text);
}
How It Was Made
mlx convert \
-i gemma-4-31b-it \
-o Gemma-4-31B-IT-UD-Q8_K_XL-mlx \
-q --q-bits 8 --q-recipe unsloth \
--imatrix-path imatrix_unsloth.gguf
Acknowledgments
- Unsloth — Quantization strategy based on their per-layer KLD benchmarks and Dynamic 2.0 methodology
- Google DeepMind — For the Gemma-4 model family
- Apple MLX — For the Metal-accelerated ML framework
License
Gemma Terms of Use (inherited from base model).
- Downloads last month
- 187
8-bit
Start the MLX server
# Install MLX LM: uv tool install mlx-lm# Start a local OpenAI-compatible server: mlx_lm.server --model "Brooooooklyn/Gemma-4-31B-IT-UD-Q8_K_XL-mlx"