We use the same six weights. For each bit size, we work out how many levels we can store. Then we round to those levels, and measure the average error. Run it. Eight bits is almost perfect. Four bits is rougher, but still close. Two bits destroys the weights. Every value becomes one of only three numbers.
app.pypython
import torchw = torch.tensor([0.82, -0.31, 0.05, -1.27, 0.66, 0.003])for bits in [8, 4, 2]: levels = 2 ** (bits - 1) - 1 # 127 for 8 bits, 7 for 4 bits, 1 for 2 bits scale = w.abs().max() / levels back = torch.round(w / scale) * scale print(f"{bits} bits: {[round(x, 2) for x in back.tolist()]} " f"error {(w - back).abs().mean():.3f}")
Four bits is the sweet spot, if we're clever. Model weights aren't spread evenly. Most are close to zero, and few are large. NF4, which means normal float four, puts more of its sixteen levels near zero, where most weights are. So it loses much less than simple four bit rounding.
Here's what that means for an eight billion parameter model. In b float sixteen, the weights need sixteen gigabytes. In eight bits, eight. In NF4, about four and a half, including the scales. That fits on a normal gaming GPU.
Let's recap. Fewer bits mean more error. Four bits is the sweet spot. NF4 puts its levels where most weights are. And an eight billion model shrinks to about four and a half gigabytes. Next, combining this with LoRA. QLoRA.