Anderion Labs · bitnet-rs

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.

B.01

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.

B.02

Features

SIMD

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.

Infrastructure
BIT

Bit-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.

Quality
FWD

Full forward pass

RMSNorm, causal multi-head attention with RoPE and GQA, SwiGLU FFN, embeddings, and high-precision output head.

Architecture
KV

KV cache & generation

FP16 cache (default), int8 or F32. Greedy, temperature, top-k, top-p, min-p sampling. Streaming API.

Runtime
TOK

Tokenizer

HuggingFace tokenizer integration (tokenizer.json). Compatible with existing models without additional conversion.

Integration
CLI

CLI & Python

bitnet-cli (convert / infer / bench) and a Python module (pip install bitnet-rs). Two interfaces for two workflows.

Interface
B.03

How 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.

Key formula Σ wᵢ·xᵢ = Σ wᵢ·(xᵢ + 128) − 128·Σ wᵢ

Everything stays in integer arithmetic — exact, including the −128 edge case.

B.04

Why this project

CPU-first

Designed for laptops, GPU-less servers, and embedded devices (Raspberry Pi, Jetson). Zero GPU dependency.

Proven correctness

Bit-exact parity discipline across all instruction sets. Correctness is an automated test, not a promise.

Clean Rust

Layered architecture (core, runtime, interface). unsafe isolated and documented. Zero clippy warnings. Modular and auditable code.

Apache-2.0

Open-source under Apache-2.0 license. Commercially adoptable without GPL friction. Open contribution.

B.05

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.

B.06

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.

B.07

Quickstart

CLI
# Build
cargo build --release

# Inference
bitnet-cli infer \
  --model model.gguf \
  --tokenizer tokenizer.json \
  --prompt "Tell me a story" \
  --max-tokens 128
Python
# 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)
B.08

Who it's for

ML Research

ML researchers and engineers working on efficiency and quantization of language models.

Edge & embedded

On-device and edge deployment. CPU-only inference without GPU infrastructure.

Enterprise

Organizations evaluating BitNet for cost-effective GPU-free inference.

Rust developers

Developers interested in low-level SIMD kernels, memory optimization, and integer arithmetic.

B.09

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.

Open-source

Contribute to bitnet-rs

The code is open. Benchmarks are reproducible. Contributions are welcome.