AI Logic

Model Compression

BitNet b1.58

Updated:

How BitNet b1.58 works. The left side shows the computation of a linear layer (BitLinear): normalize the input, quantize it to 8 bits per token, compute the matrix product with ternary weights, and rescale. The top right shows a weight matrix divided by its mean absolute value γ and rounded to −1, 0, or +1; the bottom right shows that multiplying one row of ternary weights by the input becomes additions and subtractions such as x0 − x1 + x3

Background and Overview

BitNet b1.58 is a method that trains a large language model from scratch with the weights of all linear layers restricted to the three values −1, 0, and +1. It was proposed in 2024 by Ma, Wang, and colleagues at Microsoft Research and elsewhere in the paper "The Era of 1-bit LLMs" (published on arXiv).

It builds on BitNet (Wang et al., 2023) from the same group. BitNet binarized weights to +1 and −1, turning matrix multiplication into almost nothing but additions. However, an accuracy gap remained compared with 16-bit models. BitNet b1.58 narrowed this gap by adding 0 to the set of weight values, making them ternary. Representing three values requires log⁡23≈1.58\log_2 3 \approx 1.58 bits of information, hence the name "b1.58."

The paper's main results are as follows.

  • From 3B parameters upward, it matched the accuracy of 16-bit LLaMA-style models. When trained on the same data (100 billion tokens of RedPajama), the 3B model's perplexity and zero-shot accuracy were on par with or slightly better than those of the 16-bit model.
  • Inference speed and memory improved substantially. At 3B, GPU memory dropped to 1/3.55 and per-token generation latency to 1/2.71.

As an everyday analogy for what adding 0 means, it is like adding "abstain" to a vote that previously had only "for" and "against." Because the model can choose "abstain (0)" for irrelevant inputs, it can select and sum only the features it needs.

Theory (Ternary Weights)

BitNet b1.58 has the same structure as BitNet: it replaces the linear layers (nn.Linear) of a Transformer with BitLinear. Weights are 1.58-bit, activations are 8-bit, and the model is trained from scratch. It differs from BitNet in three ways (Section 2 of the paper).

1. Ternarize weights with absmean

The weight matrix W∈Rn×mW \in \mathbb{R}^{n \times m} is divided by its mean absolute value γ\gamma and then rounded to the nearest integer among −1, 0, and +1 (Eqs. (1)–(3)).

W~=RoundClip ⁣(Wγ+ϵ, −1, 1),γ=1nm∑ij∣Wij∣\widetilde{W} = \mathrm{RoundClip}\!\left(\frac{W}{\gamma + \epsilon},\ -1,\ 1\right), \qquad \gamma = \frac{1}{nm} \sum_{ij} \lvert W_{ij} \rvert RoundClip(x,a,b)=max⁡(a,min⁡(b,round(x)))\mathrm{RoundClip}(x, a, b) = \max(a, \min(b, \mathrm{round}(x)))

As a procedure, this is:

  1. Compute the mean absolute value γ\gamma over the entire weight matrix.
  2. Divide every weight by γ\gamma. Weights of average size end up around ±1.
  3. Round to the nearest integer. Weights whose absolute value is less than half of γ\gamma become 0.
  4. Clamp values below −1 to −1 and values above +1 to +1.

Unlike BitNet's binarization (subtract the mean and take the sign), the value 0 is available, so small weights become 0 and drop out of the computation (right side of the figure at the top).

2. Quantize all activations symmetrically per token

Activation quantization uses the same absmax (divide by the maximum absolute value) as BitNet, but whereas BitNet scaled only the activations before nonlinear functions into [0,Qb][0, Q_b], b1.58 drops that and scales all activations per token into [−Qb,Qb][-Q_b, Q_b]. This removes the need for a zero point (the offset that determines which integer 0 maps to), which simplifies implementation and system-level optimization. The paper states that the effect on performance was negligible.

3. Use LLaMA-style components

To align with LLaMA, the de facto standard for open models, it uses RMSNorm, SwiGLU, and rotary position embeddings (RoPE), and removes all biases. This makes it easy to integrate into existing software such as Hugging Face, vLLM, and llama.cpp.

With weights of −1, 0, and +1, matrix multiplication can be computed by just "add the input, do nothing, or subtract it" (bottom right of the figure at the top). As in BitNet, multiplications are almost unnecessary, and according to the paper, the arithmetic energy is the same as the original BitNet.

Why It Achieves Both Accuracy and Efficiency

The paper explains the advantages of BitNet b1.58 as follows.

  • 0 enables feature selection. With binary weights, every input must be either added or subtracted. When 0 is available, an input can be excluded from the computation, so the model can explicitly choose which features to use. The paper states that this substantially improves the performance of 1-bit large language models.
  • Less data is read from memory. In large language model inference, the time and energy spent moving weights from memory (DRAM) to the memory near the compute units (SRAM) is a major burden. Going from 16-bit to about 1.58-bit weights greatly reduces the amount moved.
  • Computation becomes almost entirely integer addition. Matrix multiplication in a 16-bit model consists of floating-point multiplications and additions. In BitNet b1.58, most of it becomes 8-bit integer addition.

The benefit grows with model size because the share of total computation taken by linear layers rises as models get larger. For memory as well, the share taken by the embeddings, which are kept at high precision, shrinks in larger models.

The paper also states that moving activations from 16 bits to 8 bits doubles the context length that can be handled with the same resources, in terms of the KV cache memory that becomes a problem for long contexts.

Experimental Results

The paper compares a 16-bit LLaMA-style model reproduced by the authors (hereafter LLaMA) with BitNet b1.58, both trained on the same 100 billion tokens of RedPajama. Memory and generation latency are measured with FasterTransformer, which is optimized for GPUs, with a 2-bit computational kernel (Ladder) integrated.

Accuracy and cost

The table shows perplexity (PPL; lower is better), GPU memory, and per-token generation latency (Table 1; the values in parentheses show the reduction factor relative to LLaMA). Average zero-shot accuracy (higher is better) is the mean over seven tasks: ARC-Easy, ARC-Challenge, HellaSwag, BoolQ, OpenbookQA, PIQA, and Winogrande (Table 2).

ModelSizeMemory (GB)Latency (ms)PPLAvg. accuracy
LLaMA700M2.081.1812.3345.5
BitNet b1.58700M0.80 (2.60×)0.96 (1.23×)12.8744.3
LLaMA1.3B3.341.6211.2546.2
BitNet b1.581.3B1.14 (2.93×)0.97 (1.67×)11.2945.4
LLaMA3B7.895.0710.0449.7
BitNet b1.583B2.22 (3.55×)1.87 (2.71×)9.9150.2
BitNet b1.583.9B2.38 (3.32×)2.11 (2.40×)9.6251.2

The results show the following.

  • Small models fall slightly short of 16 bits. At 700M and 1.3B, both perplexity and accuracy were somewhat worse than LLaMA.
  • From 3B, it was on par with 16 bits. At 3B, perplexity was 9.91 (LLaMA: 10.04) and average accuracy was 50.2 (LLaMA: 49.7).
  • The 3.9B BitNet b1.58 was both lighter and more accurate than the 3B LLaMA. Memory was 1/3.32 and latency 1/2.40, with higher accuracy.

Speed, memory, and energy for larger models

The benefits grew as the models got larger (Figures 2 and 3).

SizeLatency speedupMemory reductionTotal energy reduction
1.3B1.67×2.93×18.6×
3B2.71×3.55×21.7×
7B2.90×4.40×29.1×
13B3.68×5.12×32.9×
70B4.10×7.16×41.2×

Energy is estimated from a table of per-operation energy costs (7nm, 512 tokens). Looking only at matrix multiplication arithmetic, LLaMA uses 16-bit multiplications and additions, whereas BitNet b1.58 mainly uses 8-bit integer additions, and its energy was estimated at 1/71.4.

In an experiment that placed a 70B model on two 80GB A100s with pipeline parallelism and increased the batch until memory ran out, the maximum batch size went from 16 to 176 (11×) and generation throughput from 333 to 2977 tokens/s (8.9×) (Table 3).

Training on more tokens

When the 3B BitNet b1.58 was trained with the same data recipe as StableLM-3B, which was trained on 2 trillion tokens, its average accuracy over five tasks (Winogrande, PIQA, SciQ, LAMBADA, ARC-Easy) was 74.34, surpassing StableLM-3B's 73.22 (Table 4).

Practical Considerations

  • It must be trained from scratch. BitNet b1.58 is not a method for ternarizing a trained 16-bit model after the fact. All of the paper's models were trained from scratch.
  • The paper is a short report and does not give detailed training settings. For settings such as the learning rate and the handling of backpropagation (e.g., the straight-through estimator), refer to the BitNet paper.
  • Speed and memory depend on the computational kernels. The paper's figures were measured with a 2-bit kernel, not with weights packed at exactly 1.58 bits. The paper also notes there is still room for optimization. In environments without a suitable kernel, ternary weights are computed in floating point and nothing gets faster.
  • The 16-bit baseline was reproduced by the authors. Note that the results are not a comparison against the publicly released LLaMA weights.

Accuracy comparable to 16-bit models was reached only from 3B upward. At 700M and 1.3B, both perplexity and accuracy were slightly below the 16-bit model. When using it for small models, check the accuracy gap before choosing it.

Comparison with Other Methods

The table compares methods that make weights binary or ternary with ordinary low-bit quantization along the same dimensions.

MethodWeight valuesWeight scaleActivationsMain target
BinaryConnect+1, −1NoneReal-valuedSmall image recognition (MLP, CNN)
XNOR-Net (binary weights only)+1, −1Mean ∣W∣\lvert W \rvert per filterReal-valuedImageNet CNNs
XNOR-Net+1, −1Mean ∣W∣\lvert W \rvert per filter+1, −1 (with per-position scales)ImageNet CNNs
BitNet+1, −1 (sign after subtracting the mean)Mean ∣W∣\lvert W \rvert per matrix8-bitLarge language models
BitNet b1.58−1, 0, +1Mean ∣W∣\lvert W \rvert per matrix8-bitLarge language models
GPTQ3–4-bit integersPer row / per group16-bitPretrained large language models

The next table compares the two methods from the same group in more detail.

AspectBitNet (2023)BitNet b1.58 (2024)
Weight values+1, −1−1, 0, +1
How weights are formedSubtract the mean α\alpha and take the signDivide by the mean absolute value γ\gamma and round
Activations before nonlinear functionsSubtract the minimum, map to [0,Qb][0, Q_b]Same as the others, [−Qb,Qb][-Q_b, Q_b]
Other componentsStandard Transformer (SubLN)LLaMA-style (RMSNorm, SwiGLU, RoPE, no bias)
Gap to 16-bit modelsPerplexity 1.9 higher at 6.7BOn par from 3B upward
  • To train a large language model in low bit width from scratch, the current published results make BitNet b1.58, with its small gap to 16 bits, a strong option.
  • To slim down a 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 BitLinear158(nn.Linear):
    """BitNet b1.58 linear layer: weights in {-1, 0, +1} (absmean, Eqs. (1)-(3)), activations in 8 bits (per-token absmax).
    Normalization and dequantization follow BitNet's BitLinear. 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)       # no bias (LLaMA-style)
        self.norm = nn.RMSNorm(in_features, elementwise_affine=False) # PyTorch 2.4 or later
        self.Qb = 2 ** (bits - 1)
        self.eps = eps

    def quant_weight(self):
        w = self.weight
        gamma = w.abs().mean()                                         # Eq. (3): mean absolute value
        w_t = torch.clamp(torch.round(w / (gamma + self.eps)), -1, 1)  # Eqs. (1)(2): RoundClip
        w_t = w + (w_t * gamma - w).detach()                           # STE (compute with the rescaled values)
        return w_t

    def quant_act(self, x):
        s = self.Qb / x.abs().amax(dim=-1, keepdim=True).clamp(min=self.eps)   # per token
        x_q = torch.clamp(torch.round(x * s), -self.Qb, self.Qb - 1)           # fit into 8-bit integers (upper bound Q_b - 1)
        x_q = x + (x_q / s - x).detach()                               # STE (compute with the dequantized values)
        return x_q

    def forward(self, x):
        return F.linear(self.quant_act(self.norm(x)), self.quant_weight())


layer = BitLinear158(512, 512)
with torch.no_grad():
    w = layer.weight
    w_t = torch.clamp(torch.round(w / w.abs().mean()), -1, 1)
    print("distinct values:", torch.unique(w_t).tolist())                       # [-1.0, 0.0, 1.0]
    print("fraction of 0:", (w_t == 0).float().mean().item())

x = torch.randn(4, 16, 512)
layer.train()
layer(x).pow(2).mean().backward()   # gradients flow to the high-precision weights (inference computes the same way)
print(layer.weight.grad.shape)

FAQ

Q. Why "1.58 bits"?
A.

Because each weight takes one of three values, −1, 0, or +1, so the information carried by one weight is log⁡23≈1.58\log_2 3 \approx 1.58 bits. Note, however, that the paper's memory and speed measurements used a 2-bit computational kernel, and the actual storage format depends on the implementation.

Q. Should I use BitNet or BitNet b1.58?
A.

They are methods from separate papers, and BitNet b1.58 is the successor. BitNet (2023) uses ±1 weights, and a gap to 16-bit models remained even at 6.7B. BitNet b1.58 (2024) uses ternary weights with 0 added and reports accuracy on par with 16-bit LLaMA-style models from 3B upward. The paper states that the arithmetic energy is the same, so for new training the BitNet b1.58 approach is the stronger choice.

Q. Can a trained LLaMA be converted to BitNet b1.58?
A.

The paper's method trains with ternary weights from scratch. All of the paper's models were trained from scratch, and no method for converting a trained 16-bit model is presented. To slim down a trained model, post-training quantization such as GPTQ or AWQ is a better fit.

References

  1. S. Ma, H. Wang, L. Ma, L. Wang, W. Wang, S. Huang, L. Dong, R. Wang, J. Xue, and F. Wei, "The Era of 1-bit LLMs: All Large Language Models are in 1.58 Bits," arXiv:2402.17764, 2024.
  2. H. Wang, S. Ma, L. Dong, S. Huang, H. Wang, L. Ma, F. Yang, R. Wang, Y. Wu, and F. Wei, "BitNet: Scaling 1-bit Transformers for Large Language Models," arXiv:2310.11453, 2023.
  3. PyTorch Documentation, "RMSNorm."