Instructions to use EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX 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("EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX") 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 EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX"
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": "EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX" } ] } } }Run Pi
# Start Pi in your project directory: pi
- MLX LM
How to use EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8080/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX", "messages": [ {"role": "user", "content": "Hello"} ] }' - Hermes Agent
How to use EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX 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 "EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX"
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 EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX"
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 "EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX" \ --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"
Ternary Bonsai 2 4B โ MTPLX pack (EngineeringWithJay)
Our own repackaging of Prism ML's official
Ternary-Bonsai-2-4B-mlx-2bit
into the MTPLX pack contract, with Prism's own 4B MTP head attached, so the 4B
can be served with native MTP speculative decoding on Apple silicon.
No weight bytes were changed. The trunk is byte-identical to the upstream
pack (model.safetensors sha256 432f48d0edcb8da2e6a4e0c960785883โฆ, 1,871,365,704 bytes).
Measured on this machine
One M5 Air (16 GB unified memory), MTPLX 2.12.3, one model resident, thinking disabled:
| measurement | result |
|---|---|
| mean decode over 5 prompts | 43.9 t/s |
| fastest prompt | 64.8 t/s |
| decode with an image in the prompt | 35.9 t/s |
| vision | read a real UI viewport screenshot's values correctly (Temperature 0.60, Top P 0.95, Top K 20, MTP on, Draft depth 1, Max tokens 16.4k) |
MTP and the tied output projection
Prism ships the 4B with tie_word_embeddings: true and no lm_head tensors: the
output projection is the embedding. MTPLX's draft-head builder
(draft_lm_head._make_embedding_as_linear_head) only accepted nn.Embedding and
nn.QuantizedEmbedding, so it raised TypeError on MTPLX's own
HadamardQuantizedEmbedding โ and it is hit even with --no-mtp, so a tied pack
could not be served at all.
The 4B therefore needs a one-branch patch to MTPLX. It is not a change to this pack:
# mtplx/draft_lm_head.py, in _make_embedding_as_linear_head, before the final raise
elif hasattr(module, "as_linear"):
# MTPLX's own HadamardQuantizedEmbedding: a tied Bonsai-2 output
# projection. It already exposes as_linear(), which rotates the input
# forward and reuses the stored packed matrix, so the draft head is
# the target's own tied head, exactly.
original = _embedding_report(module)
return _EmbeddingAsLinear(module), {
"source": "tied_embedding",
"original": original,
"draft_only": original,
"reused_existing_quantization": True,
"elapsed_s": time.perf_counter() - started,
}
With that branch the 4B loads with mtp_layers: 1 and tier: verified. The
untied 9B and 27B packs need no patch. The same fix is what makes any tied
Bonsai-2 size (the 2B) servable at all.
How to serve it
Requires MTPLX 2.12+ with the branch above (or a future release that includes it).
Plain mlx-lm cannot load this pack: its model_type is prism_hadamard_qwen35,
which carries the Hadamard/sign-flip integration the format needs.
mtplx serve \
--model /path/to/Ternary-Bonsai-2-4B-MTPLX \
--port 8003 --cache-dir /path/to/models \
--reasoning off --allow-swap \
--mtp --generation-mode mtp \
--mtp-batch-numerics throughput --draft-core device \
--scheduler-mode hyper --batching-preset latency \
--paged-kv-quantization q4 \
--ssd-session-cache on --ssd-session-cache-dir /path/to/ssd-bank \
--ssd-session-cache-max-size 30G
On a 16 GB Mac also set:
export MTPLX_MEMORY_LIMIT_BYTES=14495552000
export MTPLX_SESSION_BANK_MAX_BYTES=3221225472
Do not lower the session bank budget to 64 MB. The bank cannot hold one conversation entry below roughly 1 GB, so the prefix is never reused and every turn re-prefills the whole conversation (14.1 s per turn instead of 0.6 s on the same 16K-token workload).
Verify before serving:
mtplx inspect --model /path/to/Ternary-Bonsai-2-4B-MTPLX
# tier: verified | can_run: true | runtime_compatibility: native | mtp_layers: 1
What we changed relative to the upstream pack
Packaging only, all four verified by mtplx inspect:
mtp/model.safetensorsmoved tomtp.safetensorsat the pack root.- Its 31 tensor keys were given the
mtp.prefix (fc.weightโmtp.fc.weight); Prism ships them unprefixed for mlx-vlm, MTPLX expects the prefix. Payloads unchanged. config.jsongainedmtplx_mtp_contract,mtplx_mtp_quantization(bits 4, group size 64, mode affine, policy all, prequantized true),mlx_lm_extra_tensors {mtp_file},model_family, andtext_config.mtp_num_hidden_layers = 1.mtplx_runtime.jsonwas written with the keys MTPLX requires (mtplx_version,arch_id,mtp_depth_max,recommended_profile,exactness_baseline,verified_on).
The tensor namespace was already language_model.* + vision_tower.* (matching
MTPLX's contract) and components.mtp was set to true to match the sidecar we ship.
Architecture
| property | value |
|---|---|
| family | Ternary Bonsai 2 4B (Prism ML), prism_hadamard_qwen35 |
| trunk quantization | 2-bit ternary, affine, group size 128 |
| hidden size | 2560 |
| layers | 32 (8 full-attention, 24 linear-attention / Gated DeltaNet) |
| attention heads | 16 attention / 4 key-value, head_dim 256 |
| intermediate size | 9216 |
| output projection | tied to the embedding (tie_word_embeddings: true) |
| MTP head | qwen3_5_mtp, 4-bit group-64 affine, prequantized, depth 1 |
| context | 262,144 native |
| KV per token | 32 KB bf16 (8 full-attention layers x 2 x 4 heads x 256 dim x 2 bytes) |
| vision tower | 24 blocks, hidden 1024 |
Limitations
- This is the base model, not a Swift finetune.
- The MTP head is Prism's own, trained against the Ternary Bonsai 2 trunk. We measured decode rates on this machine but did not publish a separate acceptance-rate table.
- The MTP draft-head patch above is required on MTPLX 2.12.3.
- We verified text-image reading, not video or multi-image behaviour.
License and attribution
Apache-2.0. The weights are Prism ML's, redistributed unchanged; our repackaging
(README, mtplx_runtime.json, config.json additions, packaging) is also Apache-2.0.
See NOTICE.txt for the full attribution chain and LICENSE for the licence text.
Citation
@misc{engineeringwithjay_ternary_bonsai2_4b_mtplx,
title = {Ternary Bonsai 2 4B -- MTPLX pack},
author = {EngineeringWithJay},
year = {2026},
note = {MTPLX-native repackaging of prism-ml/Ternary-Bonsai-2-4B-mlx-2bit; weight bytes unchanged},
url = {https://huggingface.co/EngineeringWithJay/Ternary-Bonsai-2-4B-MTPLX}
}
- Downloads last month
- 233
2-bit