Mindket

bitnet.cpp 1 比特推理框架

新上架第 2 版 · 更新于
星标41.5k

概览

微软官方的 1 比特大模型推理框架,基于 llama.cpp。它能在 x86 和 ARM CPU 上运行 BitNet b1.58 这类三值模型,也有 GPU 内核。这份说明涵盖 Windows、Linux、GPU 内核和嵌入模型的安装步骤。

bitnet.cpp 1 比特推理框架 是一款 GitHub 上的开源项目,属于开发类,由 Mindket 上架。可免费获取。当前为第 2 版,最近更新于 。按它的 README 从 GitHub 安装。Mindket 的设置说明可在你的 Mindket 账户获取,以 zip 压缩包下载。

速览

用在
  • Windows: Visual Studio 2022 with the clang tools, and a Developer Command Prompt or PowerShell for every command
  • Debian and Ubuntu: clang 18 or newer from the automatic installation script at apt.llvm.org
  • x86 CPUs with AVX2, and ARM CPUs with NEON or the DOTPROD extension
  • NVIDIA GPUs: a separate W2A8 CUDA kernel in the gpu folder, built by a bash script into libbitnet.so, with speeds measured on an A100 40GB
先运行
git clone --recursive https://github.com/microsoft/BitNet.git
cd BitNet
conda create -n bitnet-cpp python=3.10

平台

Windows操作系统
Linux操作系统
macOS操作系统

关于

它是什么

bitnet.cpp is Microsoft’s official inference framework for 1-bit LLMs such as BitNet b1.58. The README says it offers optimized kernels for fast and lossless inference of 1.58-bit models on CPU and GPU, with NPU support coming next. It is based on llama.cpp, and its kernels build on the lookup table methods of T-MAC. You build it from source, download a model from Hugging Face and run it with Python scripts. The README reports speedups of 1.37x to 5.07x on ARM CPUs and 2.37x to 6.17x on x86 CPUs, against full-precision models.

  1. Clone the repo with its llama.cpp code
  2. Install the Python packages in a conda environment
  3. Download a 1-bit model from Hugging Face
  4. setup_env.py builds the project, with i2_s or tl1
  5. run_inference.py starts a chat or one prompt

适合谁

Developers and researchers who want to run a small 1-bit model on a laptop or server CPU with no GPU. People who study low-bit inference also get the kernels and a benchmark script. It is a C++ project with Python scripts, so expect a compiler and a build step. Skip it if you want a finished chat app. The README says it uses existing 1-bit models to demonstrate the framework, and the largest model in its table is 10B.

Who uses it, and how
IndustryWho uses itHow they use itExample
Local AIPeople with a laptop and no GPURun the 2B chat model on the CPU with run_inference.pyA reader with an ARM laptop builds the project and chats with BitNet-b1.58-2B-4T in the terminal.
Search and RAGEngineers who embed textRun the 0.6B or 270M embedding model on an x86 CPUA team asks llama-embedding for a 1024-dimensional vector for each search query.
Performance engineeringEngineers who tune kernelsChange the tiling in gemm-config.h and compare runs with e2e_benchmark.pyAn engineer sets the row and column block sizes to fit a CPU’s cache, then reruns the benchmark.
Model researchPeople who work with low-bit modelsConvert a safetensors checkpoint to GGUF and test it on a CPUA researcher downloads the BF16 checkpoint of BitNet-b1.58-2B-4T and converts it with convert-helper-bitnet.py.

用在哪里

bitnet.cpp is a framework you build and run yourself, so this is about systems rather than coding agents. The README documents no coding-agent integration.

  • Windows: Visual Studio 2022 with the clang tools, and a Developer Command Prompt or PowerShell for every command
  • Debian and Ubuntu: clang 18 or newer from the automatic installation script at apt.llvm.org
  • x86 CPUs with AVX2, and ARM CPUs with NEON or the DOTPROD extension
  • NVIDIA GPUs: a separate W2A8 CUDA kernel in the gpu folder, built by a bash script into libbitnet.so, with speeds measured on an A100 40GB
  • Other Linux systems and macOS: the README’s build steps carry no OS label, but its clang install line is for Debian and Ubuntu only. For macOS it shows only a demo of a BitNet b1.58 3B model on an Apple M2

如何设置

Get it saves a zip of Minda’s setup notes in your downloads folder, with steps for Windows, Linux, the GPU kernel, the embedding models and tuning. They are taken from Microsoft’s README and docs, with Minda’s own notes marked as Minda’s. The main route is a clone, a conda environment, a model download and one build script.

What you need first
NeedDetail
Python3.10 or newer. The README highly recommends a conda environment
CMake3.22 or newer
clang18 or newer. On Windows it comes from Visual Studio 2022 with five options turned on. On Debian or Ubuntu the README gives an installation script
A modelDownloaded from Hugging Face. The README’s first example uses BitNet-b1.58-2B-4T-gguf
For the GPU kernelAn NVIDIA GPU and the CUDA compiler, since the compile script calls nvcc. Neither page lists them
  1. Open a shell that can build. On Windows, a Developer Command Prompt or PowerShell for VS2022. On Linux, a shell where clang 18 or newer works.
  2. Clone the repo with --recursive. Then go into its folder.
  3. Make a Python 3.10 conda environment. Then install requirements.txt.
  4. Download the model with huggingface-cli. Then run setup_env.py to build the project.
  5. Run run_inference.py with the model file.
git clone --recursive https://github.com/microsoft/BitNet.git
cd BitNet
conda create -n bitnet-cpp python=3.10
conda activate bitnet-cpp
pip install -r requirements.txt
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

The README does not list huggingface-cli as a requirement or say how to install it.

如何使用

Run the model with run_inference.py. With -cnv it starts a chat, and the text after -p becomes the system prompt.

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

The other flags the README lists are -n for the number of tokens to predict, -t for threads, -c for the prompt context size and -temp for the temperature. To measure speed, the README ships a benchmark script.

python utils/e2e_benchmark.py -m /path/to/model -n 200 -p 256 -t 4

示例

You want a vector for a search query. The embedding guide has you check out a llama.cpp branch, run setup_env.py with the 0.6B model, and then call llama-embedding:

cd 3rdparty/llama.cpp && git checkout release-bitnet-embedding-0.6b-270m && cd ../..
python setup_env.py -hr microsoft/bitnet-embedding-0.6b -md /path/to/save/model
./build/bin/llama-embedding \
  -m /path/to/save/model/bitnet-embedding-0.6b/ggml-model-i2_s.gguf \
  -p "query: What is BitNet?" \
  --embd-normalize 2 \
  --embd-output-format array

The guide says the result is a 1024-dimensional, L2-normalized embedding, printed as an array that starts [[0.0239517, 0.6826404. The guide’s FAQ says to add an instruction to the query, a one-sentence instruction that describes the task, because that is how the model is trained. Without it you will see a performance degradation. The document side needs no instruction. The guide’s own example passes “query: What is BitNet?”.

新手与专家

新手:A language model keeps what it learned in numbers called weights. A 1-bit model such as BitNet b1.58 limits each weight to -1, 0 or +1, a ternary value, which is where the 1.58 bits come from. Small weights make the model smaller and the arithmetic cheaper, so a CPU can run it. bitnet.cpp is the program that runs such models. The embedding guide says its I2_S conversion needs natively trained BitNet models with ternary weights. Its F16 conversion does not. Start with BitNet-b1.58-2B-4T, the model the README builds first.

专家:The README’s table marks which of three kernels, I2_S, TL1 and TL2, work for each model on x86 and on ARM. I2_S stores ternary weights in 2 bits. The embedding guide packs every 128 values into 32 bytes, four values to a byte, and appends a float32 scale to the buffer. The README’s 15 January 2026 CPU update adds weight-parallel and activation-parallel kernels, native I2_S GEMM and GEMV in ggml, tiling set in include/gemm-config.h, and Q6_K embedding quantization. The CPU page recommends activation parallel for I2_S, and the current kernel defaults to it.

The usage text offers only i2_s and tl1 as --quant-type values, so the README does not say how to choose TL2. It also says bitnet.cpp can run a 100B BitNet b1.58 model on one CPU at 5 to 7 tokens per second, yet no model that size is in its table. Check what that claim rests on before you plan around it.

注意事项

Most of it runs on your machine, and a few paths reach out.

  • What it fetches: git clone --recursive pulls llama.cpp code from a fork that .gitmodules names, pip installs packages, and the model comes from Hugging Face. On Debian or Ubuntu the clang line downloads a script from apt.llvm.org and runs it at once
  • Models: the framework is separate from its models, and each model has its own Hugging Face page. The embedding guide gives MIT for its models, so check the page of any other model you download
  • The maker’s own caution: under Use in High-Risk Applications, the embedding guide says its models are not recommended for commercial or real-world applications without further testing and development
  • Usage data: the README and the docs say nothing about telemetry
  • Windows traps: every command needs the Developer shell, and the README prints the two PowerShell commands of its clang fix on one line. Minda’s Windows notes split them onto two lines
  • The GPU kernel: its page is tailored to BitNet-b1.58-2B-4T, and its compile script builds for compute_80
  • A mismatch in the docs: the README’s usage text calls --quant-embd a conversion to f16, and the CPU page says it converts embeddings to Q6_K
  • Removal: the README gives no uninstall steps. Minda’s notes say to delete the clone and its model folder and to remove the conda environment
  • License: MIT. The LICENSE file reads “Copyright (c) Microsoft Corporation.”

README 和文件

README

bitnet.cpp:安装说明

这个工具包里只有安装说明,由 Mindket 编写。bitnet.cpp 要从微软的仓库编译和运行,地址是 https://github.com/microsoft/BitNet

这些说明不是微软写的,也没有得到微软的认可。README 称 bitnet.cpp 是“the official inference framework for 1-bit LLMs (e.g., BitNet b1.58)”,意思是:1 比特大模型(比如 BitNet b1.58)的官方推理框架。它“offers a suite of optimized kernels that support fast and lossless inference of 1.58-bit models on CPU and GPU (NPU support coming next).”,意思是:提供一套优化过的内核,支持在 CPU 和 GPU 上快速、无损地推理 1.58 比特模型,NPU 支持即将推出。

许可证:MIT。LICENSE 文件(https://github.com/microsoft/BitNet/blob/main/LICENSE )是 MIT 许可证,写着“Copyright (c) Microsoft Corporation.”。README 说这个项目基于 llama.cpp 框架,它的内核建立在 T-MAC(https://github.com/microsoft/T-MAC/ )的查表方法之上。

会得到什么

  • 一份仓库的克隆。README 用 --recursive 克隆,会把 llama.cpp 代码一并拉到 3rdparty/llama.cpp 下。仓库的 .gitmodules 文件写明来源是 GitHub 上的一个 llama.cpp 分叉(https://github.com/isHuangXin/llama.cpp.git)。来源见 https://github.com/microsoft/BitNet/blob/main/README.md 和 https://github.com/microsoft/BitNet/blob/main/.gitmodules
  • requirements.txt 里的 Python 包,它会把 llama.cpp 自己给转换脚本用的依赖文件一起装上。
  • 由 setup_env.py 做出的一份编译产物,以及你另外下载的模型。README 的例子把模型放在克隆文件夹里的 models/。CPU 优化页面和嵌入模型指南从 build/bin/ 运行编译出的工具。
  • 运行模型的脚本 run_inference.py,和测速度的脚本 utils/e2e_benchmark.py。

bitnet.cpp 是框架,模型是从 Hugging Face 另外下载的。README 说它用现有的 1 比特模型来展示 bitnet.cpp 能做什么,并希望这次发布能推动更大规模的 1 比特大模型,在模型大小和训练词元数上都更大。

事先需要准备

  • Python 3.10 或更高版本、CMake 3.22 或更高版本、clang 18 或更高版本。README 强烈建议用 conda。来源见 https://github.com/microsoft/BitNet/blob/main/README.md
  • 在 Windows 上,需要打开五个选项的 Visual Studio 2022,并且每条命令都要在 VS2022 的开发者命令提示符或 PowerShell 里运行。见 setup/windows.md。
  • 在 Debian 或 Ubuntu 上,README 给了一个装 clang 的自动安装脚本。见 setup/linux.md。
  • 要用 GPU 内核,需要 CUDA 环境:它的编译脚本调用 nvcc。见 setup/gpu.md。
  • 一个来自 Hugging Face 的模型。README 没有写磁盘和内存需求。

主要命令

在能用 clang 的 shell 里运行。每条命令都抄自 README 的 Installation、Build from source 和 Usage 部分:https://github.com/microsoft/BitNet/blob/main/README.md

git clone --recursive https://github.com/microsoft/BitNet.git
cd BitNet
conda create -n bitnet-cpp python=3.10
conda activate bitnet-cpp

pip install -r requirements.txt
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
python run_inference.py -m models/BitNet-b1.58-2B-4T/ggml-model-i2_s.gguf -p "You are a helpful assistant" -cnv

README 没有把 huggingface-cli 列为需求,也没有说怎么安装它。

各平台的说明

  • setup/windows.md:Visual Studio 2022、开发者 shell,以及 FAQ 里的两个修复办法
  • setup/linux.md:Debian 和 Ubuntu 上的 clang,以及 README 对其他系统的说法
  • setup/gpu.md:W2A8 的 GPU 内核和它的端到端运行
  • setup/models-and-kernels.md:哪些模型能在 x86 和 ARM 上运行,以及 setup_env.py 和 run_inference.py 的选项
  • setup/embeddings.md:0.6B 和 270M 的嵌入模型、它们的 I2_S 转换和第一次生成嵌入向量
  • setup/tune-and-benchmark.md:CPU 调优文件、嵌入层量化和基准测试脚本

更新或卸载

README 和文档都没有给出更新或卸载步骤。要移除它(这是 Mindket 的说明,不是微软的),就删掉克隆的文件夹和它的模型文件夹,再用 conda 自己的移除命令删掉 conda 环境。

使用数据和对外连接

README 和文档都没有提到遥测或使用数据,也没有说程序在运行模型时会连到服务器。下面这些步骤会连到外面:git clone --recursive、从 Hugging Face 下载、pip 安装,以及在 Debian 或 Ubuntu 上从 apt.llvm.org 下载 clang 脚本。README 里链接的在线演示是一个单独托管的页面,不属于安装的一部分。

来源

  • README:https://github.com/microsoft/BitNet/blob/main/README.md
  • LICENSE:https://github.com/microsoft/BitNet/blob/main/LICENSE
  • requirements.txt:https://github.com/microsoft/BitNet/blob/main/requirements.txt
  • .gitmodules:https://github.com/microsoft/BitNet/blob/main/.gitmodules
  • CPU 推理优化:https://github.com/microsoft/BitNet/blob/main/src/README.md
  • GPU 内核:https://github.com/microsoft/BitNet/blob/main/gpu/README.md
  • GPU 依赖:https://github.com/microsoft/BitNet/blob/main/gpu/requirements.txt
  • GPU 编译脚本:https://github.com/microsoft/BitNet/blob/main/gpu/bitnet_kernels/compile.sh
  • 嵌入模型指南:https://github.com/microsoft/BitNet/blob/main/docs/bitnet-embeddings-i2s-guide.md
文件
README.md  5 KB
setup/embeddings.md  4 KB
setup/gpu.md  3 KB
setup/linux.md  2 KB
setup/models-and-kernels.md  5 KB
setup/tune-and-benchmark.md  4 KB
setup/windows.md  3 KB

7 个文件,共 28 KB,以 zip 压缩包下载。

更新内容

  • 第 2 版 · 2026-11-09

    Updated by Mindket to the current version of this kit.

  • 第 1 版 · 2026-11-03

评价

还没有评分

写评价

还没有评价。

大家怎么说

Hacker News、Bluesky、X、Reddit、Facebook 和 YouTube 上提到这个项目的帖子和评论,来自每周一次的搜索和 Trendshift。它们不是 Mindket 写的,也未经核实,点开即可在原帖处阅读。

galeosMicrosoft BitNet: inference framework for 1-bit LLMs173 分 · 33 条回复Hackobar5. Coding Agents Increase Code Volume but Not Software Output LINK 6. Microsoft releases BitNet inference framework for 1-bit LLMs LINK1 条回复@AndyBuildsAIBig AI on cheap hardware, free? BitNet shrinks weights to -1/0/+1 to run fast on a CPU. AirLLM fits a 70B model in ~4GB GPU, but it's slow. Which would you try? #AI https://t.co/ywZCzq58rxr/BestGitHubReposBitNet: Official inference framework for 1-bit LLMs (40.7k stars)dhilipsivaShow HN: A Zero-Copy 1.58-bit LLM Engine hitting 117 Tokens/s on single CPU coreThe Project: I am building R3-Engine, a from-scratch, local AI inference engine for Microsoft's bitnet-b1.58-2B-4T. It is written in 100% Safe Rust, natively cross-compiles to Wasm SIMD128, and uses Zero heap allocations in the execution loop. The Physics: By mapping a 64-byte aligned .r3 file…4 分@sm14yu.bsky.socialMicrosoft released BitNet embedding models using 1.58-bit ternary weights. The 600M version reaches 67.60 benchmark score vs 67.95 for its FP16 teacher, with up to 2.28× CPU throughput.@laogeai想本地跑大模型,一看显存就劝退?不一定得买显卡 💪 Petals 多机拼集群、微软 BitNet 1 比特量化 CPU 能推、Dolly 拿来学流程正好。 https://t.co/QwWYJ6xeTcFlere-ImsahoMicrosoft BitNet – inference with 1.58 bits2 分 · 1 条回复Marc ON4AAX #HAMR #DX #ax25 #MultiLingual #TheOutpost #TSF 📻🎙️📡github.com/microsoft/Bi...@Samir_Magdiii3 GitHub repos trending hard right now: 1-bit LLM inference, live satellite intel in your browser, and free web eyes for your AI agent. Swipe 👇 Links in reply. #AI #GitHub https://t.co/fTHFAL176jufos1111Running Microsoft's BitNet via Electron, React and Astro1 分 · 1 条回复@sm14yu.bsky.socialMicrosoft open-sourced BitNet, a C++ inference framework for 1-bit LLMs. It runs up to 100B-parameter models on consumer CPUs with reported 6x speedups and 82% lower energy use, supporting local offline chat and RAG without GPUs.

搜索日期

Mindket 的更多商品

查看 Mindket 的全部商品

Bonsai-27B-GGUF

lmstudio-community · 工具包

面向 LM Studio 的 27B Bonsai 模型 GGUF 转换版,含 3.80 GB 的 Q1_0 语言文件和 0.93 GB 的 BF16 视觉投影器。已测试文本、视觉和并行工具调用。

新上架

以每权重 2.9 位的 EXL3 量化运行 DeepSeek-V4.1-Flash-1017,这是一份 196 GiB 的副本,适合在自己硬件上部署大模型的人。困惑度与原模型相差不大。

新上架

MusicGen Small

facebook · 工具包

根据文字描述或音频提示生成短音乐片段,是 facebook MusicGen 的 small 检查点。适合想在自己电脑上试用文字生成音乐的开发者和音乐爱好者。

新上架

开发类的相似商品

查看开发类的全部商品

Lexnet

alpindale · 工具包

用一个只有约 984 个权重的小型神经网络,为 C 源代码的每个字符打上语法高亮标签,通过一个小小的 C 程序运行。适合对手工设计的网络好奇的开发者和研究者。

新上架

FLUX.2 Klein LoRA Studio

prithivMLmods · 工具包

在浏览器或你自己的电脑上,用一个 Gradio 应用试用 FLUX.2 Klein 图像模型的一组 LoRA。适合制作或测试 AI 图片的人。

新上架

anaksor-ocr

Sokheng · 工具包

这个模型从文档、收据和路牌照片里读取高棉语和英语文字,用一个检测器找文本行,再用识别器读每一行。适合需要在 Python 里做高棉语 OCR 的开发者。

新上架