Bitnet.cpp: Efficient Edge Inference for Ternary LLMs

Jinheng Wang, Hansong Zhou, Ting Song, Shijie Cao, Yan Xia, Ting Cao, Jianyu Wei, Shuming Ma, Hongyu Wang, Furu Wei

Abstract

The advent of 1-bit large language models (LLMs), led by BitNet b1.58, has spurred interest in ternary LLMs. Despite this, research and practical applications focusing on efficient edge inference for ternary LLMs remain scarce. To bridge this gap, we introduce Bitnet.cpp, an inference system optimized for BitNet b1.58 and ternary LLMs. Given that mixed-precision matrix multiplication (mpGEMM) constitutes the bulk of inference time in ternary LLMs, Bitnet.cpp incorporates a novel mpGEMM library to facilitate sub-2-bits-per-weight, efficient and lossless inference. The library features two core solutions: Ternary Lookup Table (TL), which addresses spatial inefficiencies of previous bit-wise methods, and Int2 with a Scale (I2_S), which ensures lossless edge inference, both enabling high-speed inference. Our experiments show that Bitnet.cpp achieves up to a 6.25x increase in speed over full-precision baselines and up to 2.32x over low-bit baselines, setting new benchmarks in the field. Bitnet.cpp is publicly available, offering a sophisticated solution for the efficient and practical deployment of edge LLMs.

Introduction

The recent rise of 1-bit LLMs—specifically ternary models like BitNet b1.58 where weights are constrained to just three values (-1, 0, 1)—promises massive reductions in memory and compute requirements. Theoretically, these weights only require approximately 1.58 bits per weight (bpw). However, standard computer memory and instruction sets are built around powers of two (8-bit, 16-bit, etc.).

Existing edge inference frameworks, such as llama.cpp or T-MAC, struggle to handle this non-integer 1.58 bpw efficiently. They typically either pad the weights to 2 bits, which wastes memory bandwidth, or use bit-wise operations that lead to severe memory access misalignment on standard CPUs. Furthermore, existing low-bit multiply-add (MAD) implementations often fail to perfectly match the specific quantization schemes used during BitNet's training, leading to accuracy degradation. Bitnet.cpp addresses these challenges by providing an inference engine that is both high-performance and mathematically lossless for ternary LLMs.

Methodology

The core of Bitnet.cpp is a custom mixed-precision matrix multiplication (mpGEMM) library. The authors categorize low-bit operations into MAD-based (multiply-then-add) and LUT-based (precomputed lookup tables) and introduce specialized kernels for each.

Ternary Lookup Table (TL)

Unlike standard bit-wise LUTs, the authors designed an element-wise LUT. To overcome the 1.58 bpw memory alignment issue, they employ a "signed-unsigned weight splitting" technique. By packing three ternary weights into a 5-bit representation (consisting of a 1-bit sign and a 4-bit index), they achieve a density of 1.67 bpw. This format aligns perfectly with SIMD registers, avoiding the performance penalties associated with misaligned memory access while maintaining high data density.

Int2 with a Scale (I2_S)

For MAD-based computation, the library includes a kernel that strictly adheres to the training constraints of BitNet b1.58, utilizing ternary weights and per-tensor int8 activations. This design ensures zero quantization loss during the inference process.

Comparison of MAD-based, Bit-wise LUT-based, and Element-wise LUT-based computation strategies.

To further optimize performance, Bitnet.cpp utilizes a pack-and-unpack instruction sequence during SIMD table lookups. This prevents 8-bit integer overflow by maintaining 16-bit precision without the high latency typically associated with traditional dequantization methods.

Experimental Results

The performance of Bitnet.cpp was evaluated across several standard NLP benchmarks, including WikiText2 for perplexity, and HellaSwag and WinoGrande for accuracy. The framework demonstrated truly lossless inference, achieving identical scores to Float16 baselines.

In terms of speed, Bitnet.cpp delivers substantial improvements. It achieves up to a 6.25x speedup over Float16 baselines and up to a 2.32x speedup over state-of-the-art low-bit baselines like T-MAC on Intel i7 CPUs. One of the most significant results is the ability to run a 100B parameter ternary LLM on consumer-grade edge hardware. Using the TL2_0 kernel, the system achieved 7.45 tokens/second on an Apple M2 Ultra and 1.69 tokens/second on an Intel i7.

Inference speed comparison across different frameworks and hardware platforms.

Discussion and Future Work

The development of Bitnet.cpp highlights the critical role of memory-compute trade-offs in edge inference. Because edge CPUs are often bottlenecked by memory bandwidth during the decoding stage of LLM generation, packing weights as densely as possible (e.g., 1.67 bpw vs 2.0 bpw) is essential for raising the performance ceiling.

While Bitnet.cpp currently focuses on edge CPUs (ARM and x86), there is significant potential for future expansion. Current hardware is highly optimized for MAD instructions, but specialized SIMD instructions for lookup-add-convert operations could further unlock the theoretical advantages of element-wise LUTs. Future work will also explore support for GPUs and NPUs, as well as optimization strategies for the compute-bound prefilling stage of inference.

Summary updated

BibTeX
@inproceedings{wang2025bitnet,
  author = {Jinheng Wang and Hansong Zhou and Ting Song and Shijie Cao and Yan Xia and Ting Cao and Jianyu Wei and Shuming Ma and Hongyu Wang and Furu Wei},
  title = {{Bitnet.cpp: Efficient Edge Inference for Ternary LLMs}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
  url = {https://openreview.net/forum?id=F8GkrUCPU0},
}
Figure