CPU-only inference server for Ternary Bonsai 8B, a 1.58-bit quantized language model (Qwen3-8B base) by PrismML. Serves an OpenAI-compatible API via llama-server from the PrismML fork of llama.cpp.
| Property | Value |
|---|---|
| Model | Ternary Bonsai 8B (Q2_0 GGUF) |
| Model size | 2.18 GB |
| Context window | up to 65,536 tokens |
| Avg benchmark score | 75.5 (2nd among 8B-class models) |
| License | Apache 2.0 |
| API port | 8080 |
Requires Docker with BuildKit enabled. The build compiles llama.cpp from source (~10 min) and downloads the model weights (~2.2 GB). Subsequent rebuilds use cached layers.
DOCKER_BUILDKIT=1 docker build -t bonsai-ternary-8b:local .
If a previous build was cancelled mid-download, clear the cache first to avoid a corrupt model file:
docker builder prune --filter type=exec.cachemount
DOCKER_BUILDKIT=1 docker build -t bonsai-ternary-8b:local .
docker run --rm -p 8080:8080 \
-e LLAMA_THREADS=8 \
-e LLAMA_THREADS_BATCH=16 \
-e LLAMA_CTX_SIZE=16384 \
bonsai-ternary-8b:local
| Variable | Default | Description |
|---|---|---|
LLAMA_THREADS | nproc | Threads for token generation (decode). Memory-bandwidth-bound — 8–12 physical cores is typically optimal; more can hurt. |
LLAMA_THREADS_BATCH | nproc | Threads for prompt processing (prefill). Compute-bound — use all physical cores available to the container. Also sets OPENBLAS_NUM_THREADS. |
LLAMA_BATCH_SIZE | 4096 | BLAS matrix size for prompt processing. Larger values improve prefill throughput at the cost of slightly more peak RAM. |
LLAMA_CTX_SIZE | 0 (auto-fit) | Context window in tokens. 0 lets llama.cpp auto-size the KV cache to fit available RAM. See the table below. |
LLAMA_CTX_SIZE | Approx. total RAM | Notes |
|---|---|---|
0 (auto) | fits available RAM | Recommended for most deployments |
8192 | ~2.5 GB | Minimal footprint |
16384 | ~3.5 GB | Good general-purpose default |
32768 | ~5.9 GB | Long documents / extended conversations |
65536 | ~10.5 GB | Maximum supported; requires ≥12 GB available |
The server exposes an OpenAI-compatible REST API on port 8080.
curl http://localhost:8080/health
curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "ternary-bonsai-8b",
"messages": [
{"role": "user", "content": "Explain ternary quantization in two sentences."}
]
}'
curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "ternary-bonsai-8b",
"stream": true,
"messages": [
{"role": "user", "content": "Write a haiku about compressed models."}
]
}'
These are set in the entrypoint and reflect PrismML's recommended values for the model.
| Parameter | Value | Description |
|---|---|---|
--temp | 0.5 | Temperature |
--top-p | 0.85 | Nucleus sampling |
--top-k | 20 | Top-K sampling |
--flash-attn | on | Flash attention (improves throughput) |
--reasoning | on | Qwen3 thinking mode (chain-of-thought before each answer) |
To override any parameter at runtime, append flags after the image name:
docker run --rm -p 8080:8080 bonsai-ternary-8b:local --temp 0.7 --top-p 0.95
Thinking mode is enabled by default. The model will produce chain-of-thought reasoning inside <think>...</think> tags before its final answer. This improves accuracy on complex tasks but adds latency.
To disable it:
docker run --rm -p 8080:8080 bonsai-ternary-8b:local \
--reasoning off \
--reasoning-budget 0 \
--reasoning-format none
Decode vs. prefill are different bottlenecks — tuning them separately is the biggest lever:
LLAMA_THREADS (decode) — set to physical core count, not logical. Hyperthreading does not help and can hurt due to cache contention. On a 16-core/32-thread host, try 8–12.LLAMA_THREADS_BATCH (prefill) — set to all physical cores available to the container. Prefill is a large matrix multiply that scales well across cores.LLAMA_BATCH_SIZE — default 4096 is a good balance. If you have spare RAM, try 8192 for heavier prompt workloads.Other tips:
docker run --cpuset-cpus="0-7" --cpuset-mems="0" ...--no-mmap if the model is being evicted from OS page cache under memory pressure — forces an upfront load into RAM.The Q2_0 ternary quantization type (GGML type 42) is not yet merged into upstream llama.cpp. This image builds from PrismML's prism branch. Once an upstream PR lands or PrismML publishes a tagged Ternary-specific release, the --branch prism line in the Dockerfile should be replaced with a pinned tag for reproducible builds.
Content type
Image
Digest
sha256:57a9921aa…
Size
1.7 GB
Last updated
3 months ago
docker pull nagaozen/bonsai-ternary-8b:local