4.3.7 · D1Pretraining & Fine-Tuning LLMs

Foundations — Parameter-efficient fine-tuning (PEFT)

1,902 words9 min readBack to topic

This page builds every symbol used in the parent PEFT note from absolute zero. If a line in that note used a letter you didn't recognise, it is defined here first, with a picture.


1. A vector — a list of numbers with a direction

  • are the entries (the individual numbers).
  • is how many entries there are — the dimension.
  • (a fancy "R") just means "the real numbers" — any decimal you like, positive or negative.

The picture. A vector of 2 numbers is an arrow on a flat page: the first number is how far right, the second how far up. A vector of numbers is the same idea in directions at once (we can't draw more than 3, but the idea is identical).

Why the topic needs it. In an LLM, each token (word-piece) is turned into a vector — a list of, say, 4096 numbers describing its meaning. Everything the model does is push these vectors around.


2. A matrix — a machine that transforms vectors

  • The size is written rows columns: .
  • = the number in row , column .

The picture. Think of as a grid of dials. Each dial contributes a little push to the output. A grid has exactly dials — and that number is why full fine-tuning is expensive.

Why the topic needs it. The parent note's very first line, , is "the layer's weight matrix transforms the input vector ." Every trainable part of the model is a matrix like this.


3. Matrix–vector multiply — how the machine runs

  • has entries → matches the columns of . (Sizes must line up.)
  • has entries → one per row of .

Why the topic needs it. The whole LoRA equation is three of these weighted votes added together. If you can read , you can read the whole thing.


4. — the change we want to make

The picture. Lay exactly over ; add the two grids cell by cell. If a cell of is zero, that dial doesn't move.

Why the topic needs it. Fine-tuning = finding a good . PEFT's entire trick is: don't store as a full dense grid — store it cheaply. That "cheaply" is the next idea.


5. Rank — how much independent information a matrix holds

This is the single most important prerequisite, so we go slowly.

Tiny example. Look at these two grids:

  • Left: row 2 is row 1; row 3 is row 1. There is really only one direction here → rank . It looks like a grid of 9 numbers, but it is secretly simple.
  • Right: the three rows point in three totally separate directions → rank (full).

Why the topic needs it. The parent's key claim — "fine-tuning updates lie on a low intrinsic dimension" — means exactly: is low rank. It looks big but is secretly simple, so we can store it in far fewer numbers.


6. Factorization — storing a low-rank matrix cheaply

Why two matrices reproduce a grid. The rule "rows columns must match" lets () multiply (): the shared inner size cancels, leaving . The small waist is the bottleneck — information is forced through only channels, which is why the result is guaranteed low rank.

Counting the dials.

For , :

That is times fewer numbers — the parent note's "256×".

Why the topic needs it. This is LoRA's storage trick. See Low-Rank Matrix Factorization for the deeper theory.


7. The remaining Greek and helpers


8. Where each symbol lives in the master equation

Now every piece of the parent's headline formula is defined:

Read left to right: the original weighted vote , plus a scaled, low-rank correction . Nothing here is unexplained anymore. LoRA typically inserts this on the and matrices inside Transformer Attention; the alternative it competes with is Full Fine-Tuning, and its cousin is Prompt Tuning.


Prerequisite map

Real numbers R

Vector x

Matrix W as a grid

Matrix times vector h = Wx

Change delta W

Rank and low rank

Factorization delta W = B A

Parameter count r times d plus k

LoRA forward pass

Scale alpha over r

Init B zero A random

Quantization 4 bit

QLoRA


Equipment checklist

Read a matrix size
rows by columns; it maps a -vector to a -vector.
Compute one entry of
Multiply row of elementwise with , then sum: .
Say what is
The change added to the frozen weight matrix during fine-tuning; same shape as .
Define rank in one line
The number of genuinely independent directions in a matrix's rows/columns.
Explain "low rank"
The matrix looks big but is secretly simple — few independent directions.
Give shapes of and
is (tall), is (wide); product is .
Count LoRA vs full params
trainable vs full.
State what does
Keeps update strength stable as you change the rank .
Why init
So at step 0 and the model starts identical to the pretrained one.
What quantization trades
Precision for memory — fewer bits per number.