Rust inference engine for ternary LLMs
Run BitNet LLMs on CPU, without GPU — by exploiting the fact that multiplying by a ternary weight is just a sign change and an addition.
Why
LLM inference is dominated by weight × activation multiplication, and the industry standard is to run it on GPU.
BitNet b1.58 changes the game: by quantizing each weight to a ternary value {−1, 0, +1}, floating-point multiplication disappears — each product becomes "add the activation, subtract it, or skip it."
This is exactly what the integer SIMD units in processors do best. A vector register handles dozens of ternary products per cycle. Result: a well-utilized CPU becomes a real inference target for these models — without the memory bandwidth or cost of a GPU.
Features
Runtime dispatch kernels
AVX-512 (VNNI), AVX2, ARM NEON, and a portable fallback. The same binary automatically selects the best kernel for the host CPU. No compile flags, no recompilation.
InfrastructureBit-exact numerical parity
Each SIMD kernel is verified identical, bit for bit, against a portable reference implementation (the 'oracle'). Correctness is not a promise — it's a test.
QualityFull forward pass
RMSNorm, causal multi-head attention with RoPE and GQA, SwiGLU FFN, embeddings, and high-precision output head.
ArchitectureKV cache & generation
FP16 cache (default), int8 or F32. Greedy, temperature, top-k, top-p, min-p sampling. Streaming API.
RuntimeTokenizer
HuggingFace tokenizer integration (tokenizer.json). Compatible with existing models without additional conversion.
IntegrationCLI & Python
bitnet-cli (convert / infer / bench) and a Python module (pip install bitnet-rs). Two interfaces for two workflows.
InterfaceHow it works
Pure integer arithmetic — exact at the edge case.
Activations are quantized to 8-bit integers. To exploit the "unsigned × signed" dot-product instructions in CPUs (VPDPBUSD on AVX-512, VPMADDUBSW on AVX2), bitnet-rs shifts activations to unsigned and corrects with a pre-computed row sum.
On ARM NEON, which lacks a byte dot-product, values are widened to 16 bits and accumulated. The computation is so cheap that the bottleneck is memory bandwidth, not arithmetic.
Σ wᵢ·xᵢ = Σ wᵢ·(xᵢ + 128) − 128·Σ wᵢ Everything stays in integer arithmetic — exact, including the −128 edge case.
Why this project
Designed for laptops, GPU-less servers, and embedded devices (Raspberry Pi, Jetson). Zero GPU dependency.
Bit-exact parity discipline across all instruction sets. Correctness is an automated test, not a promise.
Layered architecture (core, runtime, interface). unsafe isolated
and documented. Zero clippy warnings. Modular and auditable code.
Open-source under Apache-2.0 license. Commercially adoptable without GPL friction. Open contribution.
Performance
Generation throughput measured on Apple M4 (NEON, release build, multithreaded), on synthetic-shape models.
| Model size | tokens/second |
|---|---|
| ~0.7 B | 57 |
| ~1.5 B | 24 |
| ~3 B | 14 |
Reproducible in one command (./bench/profiles.sh).
Honest numbers from a V0 release: single-file, dense-stored weights.
The next optimization (2-bit register-unpacked weights, ×4 bandwidth)
is the roadmap priority.
Status & roadmap
Done
- Ternary format + GGUF I/O
- AVX-512 / AVX2 / NEON kernels with bit-exact parity
- Full forward pass
- KV cache FP16/int8
- Sampling + streaming
- HuggingFace tokenizer
- CLI + Python bindings
- Multithreaded matmul
- Reproducible benchmark harness
Coming next
- Register-unpacked weights (2 bits → ×4 bandwidth)
- Numerical parity validated against published BitNet checkpoints
- Direct llama.cpp checkpoint ingestion
Status: V0 "engineering-complete, pre-parity." The runtime runs end-to-end; numerical validation against a published model is the next milestone.
Quickstart
# Build
cargo build --release
# Inference
bitnet-cli infer \
--model model.gguf \
--tokenizer tokenizer.json \
--prompt "Tell me a story" \
--max-tokens 128 # Install
pip install bitnet-rs
# Streaming
from bitnet_rs import Model
m = Model("model.gguf", "tokenizer.json")
for piece in m.stream(
"Once upon a time",
max_tokens=200
):
print(piece, end="", flush=True) Who it's for
ML researchers and engineers working on efficiency and quantization of language models.
On-device and edge deployment. CPU-only inference without GPU infrastructure.
Organizations evaluating BitNet for cost-effective GPU-free inference.
Developers interested in low-level SIMD kernels, memory optimization, and integer arithmetic.
FAQ
Do I need a GPU?
No — that's the whole point. bitnet-rs targets the CPU exclusively.
Which models are supported?
BitNet b1.58 models and ternary variants, via converted GGUF checkpoints.
Which platforms?
x86-64 (AVX-512 / AVX2) and ARM64 (NEON), with a portable fallback elsewhere. The right kernel is selected at startup.
Is it production-ready?
V0 functional end-to-end. Parity validation against published checkpoints is the next milestone. Use with informed expectations.
License?
Apache-2.0.
Contribute to bitnet-rs
The code is open. Benchmarks are reproducible. Contributions are welcome.