You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!--Copyright 2025 The BitNet Team and The HuggingFace Team. All rights reserved.
2
+
3
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+
the License. You may obtain a copy of the License at
5
+
6
+
http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+
specific language governing permissions and limitations under the License.
11
+
12
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
13
+
rendered properly in your Markdown viewer.
14
+
15
+
-->
16
+
17
+
# BitNet
18
+
19
+
## Overview
20
+
21
+
Trained on a corpus of 4 trillion tokens, this model demonstrates that native 1-bit LLMs can achieve performance comparable to leading open-weight, full-precision models of similar size, while offering substantial advantages in computational efficiency (memory, energy, latency).
Several versions of the model weights are available on Hugging Face:
30
+
31
+
*[**`microsoft/bitnet-b1.58-2B-4T`**](https://huggingface.co/microsoft/bitnet-b1.58-2B-4T): Contains the packed 1.58-bit weights optimized for efficient inference. **Use this for deployment.**
32
+
33
+
*[**`microsoft/bitnet-b1.58-2B-4T-bf16`**](https://huggingface.co/microsoft/bitnet-b1.58-2B-4T-bf16): Contains the master weights in BF16 format. **Use this only for training or fine-tuning purposes.**
34
+
35
+
*[**`microsoft/bitnet-b1.58-2B-4T-gguf`**](https://huggingface.co/microsoft/bitnet-b1.58-2B-4T-gguf): Contains the model weights in GGUF format, compatible with the `bitnet.cpp` library for CPU inference.
36
+
37
+
38
+
### Model Details
39
+
40
+
41
+
***Architecture:** Transformer-based, modified with `BitLinear` layers (BitNet framework).
42
+
* Uses Rotary Position Embeddings (RoPE).
43
+
* Uses squared ReLU (ReLU²) activation in FFN layers.
* No bias terms in linear or normalization layers.
46
+
***Quantization:** Native 1.58-bit weights and 8-bit activations (W1.58A8).
47
+
* Weights are quantized to ternary values {-1, 0, +1} using absmean quantization during the forward pass.
48
+
* Activations are quantized to 8-bit integers using absmax quantization (per-token).
49
+
***Crucially, the model was *trained from scratch* with this quantization scheme, not post-training quantized.**
50
+
***Parameters:**~2 Billion
51
+
***Training Tokens:** 4 Trillion
52
+
***Context Length:** Maximum sequence length of **4096 tokens**.
53
+
**Recommendation:* For optimal performance on tasks requiring very long contexts (beyond the pre-training length or for specialized long-reasoning tasks), we recommend performing intermediate long-sequence adaptation/training before the final fine-tuning stage.
54
+
***Training Stages:**
55
+
1.**Pre-training:** Large-scale training on public text/code and synthetic math data using a two-stage learning rate and weight decay schedule.
56
+
2.**Supervised Fine-tuning (SFT):** Fine-tuned on instruction-following and conversational datasets using sum loss aggregation and specific hyperparameter tuning.
57
+
3.**Direct Preference Optimization (DPO):** Aligned with human preferences using preference pairs.
> Please do NOT expect performance efficiency gains (in terms of speed, latency, or energy consumption) when using this model with the standard transformers library.
67
+
>
68
+
> 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.
69
+
>
70
+
> 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.
71
+
>
72
+
> For achieving the efficiency benefits demonstrated in the technical paper, you MUST use the dedicated C++ implementation: [bitnet.cpp](https://github.com/microsoft/BitNet).
73
+
74
+
### Requirements
75
+
76
+
```bash
77
+
pip install transformers
78
+
```
79
+
80
+
### Example
81
+
82
+
```python
83
+
import torch
84
+
from transformers import AutoModelForCausalLM, AutoTokenizer
0 commit comments