22/31
Part 5 of 6 · A worked exampleLearn and do

A worked example: one layer by hand

Shrink it to something you can do by hand: in = 3, out = 2, r=1r = 1 and α=2\alpha = 2, so the scale is 2. The bias is zero and the input is x=[1,2,3]x = [1, 2, 3].

W=[10201−1],A=[10−1]W = \begin{bmatrix} 1 & 0 & 2 \\ 0 & 1 & -1 \end{bmatrix}, \qquad A = \begin{bmatrix} 1 & 0 & -1 \end{bmatrix}

To keep the arithmetic short, pretend training moved only BB, to B⊤=[0.5,−1]B^\top = [0.5, -1], and left AA where it started.

Before merge, merged, and unmerged: the same output

W = torch.tensor([[1., 0., 2.], [0., 1., -1.]])
A = torch.tensor([[1., 0., -1.]])
B = torch.tensor([[0.5], [-1.]])
x = torch.tensor([[1., 2., 3.]])
# base, bottleneck
print((x @ W.T).tolist(), (x @ A.T).tolist())
# trained
print((x @ W.T + 2 * (x @ A.T @ B.T)).tolist())
W_merged = W + 2 * (B @ A)
# merged
print(W_merged.tolist(), (x @ W_merged.T).tolist())
Predict

W gives [7, -1] for x, and the bottleneck x @ A.T is -2. With scale 2 and B = [0.5, -1], what does the trained layer give?

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