Search

Search papers and lessons

The Era of 1-bit LLMs: All Large Language Models are in 1.58 Bits

Shuming Ma, Hongyu Wang, Lingxiao Ma et al. · 2024

BitNet b1.58 trains a language model whose weights are each -1, 0 or +1; the paper reports it matches a full-precision model from 3B parameters up, with less memory and faster inference.

On this page

  • Colour = topic mix
  • Discrete math
  • Calculus
  • Linear algebra
  • Neural network basics
  • Efficiency
  • Probability
  • ReadReady to readNot yet

TL;DR

Language models store their knowledge in weight matrices, and each weight is usually a 16-bit floating-point number. BitNet b1.58 trains a model in which every weight is one of three values: -1, 0 or +1. That takes about 1.58 bits per weight, and it turns most of the matrix multiplication into additions. The paper reports that from 3B parameters up, the model matches a full-precision (FP16) LLaMA-style model of the same size and training tokens on perplexity and on a set of zero-shot tasks, while using less memory, less time and less energy.

Builds on: Quantization, Straight-Through Estimator · Leads to: none yet in this graph

Why it mattered

The paper argues that 1-bit and ternary weights are a new scaling recipe, not only a way to compress a trained model. The common route to low-bit models is Post-Training Quantization: take a finished model and round its weights, which loses some quality. BitNet b1.58 is trained from scratch with ternary weights, so the model learns to work with them. The authors also say the arithmetic it needs suggests new hardware, and they call for it. Their claim is that a 13B BitNet b1.58 is more efficient than a 3B FP16 model, a 30B BitNet b1.58 is more efficient than a 7B FP16 model, and a 70B BitNet b1.58 is more efficient than a 13B FP16 model, in latency, memory and energy. These are the paper's claims, measured under its own setup.

The problem

A large model is slow to run for two reasons. The arithmetic is expensive: most of a language model's work is Matrix Multiplication, and floating-point multiplication costs much more energy than integer addition. The data movement is also expensive: each weight has to be moved from main memory (DRAM) into the fast on-chip memory (SRAM) before it is used, and 16-bit weights are large to move.

[[Post-training quantization]] shrinks weights after training, for example from 16 bits to 4-bit variants, but the paper calls it sub-optimal. A plausible reason is that the model was never trained for the coarse weights, so quality falls. The question is whether a model can be trained directly with very few bits per weight and still match a full-precision model of the same size.

How it works

Take one tiny linear layer with a 2 by 2 weight matrix, and follow one forward pass through it.

  1. Start with full-precision weights. During training the layer keeps a matrix WW of ordinary floating-point numbers. Check: the layer holds four real numbers, one per entry.
  2. Measure the scale. Compute the average absolute value of all the entries. Call it γ\gamma. This is the absmean scale. Check: γ\gamma is a single positive number for the whole matrix.
  3. Round to ternary. Divide each entry by γ\gamma, round to the nearest integer, and clip the result to -1, 0 or +1. Check: every weight in the forward pass is now -1, 0 or +1.
  4. Quantize the activations. The input vector is scaled per token into the range [−Qb,Qb][-Q_b, Q_b] and rounded to integers, where QbQ_b is the bound that the activation bit width sets. The paper uses 8-bit activations. Check: the inputs are integers as well.
  5. Multiply without multiplying. Each output is a sum of input values, each added with a plus sign, subtracted, or skipped. Check: no entry is multiplied by a number other than -1, 0 or 1, so the layer needs only integer addition.
  6. Repeat in every layer. The paper replaces the linear layers of a LLaMA-style Transformer with this BitLinear layer and keeps the rest of the architecture, including the RMS Normalization layers and the full-precision embedding. Check: only the linear layers change; the rest of the model is as described in Section 2 of the paper.
flowchart LR
  W[Full-precision W] --> G[Average absolute value gamma]
  G --> R[Divide by gamma, round, clip to -1 0 1]
  X[Input x] --> Q[Scale to 8-bit integers]
  R --> M[Ternary matrix times integers]
  Q --> M
  M --> Y[Output: additions only]

Worked examples

Example
1. Tiny: absmean on a 2 by 2 matrix

Take W=(0.5−1.50.20)W = \begin{pmatrix} 0.5 & -1.5 \\ 0.2 & 0 \end{pmatrix}. Find the ternary version W~\widetilde{W}.

  1. Average absolute value: γ=(0.5+1.5+0.2+0)/4=2.2/4=0.55\gamma = (0.5 + 1.5 + 0.2 + 0)/4 = 2.2/4 = 0.55.
  2. Divide each entry by 0.55: 0.5/0.55=0.9090.5/0.55 = 0.909, −1.5/0.55=−2.727-1.5/0.55 = -2.727, 0.2/0.55=0.3640.2/0.55 = 0.364, 0/0.55=00/0.55 = 0.
  3. Round to the nearest integer: 11, −3-3, 00, 00.
  4. Clip to the range [−1,1][-1, 1]: −3-3 becomes −1-1.

Result: W~=(1−100)\widetilde{W} = \begin{pmatrix} 1 & -1 \\ 0 & 0 \end{pmatrix}. Every entry is -1, 0 or 1.

Example
2. Standard: where the speed comes from (Table 1)

Table 1 compares a 3B LLaMA model in FP16 with a 3B BitNet b1.58 model. The latency for the LLaMA model is 5.07 ms and for BitNet b1.58 is 1.87 ms. Memory is 7.89 GB for LLaMA and 2.22 GB for BitNet b1.58.

  1. Latency ratio: 5.07/1.87=2.715.07 / 1.87 = 2.71. The table reports 2.71x.
  2. Memory ratio: 7.89/2.22=3.557.89 / 2.22 = 3.55. The table reports 3.55x.
  3. Perplexity: 10.04 for LLaMA and 9.91 for BitNet b1.58, so the BitNet model is slightly lower (better) on this measure.

The memory ratio is smaller than the bit ratio, 16/1.58=10.116 / 1.58 = 10.1, because the embedding layer stays at full precision and is a larger share of the total for small models (Section 3, Memory and Latency).

Example
3. Realistic: batch size and throughput (Table 3)

Table 3 compares 70B models on two 80GB A100 cards with sequence length 512. LLaMA reaches a maximum batch size of 16 and a throughput of 333 tokens per second. BitNet b1.58 reaches a batch size of 176 and a throughput of 2977 tokens per second.

  1. Batch size ratio: 176/16=11.0176 / 16 = 11.0, matching the table.
  2. Throughput ratio: 2977/333=8.942977 / 333 = 8.94, which the table rounds to 8.9x.
  3. Interpretation: the BitNet model fits about 11 times as many sequences in memory at once, and the extra parallel work gives about 8.9 times the tokens per second.

Try it: Table 4 reports an average of 74.34 for BitNet b1.58 3B trained on 2T tokens, and 73.22 for StableLM-3B. How many percentage points higher is the BitNet average? Answer: 74.34−73.22=1.1274.34 - 73.22 = 1.12 points.

The math

Let WW be a real-valued weight matrix with n×mn \times m entries WijW_{ij}. The paper quantizes it to a ternary matrix W~\widetilde{W} whose entries are in {−1,0,+1}\{-1, 0, +1\}.

Definition: Ternary weight

A weight that takes one of three values, -1, 0 or +1. Its information content is log⁡23≈1.585\log_2 3 \approx 1.585 bits, which is the "1.58 bits" in the name.

Step 2 in symbols: the absmean scale

The scale is the mean of the absolute values:

γ=1nm∑i,j∣Wij∣\gamma = \frac{1}{nm} \sum_{i,j} |W_{ij}|

Step 3 in symbols: round and clip

Each weight is divided by γ\gamma (with a small ϵ\epsilon to avoid division by zero), rounded to the nearest integer, and clipped to the range from -1 to 1:

W~=RoundClip(Wγ+ϵ, −1, 1),RoundClip(x,a,b)=max⁡(a, min⁡(b, round(x)))\widetilde{W} = \text{RoundClip}\left(\frac{W}{\gamma + \epsilon},\ -1,\ 1\right), \qquad \text{RoundClip}(x, a, b) = \max\left(a,\ \min\left(b,\ \text{round}(x)\right)\right)

Since the rounded values are at most ±1\pm 1 after clipping, every entry is -1, 0 or +1.

Step 5 in symbols: the layer output

For a ternary matrix W~\widetilde{W} and an input vector xx, each output is

yi=∑jW~ij xjy_i = \sum_j \widetilde{W}_{ij}\, x_j

Because each W~ij\widetilde{W}_{ij} is -1, 0 or +1, each term is either xjx_j, −xj-x_j or 00. The product therefore needs only additions and subtractions, which is the basis of the energy estimate in the paper.

Why the cost falls

The paper uses a model of arithmetic energy at a 7nm process and estimates that BitNet b1.58 saves about 71.4 times the arithmetic energy for matrix multiplication (Section 3, Energy). This is an estimate from an energy model, not a measurement of a chip.

Results

Perplexity and end tasks. Table 1 shows Perplexity for LLaMA and BitNet b1.58 at four sizes: 700M, 1.3B, 3B and 3.9B. At 700M, BitNet is higher (12.87 against 12.33). At 1.3B it is 11.29 against 11.25. At 3B it is 9.91 against 10.04, so it becomes lower. The 3.9B BitNet model reaches 9.62. The table column is labelled PPL, and the text says the validation perplexity is measured on WikiText2 and C4.

Table 2 gives Zero-Shot Learning accuracy averaged over seven tasks. At 700M the averages are 45.5 for LLaMA and 44.3 for BitNet. At 1.3B they are 46.2 and 45.4. At 3B they are 49.7 for LLaMA and 50.2 for BitNet, the first size where the BitNet average is higher. The 3.9B BitNet model averages 51.2.

Cost. Table 1 gives memory and latency for 700M, 1.3B, 3B and 3.9B models. The text says the latency speedup grows with size and that BitNet b1.58 70B is 4.1 times faster than the LLaMA baseline (Figure 2). The 70B throughput gain is in Table 3.

Training with more tokens. Table 4 compares a BitNet b1.58 3B trained on 2T tokens with StableLM-3B, using five tasks. BitNet averages 74.34 against 73.22. The StableLM numbers are taken from its technical report.

Limits. Training used 100B tokens of RedPajama for the main comparison, and the LLaMA baselines were reproduced by the authors. Memory and latency use a 2-bit kernel from the Ladder work, so the authors note there is room to optimise further. Energy is an estimate from an energy model. The 70B latency is read from a figure, not a table. The end-task comparison in Table 2 covers seven tasks, and the 2T-token comparison in Table 4 covers a different set of five, so the two averages cannot be compared directly.

Reading guide

  • Section 1 (The era of 1-bit LLMs): why post-training quantization is limited and why matrix multiplication dominates the cost. Needs Quantization and Post-Training Quantization.
  • Section 2 (BitNet b1.58): the absmean quantizer, the activation quantizer, and the LLaMA-style components. Needs Matrix Multiplication, RMS Normalization and Rotary Position Embedding. The paper says it uses SwiGLU, RMSNorm and rotary embeddings, and removes all biases.
  • Section 3 (Results): Tables 1 to 4 and the energy and throughput figures. Needs Perplexity and Zero-Shot Learning.
  • Section 4 (Discussion): mixture-of-experts, long context and edge devices. Needs Mixture of Experts and KV Cache. The paper says that moving activations from 16 bits to 8 bits lets the context length double given the same resources.
  • Training method: the paper says the model is trained from scratch with ternary weights, but the text does not spell out the gradient method. The lesson on Straight-Through Estimator explains the usual way gradients pass through a rounding step.

Check yourself

QuestionHow many values can each BitNet b1.58 weight take, and why is the number of bits described as 1.58?Show answer

Each weight takes one of three values, -1, 0 or +1. The information in one such value is log⁡23≈1.585\log_2 3 \approx 1.585 bits.

QuestionA 2 by 2 weight matrix has entries 0.8, -0.2, 0.6 and -1.4. Find the ternary version using absmean.Show answer

Average absolute value: (0.8+0.2+0.6+1.4)/4=3.0/4=0.75(0.8 + 0.2 + 0.6 + 1.4)/4 = 3.0/4 = 0.75. Divide and round: 0.8/0.75=1.07→10.8/0.75 = 1.07 \to 1, −0.2/0.75=−0.27→0-0.2/0.75 = -0.27 \to 0, 0.6/0.75=0.8→10.6/0.75 = 0.8 \to 1, −1.4/0.75=−1.87→−2→−1-1.4/0.75 = -1.87 \to -2 \to -1 after clipping. The answer is (101−1)\begin{pmatrix} 1 & 0 \\ 1 & -1 \end{pmatrix}.

QuestionWhy does a ternary weight make the matrix product cheap, and what does the layer still need?Show answer

Each weight multiplies an input by -1, 0 or +1. The product is then the input, its negative, or zero, so the layer needs only additions and subtractions. The inputs are still quantized to integers, and the normalisation and other parts of the model use normal arithmetic.

QuestionIn Table 1, the 3B BitNet model uses 3.55 times less memory, but 16/1.58≈10.116 / 1.58 \approx 10.1. Why is the memory gain so much smaller than the bit ratio?Show answer

The embedding layer stays at full precision, and its share of the total memory is larger for small models. The paper says the embedding's memory proportion is smaller for larger models. The table ratios for the four BitNet sizes (2.60x to 3.55x against LLaMA) all stay below 10.1, so the memory gain is well short of the bit ratio at every size shown.

Sources

Read the full paper

Shuming Ma, Hongyu Wang, Lingxiao Ma et al., 2024. arXiv:2402.17764