Ternary Bonsai 2 WebGPU Kernels
This Space runs the model in the browser on WebGPU. The 3D scene at the top of this page is adapted from it, without the model loading.
Bonsai 2 27B is a language model from Prism ML with ternary weights that are only 5.95 GB, ideal for running in systems with limited accelerator memory.
3D scene from the Ternary Bonsai 2 WebGPU Space.
Until support for these files is upstreamed to llama.cpp, this page helps you get started with Bonsai locally. It builds on Prism ML's Bonsai-demo, the original setup for these models.
Run this in a terminal on an Apple Silicon Mac or on Linux. On Windows, use WSL 2.
curl -fsSL https://huggingface.co/spaces/osolmaz/bonsai-installer/resolve/main/install.sh | sh
The script installs the bonsai command in ~/.local/bin and runs
it. The installer looks at the memory and the GPU of the machine, and then offers a few
settings with the memory each one needs. You can take one or choose each setting
yourself.
┌ Bonsai Installer 0.2.1 │ │ This machine: 16 GB memory · runs on Metal │ Bonsai fits comfortably in 9.6 GB here and should not use more than 14.4 GB. │ ┃ How should Bonsai run? ┃ Each choice shows the memory it needs, including the context cache. ┃ > Recommended PTQ1_0, 32K context, images on needs about 8.7 GB ┃ Long context PTQ1_0, 64K context, images on needs about 10.7 GB, tight ┃ Two sessions PTQ1_0, 16K context × 2 sessions, images on needs about 8.8 GB ┃ Custom choose each setting
bonsai computes for a Mac with 16 GB of memory.The first run then downloads 6 to 8 GB, checks every file, and starts the server. Once the model has loaded, the server answers at these addresses until you press Ctrl-C.
http://127.0.0.1:8080http://127.0.0.1:8080/v1, model bonsai-2-27bLater runs reuse the saved settings and start in a few seconds. The README lists every option, and these are the ones you are most likely to need.
| Command | Effect |
|---|---|
bonsai setup | Shows the choices again |
bonsai --ctx 16384 | Sets the context for each session, in tokens |
bonsai --yes | Starts without questions, for scripts |
bonsai start | Starts the server in the background and returns when it is ready |
bonsai check | Sends one test request to the running server |
bonsai stop | Stops a server started in another terminal |
Paste this into Claude Code, Codex, or another coding agent to have it install Bonsai and start the server for you.
Install Bonsai 2 27B with Bonsai Installer and start a local server here.
Attention agent: read this file before running anything:
https://huggingface.co/spaces/osolmaz/bonsai-installer/raw/main/docs/AGENT_ENTRYPOINT.md
Follow it exactly. Tell me the download size before it starts, ask me only
for missing choices such as a longer context or a second session, and report
the endpoint and the result of `bonsai check`.
The installer chooses the weight file and the context size from the memory it finds. To check those choices we loaded the model in six setups and measured how much memory the model process held after one short request. Five setups ran on a Mac and one ran in a Linux virtual machine with 8 GB of memory.
prism-b10709-9a9394a. The Mac rows come from an Apple M5 Pro with 64 GB,
and the Linux row from Ubuntu 24.04 in a Docker virtual machine with 7.7 GiB. The
dashed lines mark 8 and 16 GiB.
On an 8 GB machine the installer uses PTQ1_0 with an 8K context and leaves out the image encoder. In the Linux virtual machine that setup took 6.37 of its 7.7 GiB, which is enough on a dedicated box and tight next to a browser. With 16 GB the installer adds the image encoder and a 32K context, and that took 8.68 GiB on the Mac.
Speed depends far more on the hardware than on the weight file. The Mac decoded about 25 tokens per second on its GPU, while the CPU build in the Linux machine managed 1.7, which is fine for batch jobs and slow for chat. Prism ML reports 91 tokens per second on an RTX 4090 with CUDA. We have not tested CUDA yet.
The installer downloads two things and does the rest on your machine. The server listens
only on 127.0.0.1, so prompts and files never leave it.
The Prism ML llama.cpp release from GitHub, built for Metal, CUDA 12.8, or CPU
One weight file and the image encoder from Hugging Face at a pinned revision
Your machine
Settings that fit the memory of the machine, or your own
Each file must match its SHA-256 hash before it is used
llama-server starts in router mode with no model loaded
POST /models/load loads the model, and the installer waits for loaded
Chat in the browser, call the API, or start localpi
Router mode is what lets Pi and localpi load and unload models through the server. The installer writes a preset file for the chosen weight file, so every load uses the same context size and flags. When your Hugging Face cache already holds a file with the right hash, the installer hard-links it instead of downloading it again.
libgomp1, and the CUDA build needs the NVIDIA
driver with the CUDA 12 runtime. The installer names any missing library before it starts.
max_tokens: 16384. For shorter replies, send
reasoning_effort: "medium".
This Space runs the model in the browser on WebGPU. The 3D scene at the top of this page is adapted from it, without the model loading.
Prism ML built the model from Qwen3.8-27B with ternary weights at 1.72 bits per weight, and published it under Apache 2.0.
The llama.cpp fork that carries the ternary kernels. The installer pins release
prism-b10735-842b188, the one Bonsai-demo uses.
Hosts the model files and this page.
A build of the Pi coding agent for small local models, which finds the llama.cpp server on its own.