Instructions to use zk0hf/Bonsai-27B-mlx-1bit-vision4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use zk0hf/Bonsai-27B-mlx-1bit-vision4bit with MLX:
# Make sure mlx-vlm is installed # pip install --upgrade mlx-vlm from mlx_vlm import load, generate from mlx_vlm.prompt_utils import apply_chat_template from mlx_vlm.utils import load_config # Load the model model, processor = load("zk0hf/Bonsai-27B-mlx-1bit-vision4bit") config = load_config("zk0hf/Bonsai-27B-mlx-1bit-vision4bit") # Prepare input image = ["http://images.cocodataset.org/val2017/000000039769.jpg"] prompt = "Describe this image." # Apply chat template formatted_prompt = apply_chat_template( processor, config, prompt, num_images=1 ) # Generate output output = generate(model, processor, formatted_prompt, image) print(output) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Pi
How to use zk0hf/Bonsai-27B-mlx-1bit-vision4bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "zk0hf/Bonsai-27B-mlx-1bit-vision4bit"
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": "zk0hf/Bonsai-27B-mlx-1bit-vision4bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- OpenClaw new
How to use zk0hf/Bonsai-27B-mlx-1bit-vision4bit with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "zk0hf/Bonsai-27B-mlx-1bit-vision4bit"
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 "zk0hf/Bonsai-27B-mlx-1bit-vision4bit" \ --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"
- Hermes Agent
How to use zk0hf/Bonsai-27B-mlx-1bit-vision4bit 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 "zk0hf/Bonsai-27B-mlx-1bit-vision4bit"
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 zk0hf/Bonsai-27B-mlx-1bit-vision4bit
Run Hermes
hermes
Bonsai-27B-mlx-1bit, vision tower at 4-bit
A repack of prism-ml/Bonsai-27B-mlx-1bit
that quantizes the vision tower. 5.129 GB → 4.666 GB (−9.0%). The language model is
untouched, bit for bit.
All credit for the model belongs to Prism ML; this repo only changes how one component is stored.
Why
The published pack quantizes the language model to 1 bit but ships the vision tower dense F16, at 0.921 GB — nearly a fifth of the total, in a model whose whole premise is extreme compression. Quantizing those Linear layers to 4-bit is ordinary MLX work.
| language model, 498 modules (1-bit, untouched) | 3.362 GB |
| scales + biases | 0.840 GB |
| vision tower, 83 Linears → 4-bit/group-64 | 0.244 GB |
| vision tower, 27 Linears left at F16 | 0.216 GB |
| total | 4.666 GB |
Those 27 are a hard limit, not a choice: MLX requires in_features % group_size == 0 and
its Metal kernels exist only for group 32/64/128, but mlp.linear_fc2 has in_features
4304 = 16 × 269, which none of them divide.
Quality
On a Japanese receipt with known ground truth, output is byte-identical to the original pack — every field, every line item, and every amount (subtotal ¥1,188, tax ¥95, total ¥1,283). Measured peak GPU memory falls from 6.54 GB to 6.07 GB at 558k pixels.
This is one document, not a benchmark. Treat it as evidence that 4-bit is not obviously lossy for the vision path, not as a quality guarantee.
Requirements
Needs the PrismML fork of mlx-swift (or their
mlx fork) for 1-bit kernels. Upstream MLX rejects
bits=1 — "The supported bits are 2, 3, 4, 5, 6 and 8" — and compiles quantized Metal
kernels only for those widths, so on stock MLX this checkpoint is unloadable rather than
merely slow.
Note it does not fit a 6 GB iPhone. 4.666 GB of weights and a 6.07 GB peak need a 12 GB-class device.
Notes on what is not reducible
The 1-bit language model cannot be compressed further. Its codes measure exactly
1.0000 bits of entropy per weight, 100% of sampled 128-bit group patterns are
distinct, and lzma -9 --extreme and bzip2 -9 both return ≥100% of the original size
on 67 MB of real codes. Sub-1-bit would have to discard information rather than compress
it, and these weights are already at the 1-bit floor from Bonsai's QAT.
A further 0.420 GB is free: the pack stores biases that equal -scale/2 bitwise
across 210.1M of 210.1M groups, so they carry no information, and PrismML's affine_sym
kernels rederive them. Not applied here because mlx-swift-lm's loader currently rejects
a biasless QuantizedLinear (verify: [.all] demands the key even though the property is
already optional).
Reproducing
scripts/repack_bonsai.py in
ondevice-vlm-ios.
- Downloads last month
- -
1-bit