BitNet is a Transformer trained from scratch with the weights of the linear layers of a large language model set to 1 bit, either +1 or ā1. It was proposed in 2023 by Wang, Ma, Dong, and colleagues at Microsoft Research and elsewhere (published on arXiv).
The main burdens of running a large language model are reading huge weights from memory and the vast number of multiplications in matrix products. Most earlier approaches were post-training methods that quantize a trained model afterward with tools such as GPTQ or SmoothQuant. They are convenient, but accuracy drops sharply as the bit width decreases, and at 1ā2 bits the model breaks down.
BitNet takes the quantization-aware training (QAT) route: it simply replaces the linear layers of a Transformer (PyTorch's nn.Linear) with a layer called BitLinear and trains a model with 1-bit weights from scratch. In BitLinear, weights are ±1 and activations are 8 bits (W1A8).
The paper's three main results are as follows.
At 6.7B parameters, 1-bit BitNet achieves accuracy comparable to a 16-bit model post-training quantized to 8 bits, and clearly outperforms post-training quantization at 4 bits or fewer.
Scaling from 125M to 30B, the loss follows a power law just like the 16-bit Transformer, and the gap between the two narrows as models get larger.
The arithmetic energy of matrix multiplication is estimated to be far smaller than that of a 16-bit Transformer.
Note that BitNet b1.58, released by the same group in 2024, is a method from a separate paper that makes weights ternary (ā1, 0, +1). This article covers the original BitNet with ±1 weights.
Theory (How BitLinear Computes)
BitNet has the same structure as an ordinary Transformer, stacking blocks of self-attention and feed-forward networks (left of the figure at the top). The only difference is that the matrix products inside the blocks are computed with BitLinear. Components such as the input and output embeddings remain at high precision (the reasons are given later).
BitLinear computes a linear layer in the following steps (Section 2.1 of the paper; center of the figure at the top).
Quantize the normalized input to b bits (8 bits in the paper) with absmax quantization.
Make the weights W 1-bit.
Compute the matrix product of the 1-bit weights and the quantized input.
Multiply the output by the weight and input scales to restore the original magnitude (dequantization).
Making weights 1-bit
From the weight matrix WāRnĆm, first subtract the overall mean α to center it at 0, then take the sign (Eqs. (1)ā(3)).
W=Sign(Wāα),α=nm1āijāāWijā
Here, Sign returns +1 for positive values and ā1 for values at or below 0. Subtracting the mean makes full use of the two available values. As a scale that reduces the difference between the real-valued and 1-bit weights, the mean absolute value β=nm1āā„Wā„1ā is used (Eq. (12)).
Making activations 8-bit
The input is divided by its maximum absolute value γ and scaled into the range [āQbā,Qbā] (Qbā=2bā1) (Eqs. (4) and (5)).
ϵ is a small number that prevents overflow at the edges of the range. Only for activations before nonlinear functions such as ReLU, the minimum Ī· is subtracted first and the values are scaled into [0,Qbā], making all values non-negative (Eq. (6)). The range is determined over the whole tensor during training and per token during inference.
The combined formula
Putting it all together, BitLinear is the following equation (Eq. (11)).
y=WQuant(LN(x))ĆQbāβγā
Since W is ±1, the matrix product becomes additions and subtractions of the quantized activations. The only remaining multiplications are the final ones by the scales β and γ/Qbā.
LayerNorm is placed before quantization to preserve the variance of the output. Assuming the weights and inputs are independent, the output variance is roughly E[x~2] (Eqs. (8)ā(10)). Normalizing the input with LayerNorm keeps this value around 1, matching the scale of a real-valued model with ordinary initialization. Inside a Transformer, this has the same implementation as the SubLN structure.
Training and Why It Is Stable
BitNet training uses three techniques (Section 2.2 of the paper).
Straight-through estimator (STE): Sign and Clip have zero derivative almost everywhere. In backpropagation, these functions are bypassed and the gradient flows through unchanged.
Keep high-precision weights: Gradients and optimizer states (such as the moving averages in Adam) are kept at high precision. High-precision weights (latent weights) are retained to accumulate updates, and they are binarized to 1 bit on every forward pass. The latent weights are not used at inference. This is the same idea as BinaryConnect.
Use a large learning rate: Moving a latent weight slightly does not change the 1-bit weight unless its sign flips. Convergence is therefore slow, especially early in training. After trying several approaches, the paper concluded that increasing the learning rate is the simplest and best option.
In the paper's stability experiment (Figure 5), with the same large learning rate, the 16-bit Transformer diverged early in training while BitNet converged. Moreover, BitNet's perplexity improved as the learning rate increased.
What is made 1-bit and what is kept
BitNet makes only the weights of linear layers with parameters 1-bit. Everything else is kept at high precision (8 bits in the experiments). The paper gives three reasons.
Negligible relative to the total computation of a large language model
The computation inside attention that produces outputs from Q, K, and V
As models grow, its cost is much smaller than that of the parameterized projections
Input and output embeddings
Selecting the next token requires high-precision probabilities
Techniques for model parallelism
Large models split a single matrix across multiple GPUs for computation (tensor parallelism). However, α, β, γ, Ī·, and the mean and variance of LayerNorm are computed over the whole matrix, which increases communication between GPUs. The paper therefore divides weights and activations into G groups along the partition dimension and computes the scales and normalization statistics per group (Eqs. (13)ā(15); the normalization follows the idea of Group Normalization). This enables model parallelism without additional communication.
Experimental Results
The paper trains BitNet from 125M to 30B on English text (Pile, Common Crawl, RealNews, CC-Stories) and compares it with 16-bit Transformers under the same settings.
Comparison with post-training quantization
The table compares models at 6.7B parameters against 16-bit Transformers with post-training quantization (Table 3). It shows perplexity (PPL; lower is better) and zero-shot accuracy on four tasks (higher is better: Winograd, Winogrande, HellaSwag, StoryCloze).
Weight bits
Method
Post-training quantization
PPL
Winograd
Winogrande
HellaSwag
StoryCloze
Avg.
16
Transformer
ā
15.19
66.7
54.3
42.9
67.4
57.8
8
Absmax
ā
21.43
60.4
52.0
38.3
62.7
53.4
8
SmoothQuant
ā
15.67
65.3
53.1
40.9
67.6
56.7
4
GPTQ
ā
16.05
57.2
51.2
39.9
63.4
52.9
2
QuIP
ā
70.43
56.1
51.2
30.3
58.4
49.0
1
SmoothQuant
ā
3.3e21
50.5
49.5
24.6
53.1
44.4
1
BitNet
ā
17.07
66.3
51.4
38.9
66.9
55.9
The results show the following.
1-bit BitNet was about as accurate as 8-bit post-training quantization. Its average accuracy of 55.9 was close to 8-bit SmoothQuant (56.7) and higher than 4-bit GPTQ (52.9).
Post-training quantization collapses at 2 bits or fewer. SmoothQuant at 1 bit had an extremely large perplexity, and its accuracy was about the same as random guessing.
A gap to the 16-bit model remains. Perplexity was 17.07 versus 15.19, and average accuracy 55.9 versus 57.8.
Trends across model sizes
When the relationship between model size N and loss L is expressed as the power law L(N)=aNb+c, BitNet follows a shape similar to the 16-bit Transformer (Figure 3). A fit from 125Mā6.7B predicts the 13B and 30B losses well, and the gap to the 16-bit model narrows as models get larger. The paper also presents an "inference-optimal scaling law" that plots loss against inference energy, stating that BitNet achieves lower loss for the same energy.
Energy estimates
The paper estimates the arithmetic energy of matrix multiplication from a table of per-operation energy costs (Table 1; input length 512). For a 6.7B model on a 7nm process, multiplication cost 1.14J for the 16-bit Transformer versus 0.02J for BitNet, and addition cost 0.54J versus 0.04J. In BitNet's matrix products, the weights are 1-bit, so multiplications are needed only for the final scaling and the rest are additions.
Effect of each technique
In the ablation (Table 4), changing activation quantization from absmax to a learned scale (Elastic) or replacing SubLN with Pre-LN worsened perplexity from 20.34 to 22ā24. The paper states that absmax makes training more stable and allows a larger learning rate.
Practical Considerations
It must be trained from scratch. BitNet is a quantization-aware training method, not a way to convert a trained model to 1 bit after the fact. Training requires as much data and compute as an ordinary Transformer.
Memory during training does not decrease. Gradients, optimizer states, and latent weights are kept at high precision, so memory shrinks only at inference.
The energy figures are estimates. The values in Table 1 are computed from a table of per-operation energy costs, not measured on real machines. Without computational kernels or dedicated hardware that handle 1-bit weights efficiently, the speed and energy advantages do not materialize.
The learning rate setting differs from usual. BitNet converged better with large learning rates that would make 16-bit models diverge. Reusing the settings of a 16-bit model as is may slow convergence.
At 6.7B, BitNet had a perplexity 1.9 higher than the 16-bit Transformer, and its average zero-shot accuracy was 1.9 points lower. Note that it is "comparable to 8-bit post-training quantization," not "the same as a 16-bit model." The successor, BitNet b1.58, narrowed the gap to 16 bits by making weights ternary.
Comparison with Other Methods
The table compares methods that make weights binary or ternary with ordinary low-bit quantization along the same dimensions.
BitNet can be seen as bringing XNOR-Net's approximation of "sign multiplied by the mean absolute value" to the linear layers of large language models. However, it keeps activations at 8 bits rather than ±1, and places LayerNorm (SubLN) before quantization to stabilize training.
When a large language model can be trained from scratch and inference memory and energy should be cut substantially, the BitNet family is a candidate. To keep the gap to 16-bit models as small as possible, BitNet b1.58 is the better fit.
To slim down an existing trained model, use post-training quantization such as GPTQ or AWQ, which requires no retraining.
PyTorch example
ā¶Show code
python
import torch
import torch.nn as nn
import torch.nn.functional as F
class BitLinear(nn.Linear):
"""BitNet's BitLinear (Eq. (11)): y = W~ Ā· Quant(LN(x)) Ā· beta Ā· gamma / Q_b
Weights are ±1, activations are b bits. Backprop passes gradients via the straight-through estimator (STE)"""
def __init__(self, in_features, out_features, bits=8, eps=1e-5):
super().__init__(in_features, out_features, bias=False)
self.ln = nn.LayerNorm(in_features, elementwise_affine=False) # normalization corresponding to SubLN
self.Qb = 2 ** (bits - 1)
self.eps = eps
def quant_weight(self):
w = self.weight # high-precision latent weights
alpha = w.mean() # Eq. (3): mean
beta = w.abs().mean() # Eq. (12): mean absolute value
w_c = w - alpha
w_bin = torch.where(w_c > 0, torch.ones_like(w), -torch.ones_like(w)) # Eqs. (1)(2)
w_bin = w_c + (w_bin - w_c).detach() # STE: ±1 in forward, identity in backward
return w_bin, beta
def quant_act(self, x):
# gamma = max|x| over the whole tensor in training, per token in inference (Section 2.1)
if self.training:
gamma = x.abs().max()
else:
gamma = x.abs().amax(dim=-1, keepdim=True)
gamma = gamma.clamp(min=self.eps)
x_s = torch.clamp(x * self.Qb / gamma, -self.Qb + self.eps, self.Qb - self.eps) # Eq. (4)
x_q = x_s + (torch.round(x_s) - x_s).detach() # round to 8-bit values (STE)
return x_q, gamma
def forward(self, x):
x_q, gamma = self.quant_act(self.ln(x))
w_bin, beta = self.quant_weight()
return F.linear(x_q, w_bin) * beta * gamma / self.Qb # dequantize
# Example: replace the nn.Linear layers of a Transformer feed-forward block with BitLinear (Eq. (6), mapping activations before the nonlinearity to [0, Q_b], is omitted)
class BitFFN(nn.Module):
def __init__(self, d_model=512, d_ff=2048):
super().__init__()
self.up = BitLinear(d_model, d_ff)
self.down = BitLinear(d_ff, d_model)
def forward(self, x):
return self.down(F.gelu(self.up(x)))
ffn = BitFFN()
# The paper uses large learning rates (e.g., 4.8e-4 for 6.7B, 2.4e-3 for 125M). Adam betas are (0.9, 0.98)
optimizer = torch.optim.AdamW(ffn.parameters(), lr=2.4e-3, betas=(0.9, 0.98), weight_decay=0.01)
x = torch.randn(4, 16, 512) # (batch, tokens, dim)
ffn.train()
loss = ffn(x).pow(2).mean()
optimizer.zero_grad()
loss.backward() # gradients flow to the latent weights via STE
optimizer.step()
ffn.eval() # inference: activation scales are computed per token
with torch.no_grad():
print(ffn(x).shape)
FAQ
Q. What is the difference between BitNet and BitNet b1.58?
A.
They are methods from separate papers. BitNet (Wang et al., 2023) binarizes weights to +1 and ā1 by subtracting the mean and taking the sign. BitNet b1.58 (Ma et al., 2024) adds 0 to make weights ternary (ā1, 0, +1) by dividing by the mean absolute value and rounding. b1.58 reports perplexity comparable to 16-bit LLaMA-style models at sizes of 3B and above.
Q. Can a trained model be turned into BitNet?
A.
BitNet in the paper is a method that trains with 1-bit weights from scratch (quantization-aware training). Applying 1-bit quantization afterward to a trained 16-bit model makes perplexity extremely bad, as shown in Table 3 of the paper. Obtaining BitNet's accuracy requires retraining a model built with BitLinear.
Q. Are BitNet's weights really just 1 bit?
A.
The linear layer weights are ±1, but each matrix has one high-precision scale, the mean absolute value β. In addition, components such as the input and output embeddings and LayerNorm stay at high precision, and activations are 8 bits. During training, high-precision weights are also kept to accumulate updates.