Instructions to use sahilchachra/nanbeige4.2-3b-mxfp4-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use sahilchachra/nanbeige4.2-3b-mxfp4-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("sahilchachra/nanbeige4.2-3b-mxfp4-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 sahilchachra/nanbeige4.2-3b-mxfp4-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 "sahilchachra/nanbeige4.2-3b-mxfp4-mlx"
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": "sahilchachra/nanbeige4.2-3b-mxfp4-mlx" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use sahilchachra/nanbeige4.2-3b-mxfp4-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 "sahilchachra/nanbeige4.2-3b-mxfp4-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 sahilchachra/nanbeige4.2-3b-mxfp4-mlx
Run Hermes
hermes
- OpenClaw new
How to use sahilchachra/nanbeige4.2-3b-mxfp4-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 "sahilchachra/nanbeige4.2-3b-mxfp4-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 "sahilchachra/nanbeige4.2-3b-mxfp4-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"
- MLX LM
How to use sahilchachra/nanbeige4.2-3b-mxfp4-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 "sahilchachra/nanbeige4.2-3b-mxfp4-mlx"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "sahilchachra/nanbeige4.2-3b-mxfp4-mlx" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sahilchachra/nanbeige4.2-3b-mxfp4-mlx", "messages": [ {"role": "user", "content": "Hello"} ] }'
nanbeige4.2-3b-mxfp4-mlx
MLX MX FP4 (micro-scaled 4-bit float) quantization of Nanbeige/Nanbeige4.2-3B, converted with mlx-lm.
Nanbeige4.2-3B is a compact agentic model built on Nanbeige4.2-3B-Base. Its Looped Transformer architecture reuses the same transformer layers across multiple passes to increase effective capacity without adding parameters. With only 3B non-embedding parameters, it outperforms larger models (Qwen3.5-9B, Gemma4-12B) on general-agent, code-agent, and reasoning benchmarks (per the base model's card: SWE-Bench Verified 63.6, GPQA-Diamond 87.4, HMMT-Feb-2026 82.8).
Architecture
| Base model | Nanbeige4.2-3B (Looped Transformer, nanbeige arch, 22 unique layers × 2 loops, ~4B total / 3B non-embedding params) |
| Quantization | MX FP4 (micro-scaled 4-bit float) |
| Bits per weight | 4.250 |
| Disk size | 2.1 GB (from ~7.8 GB bf16) |
| Format | MLX (safetensors) |
New architecture support — requires a PR branch of mlx-lm for now
Nanbeige4.2-3B uses a Looped Transformer architecture (model_type: "nanbeige"):
the same 22 decoder layers run twice (num_loops: 2), with a full RMSNorm applied
between and after each pass — a way to add effective depth without adding
parameters (3B non-embedding params, ~4B total). This architecture had no mlx-lm
support at all prior to this release. A minimal, from-scratch MLX port
(mlx_lm/models/nanbeige.py) was written for this conversion, implementing the
loop mechanism with per-loop KV cache isolation (each loop's attention only
attends to its own loop's keys/values) and covering the subset of the (very large)
upstream NanbeigeConfig that this checkpoint actually uses — the full reference
implementation also defines n-gram embeddings, hyper-connections, and
depth-attention, none of which are active here (num_loops=2 is the only
non-default architectural flag Nanbeige4.2-3B sets).
This is not yet in an official mlx-lm release. A PR adding this support is
open against ml-explore/mlx-lm. Until it
merges, install mlx-lm from the PR branch to load this model:
pip install git+https://github.com/SahilChachra/mlx-lm.git@add-nanbeige-support
Usage
from mlx_lm import load, generate
model, tokenizer = load("sahilchachra/nanbeige4.2-3b-mxfp4-mlx")
messages = [{"role": "user", "content": "Which number is bigger, 9.11 or 9.8?"}]
prompt = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
out = generate(model, tokenizer, prompt=prompt, max_tokens=2048, verbose=False)
print(out)
The chat template supports enable_thinking (default on — set False for
non-thinking mode) and preserve_thinking (whether prior turns' reasoning is
kept in multi-turn contexts; the base model card recommends False for general
chat/QA and True for multi-turn tool-use/agentic workflows). Per the base
model's recommendations: temperature 1.0 for agentic/tool-use tasks, 0.6 for
reasoning/chat tasks; eos_token_id is 166101.
CLI:
mlx_lm.generate --model sahilchachra/nanbeige4.2-3b-mxfp4-mlx \
--prompt "Which number is bigger, 9.11 or 9.8?" \
--max-tokens 2048
Smoke test
Verified via mlx_lm.generate through the model's chat template, on an Apple M4 Pro:
Prompt: "Explain the difference between TCP and UDP in two sentences."
Output (mxfp4): "...We need to provide an explanation that is concise, exactly two
sentences... TCP (Transmission Control Protocol) is a connection-oriented, reliable,
error-correcting protocol... UDP (User Datagram Protocol) is a connectionless,
unreliable, but lightweight protocol..."
Prompt: "Write a haiku about the ocean at night."
Output (mxfp8): "...haiku structure: three lines with syllable counts: 5, 7, 5...
Elements to include: night setting, ocean imagery (waves, stars reflected,
moonlight, darkness)..."
All four quantized variants preserve the base model's thinking-native behavior (private reasoning before the final answer) intact through quantization.
Decode speed
Measured with mlx_lm.generate on 5 GPQA-Diamond prompts (the same benchmark
the base model reports its 87.4 score on), Apple M4 Pro, max_tokens=400:
| Variant | Bits/weight | Disk size | Decode speed | vs FP16 |
|---|---|---|---|---|
| fp16 | 16 | 7.8 GB | 16.6 tok/s | baseline |
| mxfp4 | 4.250 | 2.1 GB | 50.0 tok/s | 3.0x |
| int4 | 4.500 | 2.2 GB | 49.2 tok/s | 3.0x |
| mxfp8 | 8.250 | 4.0 GB | 30.2 tok/s | 1.8x |
| int8 | 8.500 | 4.2 GB | 29.7 tok/s | 1.8x |
4-bit and 8-bit each cluster tightly regardless of MX-float vs affine-int encoding — pick based on quality tolerance (smaller/faster 4-bit vs higher-fidelity 8-bit) rather than the encoding scheme.
A note on accuracy: we attempted a full 25-sample GPQA-Diamond accuracy run across all variants, but this is a thinking-native model that reasons at length on hard graduate-level questions — most responses didn't reach a final answer within a 2048-token budget (across all variants), making the resulting accuracy numbers a measurement of response-length variance rather than model quality. We don't have a reliable accuracy comparison to publish here as a result; treat the decode-speed numbers above as the trustworthy signal from this exercise.
A note on correctness validation: this quantization required first porting
Nanbeige's Looped Transformer architecture to mlx-lm (see "New architecture
support" below). That port was validated against the official
modeling_nanbeige.py reference implementation (run via transformers,
float32) on held-out prompts: computed logits from both implementations for
the same inputs and compared next-token predictions and full logit
distributions. After aligning RoPE frequency initialization between the two
implementations, results matched closely — logit cosine similarity ≥0.9999
and identical next-token predictions on every test prompt.
Other MLX variants
optiq-5bpw was not produced for this release — it requires the mlx-optiq package,
which wasn't available in the conversion environment.
Credits
- Base model: Nanbeige/Nanbeige4.2-3B
- Quantization tooling: mlx-lm
- Downloads last month
- 141
4-bit