Ternary-Bonsai-27B-mlx-2bit
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 - **\~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](https://huggingface.co/prism-ml/Bonsai-27B-mlx-1bit) (\~3.9 GB), the phone-class operating point that fits an iPhone 17 Pro Max - **[Whitepaper](https://github.com/PrismML-Eng/Bonsai-demo/blob/main/bonsai-27b-whitepaper.pdf)** — full methodology, benchmarks, and measurement notes - **[Demo & examples](https://github.com/PrismML-Eng/Bonsai-demo)** — serving, benchmarking, and integrating Bonsai - **Low-bit kernels**: [MLX fork](https://github.com/PrismML-Eng/mlx) (Apple Silicon) · [mlx-swift fork](https://github.com/PrismML-Eng/mlx-swift) (iOS/macOS) · [llama.cpp fork](https://github.com/PrismML-Eng/llama.cpp) (CUDA) - **[Discord](https://discord.gg/prismml)** — join the community for support, discussion, and updates 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. 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. Two optional components ship alongside the language model (on-disk sizes from the GGUF packaging): 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. 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. 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): 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. These are the settings used for all reported benchmark results (thinking mode). You can use a simple system prompt such as: You are a helpful assistant Use the [Bonsai-demo repo](https://github.com/PrismML-Eng/Bonsai-demo) to run ternary Bonsai 27B on MacBook. CUDA inference uses the GGUF pack of the same weights: fused 2-bit GEMM kernels in our [llama.cpp fork](https://github.com/PrismML-Eng/llama.cpp) 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](https://huggingface.co/prism-ml/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](https://huggingface.co/prism-ml/Bonsai-27B-mlx-1bit) (\~3.9 GB), which fits an iPhone 17 Pro Max. `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. 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. 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. 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. 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. 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. Intelligence density captures the ratio of a model's capability to its deployed size: D = -log2(1 - score/100) / size_GB 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.
Open Ternary-Bonsai-27B-mlx-2bit in AIniverse
Compare versions, read real ratings, save to your stack.
Open in App