Open source · Apache 2.0

BitNet models,
quarter the size.

Ternair loads Microsoft's BitNet b1.58 checkpoints — including the real 2B-4T — and serves them behind an OpenAI-compatible API. Pure Python, no C++ toolchain, one command to serve.

zsh
# install
pip install git+https://github.com/Simonc44/Ternair

# serve a real BitNet model
ternair serve --model microsoft/bitnet-b1.58-2B-4T --port 8080

# query it
curl localhost:8080/v1/chat/completions \
  -d '{"messages":[{"role":"user","content":"Hello!"}]}'
How storage works — 5 trits, 1 byte
−1
0
+1
+1
−1
→
0xA7

A base-3 codec packs five ternary weights into a single byte — 1.6 bits per value, 20% denser than standard 2-bit packing.

0.9958
Pearson correlation with BitNet
4×
Smaller than FP16
1.6
Bits per value
1
Command to serve
Workflow

Three commands. That's it.

No build step, no CUDA toolkit — convert once, then serve from anywhere.

01

Install

pip install git+https://github.com/Simonc44/Ternair

Pure Python. No C++ compiler, no CUDA toolkit — just pip.

02

Convert

ternair import-bitnet --source ./bitnet-2b4t --output ./ternair-2b4t

Bit-exact conversion of the trained weights into a 4× smaller file.

03

Serve

ternair serve --model ./ternair-2b4t --port 8080

An OpenAI-compatible API, ready for your existing client code.

Comparison

Ternair vs. bitnet.cpp

Same trained weights, same architecture — a lighter file and a server built in.

Capability
Ternair
bitnet.cpp
Loads trained BitNet checkpoints
Bit-exact
Yes
File size (2B-4T)
1.1 GB
~5 GB (BF16)
HTTP server
OpenAI-compatible, built in
None official
Install
pip install
C++ build required
Platforms
macOS · Linux · Windows
macOS · Linux
Packing density
1.6 bits / value
2 bits / value
Under the hood

Everything the server needs

A small, dependency-light stack — from quantization to production metrics.

Ternary weights

{−1, 0, +1} weights with per-row absmean quantization — the same recipe as BitNet b1.58.

Packed storage

Base-3 codec: five trits per byte, 1.6 bits per value — 20% smaller than standard 2-bit packing.

KV-cache inference

One prefill pass, one token per decode step, correct RoPE position offsets, streaming generation.

OpenAI-compatible API

/v1/completions, /chat/completions, /batch, /metrics — zero external services.

Multiple backends

PyTorch, NumPy, Triton GPU, and a native C++ CPU kernel — with automatic fallback per device.

Prometheus metrics

Requests, tokens per second, latency percentiles — ready for production monitoring.

Get started

Running in under a minute

Try it with a tiny demo model, or pull the real 2B-4T checkpoint straight from Hugging Face.

zsh
# install Ternair
pip install git+https://github.com/Simonc44/Ternair

# quick sanity check with a tiny model
ternair demo

# download and serve the real 2B-4T model
hf download microsoft/bitnet-b1.58-2B-4T --local-dir ./bitnet-2b4t
ternair import-bitnet --source ./bitnet-2b4t --output ./ternair-2b4t --storage packed
ternair serve --model ./ternair-2b4t --port 8080
Open source

Ready to run BitNet models?

Apache 2.0. Issues and pull requests are welcome on GitHub.