Search

Search papers and lessons

BitNet: Scaling 1-bit Transformers for Large Language Models

Hongyu Wang, Shuming Ma, Li Dong et al. · 2023

BitNet trains large language models whose weights are one bit each, by swapping the linear layers for BitLinear, and reports competitive accuracy with far less memory and energy than 8-bit quantized baselines.

On this page

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

TL;DR

BitNet is a language-model architecture in which every big weight matrix holds only +1 or -1. It trains such models from scratch by replacing each linear layer with BitLinear, and it keeps the other parts at higher precision. On its benchmarks the 1-bit models come close to 16-bit Transformers in perplexity and zero-shot accuracy, while the paper's energy estimates for their matrix multiplications are far lower than those of the 32-bit baseline.

Builds on: Quantization, Quantization-Aware Training, Straight-Through Estimator, Transformer · Leads to: BitLinear, and the later ternary language models that followed the same recipe

Why it mattered

The paper gave a clear demonstration that a large language model can be trained with 1-bit weights and reach accuracy near that of a full-precision model. Before it, most work on quantizing language models was post-training, which rounds a finished model. The paper reports that absmax and SmoothQuant rounding of a finished model collapse at 4 bits and below, while training with the rounding in the loop does not.

It also introduced a way to measure cost that counts the energy of arithmetic, not the number of floating-point operations. That view shaped how later low-bit work reports results. The layer it defines, BitLinear, is small enough to drop into existing Transformer code, which is why it has been reused in later models.

The problem

Large language models are expensive to serve. The paper states that the memory bandwidth needed to read the parameters is often the bottleneck during inference, and that when a model is spread over several devices, the communication between them adds delay and energy use. Quantization reduces both by storing numbers with fewer bits.

Two strands existed. Post-training quantization takes a trained model and rounds its weights and activations. It is simple, but at low bit widths the model was never optimized for the rounded values, so accuracy falls. Quantization-aware training keeps the training loop and includes the rounding, so the model adapts to it. It usually gives better accuracy, but it was unclear whether it would hold up at the sizes that large language models reach, and whether its scaling behaviour matched that of ordinary full-precision models. Binarized networks had been studied for images and for translation or BERT pretraining, not for decoder-only language models.

The paper asks whether the training-time approach can work at 1 bit for language models, and whether it keeps the scaling behaviour that predicts how loss falls with model size, as described in Neural Scaling Laws.

How it works

Follow one forward pass through the model, as the paper defines it. The walkthrough uses the paper's notation.

  1. Keep the architecture. BitNet stacks blocks of self-attention and feedforward networks, as a standard Transformer does. Each matrix multiplication in those blocks is done by a BitLinear layer. The residual connections, the layer normalization, the input and output embeddings, and the softmax-based sampling stay at higher precision. The paper gives three reasons: the residual and normalization costs are small, the QKV transformation is much cheaper than the parametric projections as the model grows, and sampling needs accurate probabilities.
  2. Binarize the weights. For a weight matrix WW, subtract its mean α\alpha, then keep the sign. Each entry becomes +1+1 or −1-1. Centring makes the signs split the weights more evenly within the limited range of the binary values.
  3. Keep one scale for the weights. Compute β\beta, the mean absolute value of WW. It restores the size of the weights after the multiplication, and it is chosen to reduce the ℓ2\ell_2 error between the real weights and the binary ones.
  4. Normalize the activations. Apply layer normalization to the input of the layer. This keeps the output variance near 1, which the paper needs because binarization changes the variance of the output.
  5. Quantize the activations to 8 bits. Use absmax: divide by the largest absolute value γ\gamma, multiply by Qb=128Q_b = 128, and clip. The paper uses 8 bits for activations in all its experiments.
  6. Multiply and rescale. The product of the binary weights and the 8-bit activations is a sum of signed integers. Multiply it by βγ/Qb\beta\gamma/Q_b once, to return to the original scale.
  7. Train with the rounding in place. Keep a full-precision latent weight for each binary weight. Binarize it on the fly in the forward pass, pass gradients through the sign and clip steps with the Straight-Through Estimator, and update the latent weight with a high-precision optimizer. The latent weights are never used at inference.
  8. Use a large learning rate. The paper finds that small updates to the latent weights often change no binary weight, which biases the gradient, and that a larger learning rate is the simplest fix. The FP16 Transformer diverges at the learning rate that BitNet tolerates.

A small diagram of the layer:

flowchart LR
  W["Latent weights W (high precision)"] --> B["Sign of W minus its mean: W~ in {-1, +1}"]
  X["Activations x"] --> LN["Layer norm"] --> Q["8-bit absmax"]
  B --> M["Binary matmul: additions"]
  Q --> M
  M --> R["Rescale by beta gamma / Q_b"]
  R --> Y["Output"]
  W -. "updated by gradients through the STE" .-> W

The math

The layer and its training follow the paper's equations exactly. The layer output is y=W~ Quant(LN(x))⋅βγQb,y = \widetilde{W}\,\mathrm{Quant}(\mathrm{LN}(x)) \cdot \frac{\beta\gamma}{Q_b}, with the binarized weights W~=Sign⁡(W−α)\widetilde{W} = \operatorname{Sign}(W - \alpha), the weight scale β=1nm∥W∥1\beta = \frac{1}{nm}\lVert W\rVert_1, the mean α=1nm∑ijWij\alpha = \frac{1}{nm}\sum_{ij} W_{ij}, and the absmax activation quantization of BitLinear. The symbols nn and mm are the numbers of rows and columns of WW, and ∥⋅∥1\lVert \cdot \rVert_1 is the sum of the absolute values.

Why the variance is kept at 1

The paper estimates the variance of one output as Var(y)≈n β2 E[x~2]\mathrm{Var}(y) \approx n\,\beta^2\,E[\widetilde{x}^2] under the assumption that the weights and inputs are independent with equal distributions. The paper then simplifies this to approximately E[x~2]E[\widetilde{x}^2]. The layer normalization before the quantization sets E[LN(x~)2]=1E[\mathrm{LN}(\widetilde{x})^2] = 1, which matches the full-precision variance at standard initialization. This is the reason for the normalization in the walkthrough.

Group quantization for model parallelism

When a weight matrix is split over GG devices, each part computes its own statistics: αg=Gnm∑ijWij(g),βg=Gnm∥W(g)∥1,\alpha_g = \frac{G}{nm}\sum_{ij} W^{(g)}_{ij}, \qquad \beta_g = \frac{G}{nm}\lVert W^{(g)}\rVert_1, and for the activations γg=∥x(g)∥∞\gamma_g = \lVert x^{(g)}\rVert_\infty and ηg=min⁡ijxij(g)\eta_g = \min_{ij} x^{(g)}_{ij}, with normalization computed over each group. Because no statistic needs values from other devices, the paper says no extra communication is needed.

Energy of the operations

For matrices of sizes m×nm \times n and n×pn \times p, a full-precision product costs Eadd=m(n−1)p E^addE_{add} = m(n-1)p\,\hat{E}_{add} additions and Emul=mnp E^mulE_{mul} = mnp\,\hat{E}_{mul} multiplications. For BitNet, the paper counts the multiplications only for the scaling, Emul=(mp+mn) E^mulE_{mul} = (mp + mn)\,\hat{E}_{mul}, and most of the cost is the additions. Table 2 lists the per-operation energies in picojoules at 7 nm: an FP32 addition takes 0.38, an FP32 multiplication 1.31, and an INT8 addition 0.007. Energy per operation is the quantity the paper's comparisons use.

Results

The main results are for the model sizes the paper trained, from 125 million to 30 billion parameters.

Energy (Table 1). For the 6.7-billion-parameter model at a 512-token input, the paper reports 4.41 joules for the multiplications of a 32-bit Transformer and 0.02 joules for BitNet, at 7 nm. For the 30-billion model the figures are 20.09 and 0.06. The additions are also smaller for BitNet, at 0.04 and 0.14 joules respectively against 1.28 and 5.83 for the 32-bit Transformer. The paper's conclusion is that the saving is largest for multiplications.

Comparison with 16-bit Transformers. The paper states that the loss of BitNet falls with model size similarly to the FP16 Transformer, and that the gap between the two shrinks as models grow. It fits L(N)=aNb+cL(N) = aN^b + c on models from 125 million to 6.7 billion parameters and predicts the loss of the 13-billion and 30-billion models accurately. It also introduces an inference-optimal scaling curve, plotting loss against inference energy rather than training FLOPs. On that curve, the paper reports that BitNet has much higher scaling efficiency than the FP16 Transformer.

Downstream tasks. The paper evaluates zero-shot and four-shot accuracy on Hellaswag, Winogrande, Winograd and Storycloze, and reports that the capability scaling of BitNet is more efficient than the FP16 baseline's, in terms of inference cost.

Stability. With the same peak learning rate, BitNet converges and the FP16 Transformer does not. The paper then trains BitNet with larger learning rates and reports better convergence in perplexity as the learning rate increases.

Against post-training quantization (Table 3). At 6.7 billion parameters on the four tasks, the 16-bit Transformer has a perplexity of 15.19 and a zero-shot average of 57.8. The 8-bit baselines are SmoothQuant at 15.67 and 56.7, and absmax at 21.43 and 53.4. At 4 bits, GPTQ reaches 16.05 and 52.9, while absmax reaches 4.8×1044.8 \times 10^4 perplexity. At 1 bit, absmax and SmoothQuant reach perplexities of 3.5×10233.5 \times 10^{23} and 3.3×10213.3 \times 10^{21} with averages of 44.6 and 44.4, close to the 43.8 of random guessing. BitNet reaches a perplexity of 17.07 and an average of 55.9. BitNet's average of 55.9 is above the 8-bit Absmax (53.4) and the 4-bit GPTQ (52.9), but below the 8-bit SmoothQuant (56.7) and the 16-bit Transformer (57.8). Its perplexity of 17.07 is also above the 15.67 of 8-bit SmoothQuant.

Ablations (Table 4). Holding the model fixed, the paper compares activation quantizers and normalization placements. Its BitNet (absmax with SubLN) has a zero-shot average of 52.3 and a perplexity of 20.34. Elastic activations with Pre-LN give 50.2 and 24.05, absmax with Pre-LN gives 51.3 and 22.11, and absmax with the BMT architecture gives 51.6 and 22.98. The paper concludes that absmax is more stable than the elastic function and that SubLN is more stable than the alternatives.

Limits. The paper reports results for 1-bit weights with 8-bit activations only. Lower activation precision is left to future work. The scaling experiments go to 30 billion parameters, not to the sizes of current frontier models. The energy numbers come from a model of arithmetic energy, not from measured hardware. The 1-bit model is also still worse in perplexity than the 16-bit baseline at the same size, and the paper's accuracy claims rest on four downstream tasks.

Reading guide

Read the paper in this order, with the lessons that cover each section's ideas.

Check yourself

QuestionRecall: what is the difference between post-training quantization and quantization-aware training?Show answer

Post-training quantization rounds a finished model without changing its training. Quantization-aware training keeps the training loop with the rounding included, so the model learns weights that work after rounding. The paper argues the second is needed at low bit widths.

QuestionIn the paper's energy model, an FP32 multiplication costs 1.31 pJ and an FP32 addition costs 0.38 pJ at 7 nm. How many times as much energy does one multiplication cost as one addition?Show answer

1.31/0.38≈3.451.31 / 0.38 \approx 3.45. So one FP32 multiplication costs about 3.4 times one FP32 addition, which is why replacing multiplications matters for energy.

QuestionWhy does BitNet take the mean of the weights, subtract it, and only then keep the sign?Show answer

Centring moves the weights so that their mean is zero. The signs then split the weights more evenly between +1 and -1, which the paper says increases the capacity of the layer within the limited range of binary values. Without centring, a weight matrix whose entries were all positive would be binarized to all +1, and the layer could not tell its weights apart.

QuestionA 1-bit model has a perplexity of 17.07 and the 16-bit Transformer has 15.19. Compute the ratio of the two perplexities, and say what it means.Show answer

17.07/15.19≈1.12417.07 / 15.19 \approx 1.124. The 1-bit model's perplexity is about 12 percent higher. Perplexity is an exponential of the loss, so a 12 percent gap in perplexity is a small gap in the loss the model is trained on, and the paper reports it as competitive accuracy at a much lower cost.

QuestionA team wants to train a 1-bit model across eight devices, each holding a slice of a weight matrix. Why might per-tensor scaling cost them time, and what does the paper propose?Show answer

Per-tensor scaling needs the mean and the norm of the whole matrix, so every device must send its partial sums to the others before the layer can finish. That synchronization happens at every layer and slows the forward pass. The paper proposes group quantization: each device computes its own αg\alpha_g, βg\beta_g, γg\gamma_g, ηg\eta_g and normalizes its own group, so no extra communication is needed.

Sources

Read the full paper

Hongyu Wang, Shuming Ma, Li Dong et al., 2023. arXiv:2310.11453