How to use from
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-MXFP4_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-MXFP4_K_XL-mlx"
        }
      ]
    }
  }
}
Run Pi
# Start Pi in your project directory:
pi
Quick Links

Gemma-4-31B-IT — UD-MXFP4_K_XL (mlx-node)

MXFP4 (OCP micro-scaling FP4) quantization of google/gemma-4-31b-it for Apple Silicon, using the Unsloth Dynamic quantization strategy via mlx-node.

Original (BF16) UD-MXFP4_K_XL (this model)
Size ~62 GB 24 GB
Format SafeTensors SafeTensors
Precision BF16 uniform MXFP4 (E8M0 scales) + mixed affine + BF16
FFN group size 32
Biases no (MLP); yes (affine layers)

What is MXFP4?

MXFP4 is the Open Compute Project (OCP) micro-scaling FP4 format. Each group of 32 elements shares a single 8-bit E8M0 scale (a power-of-two exponent), and elements themselves are stored as E2M1 FP4 values. Compared to 4-bit affine:

  • Half the scale storage: uint8 E8M0 vs. fp16/fp32 affine scales
  • No biases: zero-point implicit (FP4 covers ±range)
  • Hardware-friendly: scale is just an exponent shift, no FP multiply on the scale path

For typical LLM weight distributions, MXFP4 retains quality on par with 4-bit affine while shrinking the metadata footprint.

All Variants

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: 10.6 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=4)

Weight Mode Bits Group Rationale
embed_tokens 6-bit affine 6 64 Tied with lm_head (Gemma4 shares weights); affine-only loader
self_attn.q_proj 6-bit affine 6 64 AWQ-corrected via input_layernorm
self_attn.k_proj 6-bit affine 6 64 AWQ-corrected via input_layernorm
self_attn.v_proj 6-bit affine 6 64 AWQ-corrected via input_layernorm
mlp.gate_proj mxfp4 4 32 Dense MLP (top-level default)
mlp.up_proj mxfp4 4 32 Dense MLP (top-level default)
mlp.down_proj 5-bit affine 5 64 Dense MLP; "slightly more sensitive" (unsloth base+1)
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 4 the unsloth recipe assigns 4-bit to MLP gate/up projections (the bulk of the parameter budget), 5-bit affine to down_proj, 6-bit affine + AWQ pre-scaling to attention q/k/v, and keeps self_attn.o_proj as bf16. Then --q-mxfp orthogonally promotes the 4-bit affine decisions to MXFP4 (mode="mxfp4", bits=4, group_size=32) — except for keys whose dequantizers are affine-only (embed_tokens, lm_head, embed_vision.embedding_projection).

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-MXFP4_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-MXFP4_K_XL-mlx \
  -q --q-bits 4 --q-mxfp --q-recipe unsloth \
  --imatrix-path imatrix_unsloth.gguf

Acknowledgments

License

Gemma Terms of Use (inherited from base model).

Downloads last month
10
Safetensors
Model size
9B params
Tensor type
BF16
·
U32
·
U8
·
MLX
Hardware compatibility
Log In to add your hardware

4-bit

Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including Brooooooklyn/Gemma-4-31B-IT-UD-MXFP4_K_XL-mlx