18/31
Part 4 of 6 · Merge, unmerge and freezeLearn and do

Merge and unmerge are exact on paper, not in bf16

Merging is exact in theory, but real weights are stored with limited precision.

torch.manual_seed(0)
# weights of typical size 0.02
W = torch.randn(4096, 4096) * 0.02
# an update of typical size 0.001
dW = torch.randn(4096, 4096) * 0.001
for dtype in (torch.float32, torch.bfloat16):
    w, d = W.to(dtype), dW.to(dtype)
    # merge, then unmerge
    back = (w + d) - d
    print(dtype, f"{(back.float() - w.float()).abs().max().item():.1e}")
Predict

Merge and then unmerge an update of size 0.001 into weights of size 0.02. How far off is W afterward, in float32 and in bfloat16?

Pick one to see what it prints.
Pick an answer above to see the rest