Instructions to use thoddnn/Ternary-Bonsai-27B-mlx-2bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use thoddnn/Ternary-Bonsai-27B-mlx-2bit 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("thoddnn/Ternary-Bonsai-27B-mlx-2bit") 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 thoddnn/Ternary-Bonsai-27B-mlx-2bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "thoddnn/Ternary-Bonsai-27B-mlx-2bit"
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": "thoddnn/Ternary-Bonsai-27B-mlx-2bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use thoddnn/Ternary-Bonsai-27B-mlx-2bit 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 "thoddnn/Ternary-Bonsai-27B-mlx-2bit"
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 thoddnn/Ternary-Bonsai-27B-mlx-2bit
Run Hermes
hermes
- OpenClaw new
How to use thoddnn/Ternary-Bonsai-27B-mlx-2bit with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "thoddnn/Ternary-Bonsai-27B-mlx-2bit"
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 "thoddnn/Ternary-Bonsai-27B-mlx-2bit" \ --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 thoddnn/Ternary-Bonsai-27B-mlx-2bit with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "thoddnn/Ternary-Bonsai-27B-mlx-2bit"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "thoddnn/Ternary-Bonsai-27B-mlx-2bit" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thoddnn/Ternary-Bonsai-27B-mlx-2bit", "messages": [ {"role": "user", "content": "Hello"} ] }'
Prism ML Website | Whitepaper | Demo & Examples | Discord
Ternary Bonsai 27B
Full 27B-class reasoning in ternary transformer weights — on everyday laptops
~9.4x smaller than FP16 (ideal) | 95% of FP16 intelligence retained | ~26 tok/s on an Apple M5 Pro laptop
Highlights
- ~7.2 GB deployed footprint (down from ~54 GB FP16) — full 27B-class reasoning on a standard laptop or a single GPU
- 95% of FP16 intelligence retained: 80.49 average across 15 thinking-mode benchmarks — a higher score than the conventional IQ2_XXS build (72.73) at less than two-thirds of its footprint
- Retains thinking, reasoning, and agentic behavior deep in the sub-4-bit regime, where conventional low-bit representations collapse: math within two points of full precision (93.40), coding at 85.96, agentic tool use at 74.01
- End-to-end ternary language weights across embeddings, attention projections, MLP projections, and LM head, at a true 1.71 bits per weight — no high-precision escape hatches behind a low-bit label; the vision tower ships in compact 4-bit HQQ
- 262K-token context on-device, kept practical by the Qwen3.6-27B hybrid-attention backbone (~75% linear attention) and 4-bit KV-cache quantization
- Custom 2-bit hybrid-attention kernels on Apple MLX (Python, Swift) and CUDA — packed weights are consumed directly, never expanded back to FP16
- Ships with a DSpark speculative-decoding drafter layer trained against the Bonsai 27B target — a lossless 1.34x decode speedup on the CUDA serving path
- 1-bit companion: also available as 1-bit Bonsai 27B (~3.9 GB), the phone-class operating point that fits an iPhone 17 Pro Max
Resources
- Whitepaper — full methodology, benchmarks, and measurement notes
- Demo & examples — serving, benchmarking, and integrating Bonsai
- Low-bit kernels: MLX fork (Apple Silicon) · mlx-swift fork (iOS/macOS) · llama.cpp fork (CUDA)
- Discord — join the community for support, discussion, and updates
Model Overview
| Item | Specification |
|---|---|
| Base model | Derived from Qwen3.6-27B, a 27B hybrid-attention causal language model (architecture unchanged) |
| Parameters | ~27.3B ternary language weights (~24.8B backbone across 64 blocks + ~2.5B embedding/LM head) + ~0.46B vision tower (27 blocks) |
| Architecture | Hybrid attention (~75% linear / ~25% full attention), SwiGLU MLP, RoPE, RMSNorm |
| Context length | 262K tokens (full-context capable on-device, enabled by the predominantly linear-attention backbone) |
| KV cache | Near-lossless 4-bit KV quantization; the hybrid backbone grows a full-attention cache on only 16 of 64 layers (~4.3 GB at the full 262K window) |
| Weight format | Ternary g128: {−1, 0, +1} weights with FP16 group-wise scaling |
| Low-bit coverage | Embeddings, attention projections, MLP projections, LM head |
| Vision tower | HQQ 4-bit; optional ~0.63 GB mmproj pack, loaded only for image input |
| Deployed size | ~7.2 GB (5.9 GB ideal at 1.71 bits/weight; see below) |
| Acceleration | DSpark speculative-decoding drafter layer provided |
| Backends | Apple MLX (Python, Swift) and CUDA |
| License | Apache 2.0 |
Weight Representation: Ternary g128
Each weight takes a value from {−1, 0, +1}, with one shared FP16 scale factor for every group of 128 weights. A ternary value carries log₂3 ≈ 1.585 bits of information, so the effective storage cost is ~1.71 bits/weight (ternary code + 16-bit scale amortized over 128 weights) — an idealized ~9.4x reduction vs FP16.
Relative to the binary format, the extra zero state gives a more expressive weight alphabet and recovers more of the full-precision model's behavior, which makes ternary the quality-oriented operating point of the Bonsai 27B family.
Memory Requirement
| Format | True bits/weight | Ideal size | Deployed size | Reduction (ideal) |
|---|---|---|---|---|
| FP16 (baseline) | 16.0 | ~54 GB | — | 1.0x |
| Ternary g128 | 1.71 | 5.9 GB | ~7.2 GB | ~9.4x |
Today's kernels store each ternary value in a 2-bit slot (2.125 bits/weight deployed), so the deployed footprint sits above the representation's information-theoretic minimum until native ternary kernels close the gap. The deployed figure describes the language model alone — the only component that must stay resident for text inference; a negligible tail of normalization and scale parameters remains in higher precision.
Unlike conventional low-bit builds — whose advertised labels understate their true average bit-width (a widely-used "2-bit" build of Qwen3.6-27B is really 2.8 bits/weight at 9.4 GB) — the Bonsai representation carries a bit-width that matches its name.
Shipped Components
Two optional components ship alongside the language model (on-disk sizes from the GGUF packaging):
| Component | Pack | Size | Residency |
|---|---|---|---|
| Language model | 2-bit g128 slots | 7.17 GB | resident |
| DSpark drafter | Q4_1 (default) | 1.95 GB | optional — speculative decoding |
| DSpark drafter | bf16 (reference) | 7.29 GB | optional |
| Vision tower | mmproj HQQ 4-bit (Q8_0 container) | 0.63 GB | optional — multimodal input only |
| Vision tower | mmproj BF16 (reference) | 0.93 GB | optional |
The vision tower is usually offloaded: it sits outside the accelerator's resident budget and is loaded only when an image actually arrives, so text-only serving never pays for it. A group-64 ternary pack (7.59 GB) is also published, matching the 64-value-group Q2_0 packing in llama.cpp — the same native g128 representation with each scale repeated per 64-value block.
MLX Packaging
The published MLX pack measures 8.49 GB on disk (safetensors, vision tower bundled in the same file). MLX's grouped low-bit format stores both a scale and a bias per group; Bonsai's scale-only weights are packed by setting s_mlx = 2·s_g and bias = −s_g, which reproduces ±s_g exactly — the bias carries no new information — but stores two FP16 values per group where the native format stores one. The effective rate is therefore 2.25 bits/weight versus the deployed 2.125. This is a current MLX limitation; once MLX supports scale-only group formats, the MLX pack matches the native rate.
Peak Memory at Context
What a device must actually accommodate is peak memory — weights plus KV cache plus activations and runtime buffers (~1.3 GB across backends). Measured, language model only, no KV-cache compression (sizes in decimal GB; the Q4_K_XL row is derived from its weight footprint plus the same measured cache-and-overhead build-up, all other rows directly measured):
| Build | Weights | 4K ctx | 10K ctx | 100K ctx |
|---|---|---|---|---|
| Ternary Bonsai (llama.cpp Q2_0) | 7.15 | 8.4 | 8.7 | 14.7 |
| Ternary Bonsai (MLX 2-bit) | 7.57 | 9.2 | 9.6 | 15.5 |
| Qwen3.6-27B "4-bit" (Q4_K_XL) | 17.6 | 19.2 | 19.6 | 25.6 |
| 27B 16-bit (GGUF bf16) | 51.25 | 52.6 | 53.3 | 59.3 |
The ternary build holds a 100K-token context at 14.7–15.5 GB without any KV-cache compression — a budget that fits mainstream laptops outright; the conventional Q4_K_XL build needs ~25.6 GB before the first long document is loaded. These peaks are the conservative case, with the cache left at FP16. Enabling the 4-bit KV cache shrinks the context-dependent term ~4x: the ternary build's 100K peak drops to ~10.1 GB, and the full 262K window fits in ~12.8 GB peak.
Best Practices
Generation Parameters
| Parameter | Suggested |
|---|---|
| Temperature | 0.7 |
| Top-p | 0.95 |
| Top-k | 20 |
These are the settings used for all reported benchmark results (thinking mode).
System Prompt
You can use a simple system prompt such as:
You are a helpful assistant
Quickstart
MLX (Apple Silicon — Mac)
Use the Bonsai-demo repo to run ternary Bonsai 27B on MacBook.
CUDA (NVIDIA GPUs)
CUDA inference uses the GGUF pack of the same weights: fused 2-bit GEMM kernels in our llama.cpp fork unpack the ternary codes and apply the group-wise scales inside the matrix multiply — the model is never expanded into a dense FP16 tensor in memory. See Ternary-Bonsai-27B-gguf for the full CUDA, Metal, and server quickstarts.
Deploying to a phone? The ternary build (~7.2 GB) exceeds the ~6 GB per-app iOS memory budget and is laptop/GPU-only. Use the 1-bit companion (~3.9 GB), which fits an iPhone 17 Pro Max.
Cross-Platform Throughput
tg128 is token-generation throughput over 128 generated tokens (the memory-bandwidth-bound, interactive phase); pp512 is prompt-processing throughput over 512 input tokens (the compute-bound phase). Both in tokens/s. Rows are measured with llama.cpp (Metal/CUDA, custom low-bit kernels) on the GGUF pack of the same weights.
| Platform | Footprint | TG128 (tok/s) | PP512 (tok/s) |
|---|---|---|---|
| Laptop (Apple M5 Max, Metal) | 7.2 GB | 44.0 | 830 |
| Laptop (Apple M5 Pro, Metal) | 7.2 GB | 26.2 | 393 |
| Laptop (Apple M4 Pro, Metal) | 7.2 GB | 18.0 | 125 |
| Single GPU (H100, CUDA) | 7.2 GB | 98.0 | 2596 |
On the laptop, the FP16 baseline (~54 GB) and even conventional "4-bit" builds (17.6 GB) do not fit at all — the meaningful statement is not a speedup ratio but that a 27B model runs interactively on an everyday laptop. The measured decode streams ~186 GB/s of weights on the M5 Pro, confirming the memory-bandwidth-dominated profile that the low-bit representation is built to exploit. The H100 row is the exception that proves the rule: at batch size 1 a datacenter GPU is limited by kernel-launch and synchronization latency rather than weight bandwidth, so the ternary and binary variants converge there (98 vs 104.8 tok/s) despite their ~1.9x difference in bytes per step.
Speculative Decoding: DSpark
Ternary Bonsai 27B ships with a DSpark drafter layer trained against the low-bit target — a semi-autoregressive drafter with confidence-scheduled verification. Speculative decoding is lossless: verification preserves the target distribution exactly, so accepted tokens are indistinguishable from ordinary generation.
The drafter is a compact six-layer block-parallel transformer conditioned on hidden states tapped from five evenly spaced layers of the target; its drafter-unique weights add roughly 0.5 GB at serving precision (embeddings and output head are shared with the resident target). It follows the DSpark recipe with a diffusion-flavored block-denoising objective, survival-probability-weighted distillation, per-source-normalized hidden-state taps, and a draft block size chosen from a measured verify-cost model of the serving stack. The drafter ships 4-bit quantized — the ~1.95 GB Q4_1 pack is the default; it drafts faster than the bf16 reference at essentially unchanged draft quality, and because verification preserves the target distribution exactly, drafter precision affects only speed, never output quality.
On the CUDA serving path the drafter is a measured net win — an accepted length of τ ≈ 3.7 at draft depth k = 4 turns into a 1.34x end-to-end decode speedup on H100 (98 → 131.8 tok/s). On Apple Silicon the batch-1 verification pass does not yet amortize, so the drafter layer is not enabled by default on-device.
Benchmarks
Evaluated with EvalScope + vLLM on NVIDIA H100 under identical infrastructure, decoding, and scoring, in thinking mode — where the model's full reasoning is exercised and the sub-4-bit collapse of conventional methods is most visible. 15 benchmarks across six skill categories. For cross-family context the table also includes Gemma-4-31B, a model of the same capability tier, with its conventional low-bit builds — the collapse below 4 bits is a property of the methods, not of one base model. Bit-widths are true averages; "vs FP16" is relative to the Qwen3.6-27B FP16 reference.
| Variant | True bpw | Footprint | Thinking avg | vs FP16 |
|---|---|---|---|---|
| Qwen3.6-27B FP16 | 16.0 | 54 GB | 85.07 | 100% |
| Qwen3.6-27B Q4_K_XL ("4-bit") | 5.2 | 17.6 GB | 84.99 | 99.9% |
| Qwen3.6-27B IQ2_XXS ("2-bit") | 2.8 | 9.4 GB | 72.73 | 85.5% |
| Gemma-4-31B FP16 | 16.0 | 61.5 GB | 84.58 | 99.4% |
| Gemma-4-31B QAT ("4-bit") | 6.0 | 23.3 GB | 83.41 | 98.0% |
| Gemma-4-31B Q2_K_XL ("2-bit") | 3.0 | 11.8 GB | 73.31 | 86.2% |
| Ternary Bonsai 27B | 1.71 | 5.9 GB | 80.49 | 94.6% |
| 1-bit Bonsai 27B | 1.125 | 3.9 GB | 76.11 | 89.5% |
At 5.9 GB, Ternary Bonsai 27B outscores both sub-4-bit conventional builds by more than seven points at one-half to two-thirds of their size.
The aggregate gap also understates how the conventional builds fail: their degradation is selective, concentrated on the benchmarks that demand sustained chains of reasoning. IQ2_XXS falls to 57.5 on AIME26 and 56.4 on LiveCodeBench while still scoring 88.93 on MMLU-Redux — which is why casual testing misses the collapse. Ternary Bonsai holds exactly these benchmarks, keeping AIME at 87.5–90.8 and LiveCodeBench at 82.8.
By Skill Category
| Category | Benchmarks | FP16 | Ternary 27B |
|---|---|---|---|
| Knowledge & reasoning | MMLU-Redux, MuSR | 83.15 | 76.96 |
| Math | GSM8K, MATH-500, AIME25, AIME26 | 95.33 | 93.40 |
| Coding | HumanEval+, MBPP+, LiveCodeBench | 88.74 | 85.96 |
| Instruction following | IFEval, IFBench | 78.47 | 71.77 |
| Agentic / tool calling | BFCL v3, τ²-Bench | 80.00 | 74.01 |
| Vision | MMMU-Pro, OCR Bench v2 | 72.61 | 65.19 |
| Overall (15) | 85.07 | 80.49 |
The reasoning backbone comes through intact: math stays within two points of full precision (93.40), coding at 85.96, and the ternary model spends its extra footprint to hold the most demanding categories — agentic tool use at 74.01 and vision at 65.19 — the behaviors that conventional sub-4-bit representations lose first.
Full Per-Benchmark Results
Expand full per-benchmark results (thinking mode)
| Benchmark | FP16 | Ternary 27B |
|---|---|---|
| MMLU-Redux | 93.42 | 88.05 |
| MuSR | 72.88 | 65.87 |
| GSM8K | 95.30 | 96.06 |
| MATH-500 | 99.40 | 99.20 |
| AIME25 | 93.29 | 90.84 |
| AIME26 | 93.33 | 87.50 |
| HumanEval+ | 95.12 | 93.90 |
| MBPP+ | 83.33 | 81.22 |
| LiveCodeBench | 87.77 | 82.75 |
| IFEval | 88.91 | 85.03 |
| IFBench (prompt-loose) | 68.03 | 58.50 |
| BFCL v3 | 77.10 | 74.41 |
| τ²-Bench | 82.90 | 73.61 |
| MMMU-Pro | 79.94 | 68.96 |
| OCR Bench v2 | 65.28 | 61.42 |
| Average (15) | 85.07 | 80.49 |
Intelligence Density
Intelligence density captures the ratio of a model's capability to its deployed size:
D = -log2(1 - score/100) / size_GB
| Variant | Size (GB) | Benchmark avg | Intelligence Density (1/GB) |
|---|---|---|---|
| 1-bit Bonsai 27B | 3.9 | 76.11 | 0.530 |
| Ternary Bonsai 27B | 5.9 | 80.49 | 0.400 |
| Qwen3.6-27B IQ2_XXS | 9.4 | 72.73 | 0.199 |
| Gemma-4-31B Q2_K_XL | 11.8 | 73.31 | 0.162 |
| Qwen3.6-27B Q4_K_XL | 17.6 | 84.99 | 0.155 |
| Gemma-4-31B QAT | 23.3 | 83.41 | 0.111 |
| Qwen3.6-27B FP16 | 54 | 85.07 | 0.051 |
| Gemma-4-31B FP16 | 61.5 | 84.58 | 0.044 |
Ternary Bonsai 27B delivers 2x the density of the densest conventional build (IQ2_XXS at 0.199) and nearly 8x FP16 — no conventional build of Qwen3.6-27B or Gemma-4-31B exceeds 0.2. Each stored gigabyte is translated into far more usable intelligence.
Use Cases
- Laptop-local 27B agents: full 27B reasoning and tool use on a standard laptop at ~26 tok/s, with the 262K context available for long-document analysis, full-repository code work, and other tasks that depend on holding a large working set in context
- Privacy-sensitive and offline settings: on-device execution keeps prompts and data on the device by construction, and works with intermittent or no connectivity
- Single-GPU and commodity-GPU serving: 27B-class quality from a single consumer or entry-level datacenter GPU, with headroom for larger batches, longer contexts, or co-resident models — combined with the KV-cache quantization, high-throughput serving and long-context document analysis become practical on a single 24 GB GPU
- Quality-first low-bit deployment: when the deployment target has laptop-class memory or better, ternary is the operating point that retains the most of the full-precision model's behavior
Limitations
- The quality–footprint trade-off: the ternary model retains 94.6% of the full-precision average, and the gap is modest and predictable — the reasoning core (math, coding) stays within a few points of baseline, with the difference concentrated in the most demanding categories; deployments that need the last few points of accuracy can still reach for the full-precision model where its footprint is not a constraint
- Does not fit a phone: at ~7.2 GB the ternary build exceeds the ~6 GB per-app iOS memory budget; use the 1-bit companion for phone deployment
- Served in 2-bit slots today: the deployed footprint (~7.2 GB) sits above the representation's ~5.9 GB native target; native ternary kernels are an active engineering target and would return the remaining bandwidth and footprint advantage directly as latency and energy improvements
- Agentic coding (long-horizon, multi-file, run-test-and-repair workflows) is not yet a strong target of this release; a Bonsai 27B variant tuned for agentic coding is next on the roadmap
- KV compression headroom: this release standardizes on a 4-bit KV cache; Bonsai's tolerance to KV-cache error grows with context length, and early results show the key cache can be pushed toward the sub-2-bit regime — a path to still longer contexts within a fixed device-memory budget
Citation
If you use Ternary Bonsai 27B, please cite:
@techreport{bonsai27b,
title = {Bonsai 27B: Full 27B-Class Reasoning in Binary and Ternary
Transformer Weights --- on Laptops and Phones},
author = {Prism ML},
year = {2026},
month = {July},
url = {https://prismml.com}
}
Contact
For questions, feedback, or collaboration inquiries: contact@prismml.com
- Downloads last month
- -
2-bit
Model tree for thoddnn/Ternary-Bonsai-27B-mlx-2bit
Base model
Qwen/Qwen3.6-27B