$ show microsoft/BitNet
BitNet is a high-performance inference framework for 1-bit large language models, specifically the BitNet b1.58 ternary architecture. It provides CPU (x86 with AVX2, ARM with NEON) and GPU (NVIDIA CUDA) backends with custom quantization formats (I2_S, TL1, TL2) that pack ternary weights and use efficient look-up tables and integer matrix multiplication (int8Γint2) to achieve significant speedups over full-precision models (1.37β6.17Γ on CPU). The system is built on a fork of llama.cpp, adding custom GEMM kernels and a Python utility suite for model conversion, embedding quantization, benchmark, and deployment. It includes a CLI interactive mode and an HTTP server for production serving. The repository contains extensive performance benchmarks and configuration tools, making it a production-ready solution for deploying 1-bit LLMs on commodity hardware.
The LLM identified 3 files worth highlighting for reuse:
A self-contained CUDA kernel for int8Γint2 matrix multiplication using the dp4a instruction. It dispatches to specialized ladder kernels based on matrix dimensions (e.g., 2560Γ2560, 3200Γ8640) and supports both column and row layouts. This kernel could be extracted and reused in any CUDA project requiring efficient ternary-by-int8 GEMM, with minimal modification to expose a general interface.
Implements a LazyTensor/LazyModel framework that defers tensor loading and quantization until needed, allowing conversion of large models with limited memory. The pattern supports on-the-fly processing, parallel map operations, and a growing GGUF output file. This abstraction is reusable for any model format conversion that requires efficient memory handling and progressive writing.
Generates model-specific C++ kernel headers for TL2 quantization (3-table + 2-table LUT GEMM) from a configuration file. It produces optimized lookup tables, preprocessing routines, and main gemm functions tailored to exact matrix dimensions. This pattern allows automatic generation of architecture-specific kernels, and the script can be adapted to generate kernels for new models or other low-bit schemes with a new configuration.