7/31
Part 2 of 6 · How A and B startLearn and do
With B at zero, the wrapped layer equals the base layer
Right after wrapping, the model should behave exactly as before.
base = nn.Linear(16, 12)
lora = LoRALinear(base, r=4, alpha=8.0)
print(torch.equal(lora(x), base(x)))
True
torch.equal is True only when every number matches exactly.
B (2, 1)00
A, random (1, 3)10-1
B @ A (2, 3)000000
With B at zero, B @ A is all zeros, so lora(x) = base(x) + (α / r) · 0 = base(x). These are the sizes of the worked example in Part 5: out = 2, r = 1, in = 3.
That needs , so one of the two factors starts at zero. The paper's choice is a random Gaussian and a zero .
In the editor, lora wraps a fresh base layer at rank 4, and x holds 5 inputs. Set same_at_start: whether lora(x) equals base(x) exactly. The next line moves B, as one training step would. Then set moved: whether the two outputs differ now.