microsoft/bitnet-b1.58-2B-4T (This repository): Contains the packed 1.58-bit weights optimized for efficient inference. Use this for deployment.microsoft/bitnet-b1.58-2B-4T-bf16: Contains the master weights in BF16 format. Use this only for training or fine-tuning purposes.microsoft/bitnet-b1.58-2B-4T-gguf: Contains the model weights in GGUF format, compatible with the bitnet.cpp library for CPU inference.BitLinear layers (BitNet framework).
subln normalization.transformers)Please do NOT expect performance efficiency gains (in terms of speed, latency, or energy consumption) when using this model with the standard transformers library, even with the required fork.The current execution paths within transformers do not contain the specialized, highly optimized computational kernels required to leverage the advantages of the BitNet architecture. Running the model via transformers will likely result in inference speeds and energy usage comparable to, or potentially worse than, standard full-precision models within this framework on both CPU and GPU.While you might observe reduced memory usage due to the quantized weights, the primary computational efficiency benefits are not accessible through this standard transformers usage path.For achieving the efficiency benefits demonstrated in the technical paper, you MUST use the dedicated C++ implementation: bitnet.cpp.
pip install git+https://github.com/shumingma/transformers.gittransformers library. This installation method may change in the future.1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_id = "microsoft/bitnet-b1.58-2B-4T"
5
6# Load tokenizer and model
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8model = AutoModelForCausalLM.from_pretrained(
9 model_id,
10 torch_dtype=torch.bfloat16
11)
12
13# Apply the chat template
14messages = [
15 {"role": "system", "content": "You are a helpful AI assistant."},
16 {"role": "user", "content": "How are you?"},
17]
18prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
19chat_input = tokenizer(prompt, return_tensors="pt").to(model.device)
20
21# Generate response
22chat_outputs = model.generate(**chat_input, max_new_tokens=50)
23response = tokenizer.decode(chat_outputs[0][chat_input['input_ids'].shape[-1]:], skip_special_tokens=True) # Decode only the response part
24print("\nAssistant Response:", response)bitnet.cpp)| Benchmark | LLaMA 3.2 1B | Gemma-3 1B | Qwen2.5 1.5B | SmolLM2 1.7B | MiniCPM 2B | BitNet b1.58 2B |
|---|---|---|---|---|---|---|
| Memory (Non-emb) | 2GB | 1.4GB | 2.6GB | 3.2GB | 4.8GB | 0.4GB |
| Latency (CPU Decoding) | 48ms | 41ms | 65ms | 67ms | 124ms | 29ms |
| Energy (Estimated) | 0.258J | 0.186J | 0.347J | 0.425J | 0.649J | 0.028J |
| Training Tokens (Pre-train) | 9T* | 2T** | 18T | 11T | 1.1T | 4T |
| ARC-Challenge | 37.80 | 38.40 | 46.67 | 43.52 | 44.80 | 49.91 |
| ARC-Easy | 63.17 | 63.13 | 76.01 | 62.92 | 72.14 | 74.79 |
| OpenbookQA | 34.80 | 38.80 | 40.80 | 46.00 | 40.20 | 41.60 |
| BoolQ | 64.65 | 74.22 | 78.04 | 75.78 | 80.67 | 80.18 |
| HellaSwag | 60.80 | 57.69 | 68.28 | 71.71 | 70.81 | 68.44 |
| PIQA | 74.21 | 71.93 | 76.12 | 76.12 | 76.66 | 77.09 |
| WinoGrande | 59.51 | 58.48 | 62.83 | 68.98 | 61.80 | 71.90 |
| CommonsenseQA | 58.48 | 42.10 | 76.41 | 63.55 | 71.74 | 71.58 |
| TruthfulQA | 43.80 | 38.66 | 46.67 | 39.90 | 41.41 | 45.31 |
| TriviaQA | 37.60 | 23.49 | 38.37 | 45.97 | 34.13 | 33.57 |
| MMLU | 45.58 | 39.91 | 60.25 | 49.24 | 51.82 | 53.17 |
| HumanEval+ | 31.10 | 37.20 | 50.60 | 28.00 | 43.90 | 38.40 |
| GSM8K | 38.21 | 31.16 | 56.79 | 45.11 | 4.40 | 58.38 |
| MATH-500 | 23.00 | 42.00 | 53.00 | 17.60 | 14.80 | 43.40 |
| IFEval | 62.71 | 66.67 | 50.12 | 57.91 | 36.81 | 53.48 |
| MT-bench | 5.43 | 6.40 | 6.12 | 5.50 | 6.57 | 5.85 |
| Average | 44.90 | 43.74 | 55.23 | 48.70 | 42.05 | 54.19 |