Extract a LoRA adapter from a full fine-tune with SVD
Why it matters Turning full fine-tunes into small LoRA adapters makes them cheap to store and to serve many at once.
If you have a fully fine-tuned weight, you can compress the change into a LoRA adapter: the best rank-r approximation of the weight difference comes from its SVD.
Write extract_lora(W_base, W_ft, r, alpha). delta = W_ft - W_base, shape (d_out, d_in). Take U, S, Vt = SVD(delta) and keep the top r components. Return (A, B, rel_err) with A of shape (r, d_in) and B of shape (d_out, r) such that (alpha / r) * B @ A equals the rank-r approximation U_r diag(S_r) Vt_r. Split the singular values evenly: B = U_r * sqrt(S_r / scale) and A = sqrt(S_r / scale)[:, None] * Vt_r, with scale = alpha / r. rel_err = ||delta - scale * B @ A||_F / ||delta||_F as a float (0.0 if delta is all zeros).
def extract_lora(W_base, W_ft, r, alpha)Example
W_base = zeros (2, 2), W_ft = [[3, 0], [0, 1]], r = 1, alpha = 1 gives scale * B @ A = [[3, 0], [0, 0]] and rel_err = 0.3162.
Understand the idea
A full fine-tune changes every number in a weight matrix, but most of that change usually lies in a few directions. SVD finds those directions, ranked by importance, like listing the main ingredients of a recipe in order of quantity.
Example: delta = [[3, 0], [0, 1]]. Its singular values are 3 and 1. Keeping rank 1 gives [[3, 0], [0, 0]]. The error is the dropped part [[0, 0], [0, 1]], whose size is 1, against a total size of sqrt(9 + 1) = 3.16, so the relative error is 0.316.
Rule: delta_r = U_r diag(S_r) Vt_r. LoRA computes scale * B A with scale = alpha / r, so set B = U_r sqrt(S_r / scale) and A = sqrt(S_r / scale) Vt_r.
The Eckart-Young theorem says no rank-r matrix is closer to delta in Frobenius norm. Tools that convert fine-tuned checkpoints into adapters, and LoRA initialisations based on the weights' principal directions, use this same SVD step.
Shapes and data flow
delta (d_out, d_in) -> U (d_out, k), S (k,), Vt (k, d_in) -> B (d_out, r), A (r, d_in)