# BitNet

> Run 1.58-bit quantized LLMs fast on your CPU

- Category: Models & Inference / Quantization & Compression
- Language: C++
- Licence: MIT
- Repository: https://github.com/microsoft/BitNet
- Canonical page: https://ai-tldr.dev/tools/bitnet/

## In short

BitNet (bitnet.cpp) is Microsoft's official inference framework for 1-bit large language models, such as BitNet b1.58. It sits in the Quantization & Compression category of the Models & Inference tools and is open-source, written in C++ and licensed MIT. To get started: clone the repository.

## Overview

BitNet (bitnet.cpp) is Microsoft's official inference framework for 1-bit large language models, such as BitNet b1.58. Instead of the usual 16-bit weights, these models store each weight in about 1.58 bits (the ternary values -1, 0, 1), so the model files and memory use shrink a lot.

The framework ships a set of optimized kernels built on top of llama.cpp that run these ternary models on CPU and GPU. On CPUs it reports speedups of roughly 1.37x to 6.17x over a baseline and large drops in energy use, and it can even run a 100B BitNet b1.58 model on a single CPU at reading speed (5-7 tokens per second).

It is aimed at developers who want to run quantized LLMs locally without a dedicated accelerator, and at researchers exploring 1-bit model inference. Within the quantization and compression space, BitNet focuses specifically on ternary (1.58-bit) models rather than general low-bit formats.

## What it does

- Official inference framework for 1-bit / 1.58-bit ternary LLMs like BitNet b1.58
- Optimized kernels (I2_S, TL1, TL2) for both x86 and ARM CPUs
- Reported CPU speedups up to ~6x and large energy-use reductions versus baseline inference
- Can run a 100B BitNet b1.58 model on a single CPU at 5-7 tokens per second
- GPU inference kernel available in addition to CPU support
- Built on the llama.cpp framework, with ready-to-use models on Hugging Face

## Getting started

Build bitnet.cpp from source, download a ternary model, then run inference in chat mode. These commands come from the project's README.

1. Clone the repository

   Clone with submodules, since bitnet.cpp pulls in dependencies like llama.cpp.

```bash
git clone --recursive https://github.com/microsoft/BitNet.git
cd BitNet
```

2. Set up the environment

   Create a Python environment and install the project's requirements.

```bash
conda create -n bitnet-cpp python=3.9
conda activate bitnet-cpp
pip install -r requirements.txt
```

3. Download a model and build kernels

   Download the official 2B model in GGUF format, then run setup_env.py to build the kernels for the i2_s quantization type.

```bash
huggingface-cli download microsoft/BitNet-b1.58-2B-4T-gguf --local-dir models/BitNet-b1.58-2B-4T
python setup_env.py -md models/BitNet-b1.58-2B-4T -q i2_s
```

4. Run inference

   Point run_inference.py at the GGUF model file. Use -p for the prompt and -cnv to enable conversation mode.

```bash
python run_inference.py -m models/BitNet-b1.58-2B-4T/ggml-model-i2_s.gguf -p "You are a helpful assistant" -cnv
```

## When to use it

- Run a quantized LLM locally on a laptop or server CPU without a dedicated GPU
- Cut memory footprint and energy use for on-device or edge inference
- Experiment with and benchmark 1-bit / 1.58-bit ternary models from Hugging Face
- Serve larger BitNet models on commodity hardware where full-precision inference would not fit
