Installation
Complete installation guide for BitNet on all supported platforms
System Requirements
Required
- Python 3.9 or higher (Python 3.9 recommended)
- CMake 3.15 or higher
- C++ Compiler:
- Linux: GCC 9+ or Clang 10+
- Windows: Clang with MS-Build support or Visual Studio 2022
- macOS: Clang (Xcode Command Line Tools)
- Git for cloning the repository
- Conda (highly recommended) or pip
Optional but Recommended
- CUDA-capable GPU for optimal performance
- NVIDIA CUDA Toolkit 11.0+ for GPU acceleration
- cuDNN for optimized neural network operations
Installing Dependencies
Linux (Ubuntu/Debian)
Install Clang
bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
Alternatively, you can install from your distribution's repositories:
sudo apt-get update
sudo apt-get install clang cmake git python3 python3-pip
Windows
On Windows, you need to use a Developer Command Prompt or PowerShell for VS2022. Make sure to initialize your environment properly.
Command Prompt
"C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\Tools\VsDevCmd.bat" \
-startdir=none -arch=x64 -host_arch=x64
PowerShell
Import-Module "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
Enter-VsDevShell 3f0e31ad -SkipAutomaticLocation -DevCmdArguments "-arch=x64 -host_arch=x64"
For more Windows-specific issues, check our FAQ Page.
macOS
Install Xcode Command Line Tools:
xcode-select --install
Install CMake and other dependencies via Homebrew:
brew install cmake git python@3.9
Building from Source
Step 1: Clone the Repository
git clone --recursive https://github.com/microsoft/BitNet.git
cd BitNet
Important: Use --recursive to include submodules.
Step 2: Create Conda Environment
We highly recommend using conda for environment management:
conda create -n bitnet-cpp python=3.9
conda activate bitnet-cpp
Step 3: Install Python Dependencies
pip install -r requirements.txt
Step 4: Download and Setup Model
Download a pre-quantized model from HuggingFace:
huggingface-cli download microsoft/BitNet-b1.58-2B-4T-gguf \
--local-dir models/BitNet-b1.58-2B-4T
For a complete list of available models, see our Models Page.
Step 5: Setup BitNet Environment
python setup_env.py -md models/BitNet-b1.58-2B-4T -q i2_s
setup_env.py Options
| Option | Description | Values |
|---|---|---|
--hf-repo, -hr |
Model used for inference | Various model names |
--model-dir, -md |
Directory to save/load the model | Path to model directory |
--log-dir, -ld |
Directory to save logging info | Path to log directory |
--quant-type, -q |
Quantization type | i2_s or tl1 |
--quant-embd |
Quantize embeddings to f16 | Flag (no value) |
--use-pretuned, -p |
Use pretuned kernel parameters | Flag (no value) |
Verifying Installation
To verify your installation, try running inference:
python run_inference.py \
-m models/BitNet-b1.58-2B-4T/ggml-model-i2_s.gguf \
-p "Hello, world!"
Converting Models from .safetensors
If you have a .safetensors checkpoint, you can convert it to GGUF format:
Step 1: Download .safetensors Model
huggingface-cli download microsoft/bitnet-b1.58-2B-4T-bf16 \
--local-dir ./models/bitnet-b1.58-2B-4T-bf16
Step 2: Convert to GGUF
python ./utils/convert-helper-bitnet.py ./models/bitnet-b1.58-2B-4T-bf16
Troubleshooting
If you encounter issues during installation, check our FAQ Page for solutions to common problems. Common issues include:
- Build errors with llama.cpp
- CUDA compatibility issues
- Windows environment setup problems
- Missing dependencies
Next Steps
Once installation is complete, you can:
- Follow our Getting Started Guide for a quick introduction
- Explore Usage Examples to learn how to use BitNet
- Check out available Models for your use case
- Read the Documentation for detailed API reference
Additional Resources
- Getting Started Guide - Quick introduction
- Usage Guide - How to use BitNet
- FAQ - Common questions and answers
- GitHub Repository - Source code
- GitHub Issues - Report problems