← Lesson
LoRA
Joeven
Run
Reset
Python loads on first run
W = [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], ] B = [[0.0], [0.5], [0.0]] A = [[0.0, 0.0, 2.0]] def matvec(M, x): return [sum(row[j] * x[j] for j in range(len(x))) for row in M] def add(u, v): return [a + b for a, b in zip(u, v)] x = [1.0, 0.0, 1.0] base = matvec(W, x) Ax = matvec(A, x) patch = matvec(B, Ax) y = add(base, patch) print("x", x) print("base Wx", base) print("Ax", Ax) print("LoRA patch", patch) print("W+BA", y) print("only dim 1 picked up the adapter") x2 = [1.0, 0.0, 0.0] print("x2", x2, "patch", matvec(B, matvec(A, x2)), "y", add(matvec(W, x2), matvec(B, matvec(A, x2))))
Run to execute this in your browser. Nothing is sent to a server.