prism-ml/Ternary-Bonsai-4B-gguf

Model

Ternary-Bonsai-4B-gguf

34

3 commits

2 linked in READMEs

updated Jun 10, 2026

See the code
1.58-bit
bonsai
conversational
endpoints_compatible
eval-results
gguf
llama-cpp
on-device
prismml
q2_0
ternary
text-generation

README

Bonsai

Prism ML Website  |  White Paper  |  Demo & Examples  |  Discord

Ternary-Bonsai-4B-gguf

Ternary (1.58-bit) language model in GGUF Q2_0 format for llama.cpp

Pareto Frontier

Resources

  • White Paper
  • Demo repo — examples for serving, benchmarking, and integrating Bonsai
  • Discord — community support and updates
  • Kernels: Q2_0 is not yet in mainline llama.cpp. Use our fork at PrismML-Eng/llama.cpp (prism branch, default) which adds Q2_0 support for CPU (NEON/generic) and Metal. Upstream PR coming soon.

Model Overview

ItemSpecification
Base modelQwen3-4B
Parameters4.0B (~3.6B non-embedding)
ArchitectureGQA (32 query / 8 KV heads), SwiGLU MLP, RoPE, RMSNorm
Layers36 Transformer decoder blocks
Context length32,768 tokens
Vocab size151,936
Weight formatGGUF Q2_0 g128: {-1, 0, +1} with FP16 group-wise scaling
Packed Q2_0 size1,020 MiB (1.07 GB)
Ternary coverageEmbeddings, attention projections, MLP projections, LM head
LicenseApache 2.0

Quantization Format: GGUF Q2_0 (g128)

Each weight takes a value from {-1, 0, +1}, with one shared FP16 scale per group of 128 weights:

w_i = scale_g * t_i,    t_i in {-1, 0, +1}

Q2_0 encodes each weight as a 2-bit code q in {0, 1, 2, 3}, dequantized via w = (q - 1) * scale. One 128-element block is 34 bytes (2 bytes FP16 scale + 32 bytes of packed 2-bit codes) for an effective 2.125 bits/weight. The fourth code point (q = 3, reconstructing to +2 * scale) is reserved for future extensions; for ternary weights it is unused.

Memory

FormatSizeReductionRatio
FP168.04 GB--1.0x
GGUF Q2_0 g1281,020 MiB (1.07 GB)86.3%7.3x

Files in this repo

FileFormatSizeRecommended
Ternary-Bonsai-4B-F16.ggufFP168.04 GBbaseline / re-quantization source
Ternary-Bonsai-4B-Q2_0.ggufQ2_0 (g128)1,020 MBrecommended (lossless for ternary)

Quickstart

Build from the Prism fork

git clone https://github.com/PrismML-Eng/llama.cpp
cd llama.cpp
cmake -B build -DGGML_METAL=ON   # or -DGGML_CUDA=ON, -DGGML_VULKAN=ON
cmake --build build -j

llama.cpp CLI

./build/bin/llama-cli \
  -m Ternary-Bonsai-4B-Q2_0.gguf \
  -p "Explain quantum computing in simple terms." \
  -n 256

llama.cpp server

./build/bin/llama-server -m Ternary-Bonsai-4B-Q2_0.gguf -c 4096

Throughput (llama.cpp, Apple M4 Pro 48 GB)

BackendPP512 (tok/s)TG128 (tok/s)
Metal (GPU)826120
NEON CPU (10 t)22656

Flags: -ngl 99 -fa 1 for Metal; -ngl 0 -fa 1 -t 10 for CPU.

Fidelity (Q2_0 vs FP16 baseline)

Q2_0 is effectively lossless for ternary weights — the ternary values land exactly on three of the four 2-bit code points, so quantize/dequantize is bit-exact in the absence of FP16 scale rounding.

Benchmarks

Evaluated with EvalScope v1.4.2 + vLLM 0.15.1 on NVIDIA H100. Full benchmark suite:

ModelSizeAvgMMLU-RMuSRIFEvalGSM8KHE+BFCLv3
Ternary Bonsai 4B1.02 GB70.769.745.172.190.578.767.8
1-bit Bonsai 4B (prior)0.57 GB62.758.741.469.687.371.348.0
Qwen 3 4B8.04 GB77.179.857.480.092.174.478.9
Ministral3 3B6.86 GB73.277.556.573.191.469.571.3
Gemma 3 4B7.76 GB67.966.046.373.089.867.165.1
Llama 3.2 3B6.43 GB64.465.548.978.380.152.460.9

Intelligence Density

density = -ln(1 - score/100) / size_GB
ModelSizeIntelligence Density (1/GB)
Ternary Bonsai 4B1.02 GB1.202
1-bit Bonsai 4B (prior)0.57 GB1.744
Ministral3 3B6.86 GB0.192
Qwen 3 4B8.04 GB0.183
Llama 3.2 3B6.43 GB0.161
Gemma 3 4B7.76 GB0.146

Citation

@techreport{ternarybonsai,
    title   = {Ternary Bonsai: 1.58-bit Language Models at 8B, 4B, and 1.7B Scale},
    author  = {Prism ML},
    year    = {2026},
    month   = {April},
    url     = {https://prismml.com}
}

Contact

For questions, feedback, or collaboration inquiries: contact@prismml.com

Contributors

pashak

3 commits

prism-ml/Ternary-Bonsai-4B-gguf

Model

Ternary-Bonsai-4B-gguf

34

3 commits

2 linked in READMEs

updated Jun 10, 2026

See the code
1.58-bit
bonsai
conversational
endpoints_compatible
eval-results
gguf
llama-cpp
on-device
prismml
q2_0
ternary
text-generation

README

Bonsai

Prism ML Website  |  White Paper  |  Demo & Examples  |  Discord

Ternary-Bonsai-4B-gguf

Ternary (1.58-bit) language model in GGUF Q2_0 format for llama.cpp

Pareto Frontier

Resources

  • White Paper
  • Demo repo — examples for serving, benchmarking, and integrating Bonsai
  • Discord — community support and updates
  • Kernels: Q2_0 is not yet in mainline llama.cpp. Use our fork at PrismML-Eng/llama.cpp (prism branch, default) which adds Q2_0 support for CPU (NEON/generic) and Metal. Upstream PR coming soon.

Model Overview

ItemSpecification
Base modelQwen3-4B
Parameters4.0B (~3.6B non-embedding)
ArchitectureGQA (32 query / 8 KV heads), SwiGLU MLP, RoPE, RMSNorm
Layers36 Transformer decoder blocks
Context length32,768 tokens
Vocab size151,936
Weight formatGGUF Q2_0 g128: {-1, 0, +1} with FP16 group-wise scaling
Packed Q2_0 size1,020 MiB (1.07 GB)
Ternary coverageEmbeddings, attention projections, MLP projections, LM head
LicenseApache 2.0

Quantization Format: GGUF Q2_0 (g128)

Each weight takes a value from {-1, 0, +1}, with one shared FP16 scale per group of 128 weights:

w_i = scale_g * t_i,    t_i in {-1, 0, +1}

Q2_0 encodes each weight as a 2-bit code q in {0, 1, 2, 3}, dequantized via w = (q - 1) * scale. One 128-element block is 34 bytes (2 bytes FP16 scale + 32 bytes of packed 2-bit codes) for an effective 2.125 bits/weight. The fourth code point (q = 3, reconstructing to +2 * scale) is reserved for future extensions; for ternary weights it is unused.

Memory

FormatSizeReductionRatio
FP168.04 GB--1.0x
GGUF Q2_0 g1281,020 MiB (1.07 GB)86.3%7.3x

Files in this repo

FileFormatSizeRecommended
Ternary-Bonsai-4B-F16.ggufFP168.04 GBbaseline / re-quantization source
Ternary-Bonsai-4B-Q2_0.ggufQ2_0 (g128)1,020 MBrecommended (lossless for ternary)

Quickstart

Build from the Prism fork

git clone https://github.com/PrismML-Eng/llama.cpp
cd llama.cpp
cmake -B build -DGGML_METAL=ON   # or -DGGML_CUDA=ON, -DGGML_VULKAN=ON
cmake --build build -j

llama.cpp CLI

./build/bin/llama-cli \
  -m Ternary-Bonsai-4B-Q2_0.gguf \
  -p "Explain quantum computing in simple terms." \
  -n 256

llama.cpp server

./build/bin/llama-server -m Ternary-Bonsai-4B-Q2_0.gguf -c 4096

Throughput (llama.cpp, Apple M4 Pro 48 GB)

BackendPP512 (tok/s)TG128 (tok/s)
Metal (GPU)826120
NEON CPU (10 t)22656

Flags: -ngl 99 -fa 1 for Metal; -ngl 0 -fa 1 -t 10 for CPU.

Fidelity (Q2_0 vs FP16 baseline)

Q2_0 is effectively lossless for ternary weights — the ternary values land exactly on three of the four 2-bit code points, so quantize/dequantize is bit-exact in the absence of FP16 scale rounding.

Benchmarks

Evaluated with EvalScope v1.4.2 + vLLM 0.15.1 on NVIDIA H100. Full benchmark suite:

ModelSizeAvgMMLU-RMuSRIFEvalGSM8KHE+BFCLv3
Ternary Bonsai 4B1.02 GB70.769.745.172.190.578.767.8
1-bit Bonsai 4B (prior)0.57 GB62.758.741.469.687.371.348.0
Qwen 3 4B8.04 GB77.179.857.480.092.174.478.9
Ministral3 3B6.86 GB73.277.556.573.191.469.571.3
Gemma 3 4B7.76 GB67.966.046.373.089.867.165.1
Llama 3.2 3B6.43 GB64.465.548.978.380.152.460.9

Intelligence Density

density = -ln(1 - score/100) / size_GB
ModelSizeIntelligence Density (1/GB)
Ternary Bonsai 4B1.02 GB1.202
1-bit Bonsai 4B (prior)0.57 GB1.744
Ministral3 3B6.86 GB0.192
Qwen 3 4B8.04 GB0.183
Llama 3.2 3B6.43 GB0.161
Gemma 3 4B7.76 GB0.146

Citation

@techreport{ternarybonsai,
    title   = {Ternary Bonsai: 1.58-bit Language Models at 8B, 4B, and 1.7B Scale},
    author  = {Prism ML},
    year    = {2026},
    month   = {April},
    url     = {https://prismml.com}
}

Contact

For questions, feedback, or collaboration inquiries: contact@prismml.com

Contributors

pashak

3 commits