TL;DR
BitLinear is a layer that takes the place of an ordinary linear layer inside a Transformer. Its weights are stored as just +1 or -1, and its input is rounded to 8-bit integers, so the big matrix multiplication needs almost no real multiplication. It was introduced in 2023 to train language models whose weights are 1 bit from the start, which cuts memory and energy use a great deal.
Builds on: Quantization, Straight-Through Estimator, Layer Normalization · Leads to: BitNet, BitNet b1.58 and the later ternary language models
Where it's used
Training language models from scratch at 1 bit. The BitNet paper (Wang et al., 2023) replaced the weight projections in the attention and feed-forward blocks of a Transformer with BitLinear, and trained autoregressive language models from 125 million to 30 billion parameters on an English corpus. The change was a swap of one layer type. The other components stayed at higher precision (8-bit in the paper's experiments), so the recipe needs no new architecture.
Serving large models with less memory. A 6.7-billion-parameter model has about 6.7 billion weights. At 16 bits each that is about 13.4 GB of weights; at 1 bit each it is about 0.84 GB. Memory bandwidth, the time spent moving weights from memory to the processor, is often the limit when a large model answers one request at a time. Smaller weights mean less of that movement.
Cheaper arithmetic on energy-limited hardware. The paper's energy estimate for a 6.7-billion-parameter model (Table 1) gives 4.41 J for the multiplications of a 32-bit Transformer at 7 nm, and 0.02 J for BitNet's multiplications in the same setting. The additions that remain are cheap too, which matters on battery-powered hardware.
How it works
Take one tiny layer with a 2 by 2 weight matrix and one input vector, and follow one forward pass. The weights are and the input is .
- Start with the real-valued weights. During training the layer keeps the four numbers in at full precision. Check: the matrix has four entries and they can be any size.
- Centre the weights. Subtract the mean of all entries. The mean is , so is . Check: the four new entries add to zero, since .
- Keep only the sign. Each entry becomes +1 if it is positive and -1 otherwise. The binary matrix is . Check: every entry is +1 or -1, so storing it needs one bit per entry.
- Measure one scale for the weights. Average the absolute values of the original weights: . Check: is one positive number for the whole layer. It will be used once, at the end, to put the output back on the right scale.
- Normalize the input. This is the layer normalization step: subtract the mean of and divide by its spread. The mean of is , and the variance is , so the square root is 3 and . Check: the new vector has mean 0 and variance 1.
- Round the input to 8-bit integers. Find the largest absolute value in the normalized input, . Multiply every entry by , where for 8 bits, and clip to the range . The input becomes . Check: both entries are integers in the 8-bit range. (The real formula keeps a tiny margin inside the range; we ignore it here.)
- Multiply with additions only. Each output is a sum of the input entries, each added or subtracted according to its weight sign. Row 1 gives . Row 2 gives . Check: every step is an addition or subtraction.
- Rescale once. Multiply the sums by . Each output becomes , so . Check: one multiplication per output, not one per weight.
For comparison, the same layer without any rounding gives . The 1-bit layer lands close to it, not on it. On a matrix this small the error is large; on a layer with thousands of inputs the errors average out, which is why the design is useful at scale.
- 8-bit absmax, γ = 1
flowchart LR
W["Real weights W"] --> C["Centre and take sign: W~ in {-1, +1}"]
X["Input x"] --> LN["Layer norm: LN(x)"]
LN --> Q["8-bit absmax: x~"]
C --> M["W~ times x~: additions only"]
Q --> M
M --> S["Rescale by beta gamma / Q_b"]
S --> Y["Output y"]
The math
For a weight matrix and an input , let be the mean of the entries of , the matrix of signs, the mean absolute value of the entries of , the layer-normalized input, and the input rounded to bits by absmax. The layer output is
Step 2 in symbols: centring
. Subtracting moves the weights so that their mean is zero, which lets the signs split them evenly. In the example, .
Step 3 in symbols: the sign
Applied entry by entry to . Note that zero maps to -1, as in the paper. For instance, if and , then and the sign is +1.
Step 4 in symbols: the weight scale
. The sign matrix has entries of size 1, while the real weights have typical size . Multiplying by at the end restores that size. In the example, .
Step 5 in symbols: layer normalization
Here is the mean of the entries of and their variance, with a tiny constant that avoids dividing by zero. The paper's reason for this step: with standard initialization (Kaiming or Xavier), the full-precision output variance is about 1. Normalizing before the 8-bit rounding keeps the quantized output near that value, since the paper's estimate is .
Step 6 in symbols: absmax rounding
With bits, , and
Here is the largest absolute value of the entries, and . The input is scaled so its largest entry lands on , then clipped. In the example, , so the values are .
Steps 7 and 8 in symbols: the product and the rescale
The matrix product is . Because each is , every term is , so the product is a signed sum of inputs. In the example, . The output is .
Two details from the paper matter in practice. During training, is computed once per tensor. During inference it is computed per token, which the paper says helps both stability and efficiency. The paper also quantizes activations to 8 bits and leaves lower precision to future work.
Worked examples
Treat one row, , as a whole layer with one output, so uses only its two entries. The input after normalization and rounding is . Use only the weight signs, not the real values, in the sum.
- The row's mean is , so the centred row is .
- The signs of are .
- The signed sum is .
- The scale is and , so the output is .
- Interpretation: the layer turned a sign pattern and an 8-bit input into one real number, using additions for the big sum and a single multiplication at the end.
Input after normalization: . Find the 8-bit values .
- The largest absolute value is .
- The scale factor is .
- Multiply each entry: , , .
- Each value is already inside , so clipping changes nothing.
- Interpretation: the entry of largest size maps to the edge of the 8-bit range, and the others keep their ratios. The scale is applied back at the end, in the rescale step.
A 6.7-billion-parameter language model has hidden size 4096 (Table 6 of the paper lists this for the 6.7B model), so its projection layers are 4096 by 4096. Compare the memory of one such layer's weights at 16 bits and at 1 bit. Use 1 megabyte = 1,048,576 bytes and ignore the few scalar values , , .
- The layer has weights.
- At 16 bits each, that is bytes.
- Divided by 1,048,576, that is 32 megabytes.
- At 1 bit each, the weights take bytes.
- Divided by 1,048,576, that is 2 megabytes. The ratio is .
- Interpretation: each projection shrinks sixteenfold in storage. The paper's energy and memory claims come from this kind of saving, applied to every projection in the network.
Try it: a feedforward projection in a model of hidden size 4096 has size 4096 by 11008 (11008 is the inner width). How many megabytes does it take at 16 bits, and how many at 1 bit? Use the same conventions as above.
Answer: weights. At 16 bits that is bytes, which is 86 megabytes. At 1 bit it is bytes, which is 5.375 megabytes. The ratio is 16 again.
Common mistakes and tradeoffs
It is tempting to think a 1-bit network does all its arithmetic in 1 bit. In fact the weights are 1 bit, but the activations are 8 bits and the scales and are real numbers. The additions are cheap because the weights are binary; the input still needs enough precision to carry information.
It is tempting to think you can round a finished model to 1 bit and keep its quality. In fact the paper's post-training absmax baseline at 1-bit weights reached a Perplexity of , and its zero-shot average fell to 44.6, close to the 43.8 of random guessing. BitNet, trained with the rounding in the loop, reached a perplexity of 17.07 at 6.7B parameters, against 15.19 for the FP16 Transformer, with a zero-shot average of 55.9. The network has to learn weights whose signs work after rounding, which is why the training recipe matters (see Quantization-Aware Training).
It is tempting to think the latent weights must be binary too. In fact the optimizer updates a full-precision copy, and the binary weights are recomputed from it on every forward pass. The paper notes that a small update to the latent weights often changes no 1-bit weight at all, which is why the copy is kept.
It is tempting to think the centring and the layer norm are decoration. They are part of the design. Centring makes the signs split evenly, and the layer norm keeps the output variance near 1 after rounding. In the paper's ablation (Table 4), its configuration (absmax with SubLN placement) gets a zero-shot average of 52.3, against 51.3 for absmax with a standard Pre-LN placement and 50.2 for the elastic activation quantizer of an earlier method with Pre-LN.
When to use it. Use BitLinear when you can train from scratch or continue training, and when memory or energy at inference is the limit. The paper's Figure 1 says the cost savings become more significant as the model grows. Quality is not free at 6.7B, though: the perplexity gap to the FP16 Transformer is 17.07 against 15.19, so compare on your own task before committing. The paper also keeps the input and output embedding layers at high precision, because sampling from the output needs accurate probabilities.
When not to use it. If you already have a trained 16-bit model and no training budget, post-training quantization is simpler (see Post-Training Quantization), at a cost in accuracy at low bit widths.
Alternatives. Ternary weights in (see Ternary Quantization, and BitNet b1.58 for the language-model version) give a little more capacity per weight, at about 1.58 bits; Mixed-Precision Training keeps sensitive layers at higher precision.
History
For years, binary neural networks were studied mainly on convolutional image classifiers, as the BitNet paper notes. XNOR-Net (Rastegari and colleagues, 2016) used binary weights and inputs in convolution layers, and the large language model setting was a different problem.
The training trick came from earlier work. The Straight-Through Estimator was described by Bengio, Léonard and Courville in 2013 as a way to pass gradients through a hard step. It is what lets the rounding sit inside the forward pass during training.
In October 2023, BitNet (Wang and colleagues) introduced BitLinear as a drop-in replacement for the linear layer and reported scaling results up to 30 billion parameters. A 2024 follow-up, BitNet b1.58, moved the weights to the ternary values . The idea is easy to try because it changes one layer type, not the whole training system.
Recap
- A linear layer multiplies a weight matrix by an input. BitLinear replaces the weights with their signs, , after centring them.
- The input is normalized with layer normalization and rounded to 8 bits with absmax, so the product is a sum of signed inputs.
- One real-valued scale, , is applied to each output at the end.
- The network is trained with the Straight-Through Estimator and a full-precision latent weight, so it learns weights that survive the rounding.
- Read next: the BitNet paper, which builds the whole model from this layer, and BitNet b1.58 for the three-value variant. Quantization-Aware Training explains the training recipe.
Check yourself
QuestionRecall: what are the only two values a BitLinear weight can take?Show answer
+1 and -1. The sign of the centred weight, , decides which. There is no zero.
QuestionFor the weights used in the walkthrough, the mean is . What is the sign of the entry ?Show answer
Compute . This is not greater than zero, so the sign is -1. A value that sits just below the mean is still mapped to -1, which is why the centring step matters.
QuestionWhy does the layer divide by the scale before rounding the input, and then multiply by at the end?Show answer
Dividing by and multiplying by puts the largest input entry exactly on the edge of the 8-bit range, so the rounding uses the full range and loses as little as possible. The factor undoes this scaling at the end, so the output is on the same scale as the real-valued product. does the same for the weights.
QuestionA layer has 1024 inputs and 1024 outputs. How many bits does its weight matrix need at 1 bit per weight, ignoring scalars?Show answer
weights, each one bit, so bits, which is 131,072 bytes or 128 kilobytes (with 1 kilobyte = 1024 bytes).
QuestionA team wants a 1-bit model for a phone and has a trained 16-bit model with no training budget left. Should they convert it with BitLinear? Explain.Show answer
No. BitLinear needs training with the rounding in the loop, as the paper does from scratch. Rounding a finished 16-bit model to 1 bit without that training loses almost all accuracy; the paper's post-training 1-bit baseline collapsed. Post-training quantization at 8 or 4 bits is the practical choice in that situation.
Sources
- BitNet: Scaling 1-bit Transformers for Large Language Models (Wang et al., 2023)
- Layer Normalization (Ba, Kiros, Hinton, 2016)
- Estimating or propagating gradients through stochastic neurons (Bengio, Léonard, Courville, 2013)
- The Era of 1-bit LLMs: All Large Language Models are in 1.58 Bits (Ma et al., 2024)