Skip to content
Optimal Lab

AI Engineering · interactive

LoRA: fine-tune a sliver of the model

Full fine-tuning changes every weight and needs a whole new copy of the model. LoRA freezes the original weights and trains two thin matrices beside them. Their product is the same shape as the weights it adjusts, at a fraction of the size.

A tiny 8×8 layer at rank 2 (the picture stops at 2)

W (frozen) · 64
+
B · 8×2
×
A · 2×8
=
B·A · 8×8

Trained here: 32 numbers (B and A) to adjust all 64 weights, and the update can only change the layer in 2 independent directions. The saving grows with size: at 4096×4096, rank 8 trains 0.39% as many numbers.

Full fine-tune of those layers (a 7B model)1.07B

LoRA at rank 84.2M

Rank 8: train 4.2M numbers instead of 1.07B, 0.06% of the model. The adapter file is 8 MB.

  1. 1

  2. 2

  3. 3

    Gradients flow through the frozen model but only update the adapters, so training fits on far smaller GPUs.

    4.2M trainable numbers, 0.39% of a full fine-tune of the same layers.

  4. 4