Intuition Why a whole page of examples?
The parent note gave you the LoRA equation and three examples. But real practice throws edge cases at you: what if the two weight matrices aren't square? What if r = 0 ? What happens the instant merging is done? This page builds a matrix of every case class and then works one example per cell — so when an exam or a real GPU throws a scenario at you, you have already seen it.
Recall the single formula everything on this page uses:
Every symbol above is used below. Nothing new is introduced without a picture.
Every LoRA question is really "count parameters" or "track a number through the equation" — but the setup varies along a few axes. Here is the full grid. Each cell gets its own worked example.
Cell
Scenario class
What makes it tricky
Example
C1
Square matrix, standard r
The baseline; get the arithmetic reflex
Ex 1
C2
Non-square matrix (d = k )
B and A have different sizes
Ex 2
C3
Degenerate r = 0
LoRA vanishes — sanity limit
Ex 3
C4
Limiting r = min ( d , k )
LoRA stops saving anything
Ex 4
C5
α / r scaling across ranks
Keep update magnitude fixed
Ex 5
C6
Init step-0 behaviour
B A = 0 , forward equals base
Ex 6
C7
Merge & zero-latency
W ′ = W + r α B A is one matrix
Ex 7
C8
Storage / multi-task word problem
Real GB-vs-MB budgeting
Ex 8
C9
QLoRA memory exam twist
4-bit base + 16-bit adapters
Ex 9
C10
Break-even rank exam twist
When does LoRA stop being cheaper?
Ex 10
The figure above shows the sizes: the big frozen square W , and beside it the two skinny strips B (tall, r columns) and A (wide, r rows). All examples are just measuring these shapes or pushing x through them.
Worked example Example 1 — the baseline count
A linear layer has W ∈ R 4096 × 4096 . Apply LoRA with r = 8 . How many parameters do you train, and what fraction of the full matrix is that?
Forecast: guess the number of trained params before reading — is it thousands, tens of thousands, or millions?
Shape B and A . B is d × r = 4096 × 8 ; A is r × k = 8 × 4096 .
Why this step? The formula fixes B 's columns and A 's rows to r ; the other dimension matches W .
Count entries. B has 4096 × 8 = 32 , 768 ; A has 8 × 4096 = 32 , 768 . Total = 65 , 536 .
Why this step? Trainable params are exactly the entries of B plus A — nothing in W moves.
Full matrix size. Δ W dense would be 4096 × 4096 = 16 , 777 , 216 .
Why this step? This is the thing LoRA replaces; the ratio is the point.
Fraction. 65 , 536/16 , 777 , 216 = 0.00390625 = 0.39% .
Verify: general formula r ( d + k ) = 8 ( 4096 + 4096 ) = 8 × 8192 = 65 , 536 . ✓ Matches step 2. And 256 × 65 , 536 = 16 , 777 , 216 , so LoRA is exactly 256 × smaller.
Worked example Example 2 — when
d = k
A projection has W ∈ R 1024 × 4096 (maps a 4096-vector down to 1024). Apply LoRA with r = 16 . Count trainable params, and check the two thin matrices multiply back to the right shape.
Forecast: will B and A be the same size this time? (No — watch.)
Shape B . B is d × r = 1024 × 16 = 16 , 384 entries.
Why this step? B 's rows always match the output dimension d = 1024 .
Shape A . A is r × k = 16 × 4096 = 65 , 536 entries.
Why this step? A 's columns always match the input dimension k = 4096 . Different from B now!
Total. 16 , 384 + 65 , 536 = 81 , 920 .
Shape check of B A . ( 1024 × 16 ) ( 16 × 4096 ) = 1024 × 4096 — same shape as W . ✓
Why this step? The inner dimension r = 16 cancels; the update must match W to be addable.
Verify: formula r ( d + k ) = 16 ( 1024 + 4096 ) = 16 × 5120 = 81 , 920 . ✓ Full Δ W would be 1024 × 4096 = 4 , 194 , 304 , so LoRA is ≈ 51 × smaller here.
Worked example Example 3 — the rank-zero sanity check
What does LoRA do if you set r = 0 ? Show the update vanishes and explain why the model is then exactly the base.
Forecast: does the model break, or does it quietly become the frozen model?
Shapes collapse. B is d × 0 and A is 0 × k — matrices with zero columns / rows.
Why this step? r literally is the shared dimension; setting it to 0 removes it.
The product. B A is the d × k zero matrix (an empty sum of outer products = 0 ).
Why this step? B A = ∑ i = 1 r B : , i A i , : ; with r = 0 there are no terms, so the sum is 0 .
Forward pass. h = W x + 0 α ⋅ 0 ⋅ x . The 0 α is only a red flag on paper — since B A = 0 before scaling, the correction is 0 and h = W x .
Why this step? You never actually divide by zero in code because you never build a rank-0 adapter; this is a limiting sanity check showing "no LoRA = base model."
Verify: trainable params = r ( d + k ) = 0 ⋅ ( d + k ) = 0 . Zero rank ⇒ zero new params ⇒ pure base model. ✓
Worked example Example 4 — when LoRA saves nothing
For W ∈ R 4096 × 4096 , push r up to 2048 . Compare LoRA's param count to the full dense update. At what rank does LoRA stop being cheaper?
Forecast: at r = 2048 (half of 4096), is LoRA still smaller than dense?
LoRA count. r ( d + k ) = 2048 × 8192 = 16 , 777 , 216 .
Why this step? Plug into the same formula — nothing special except r is now large.
Dense count. d × k = 4096 × 4096 = 16 , 777 , 216 .
Why this step? This is the fixed size of a full Δ W .
Compare. They are equal . At r = 2048 , LoRA uses exactly as many params as the full update.
Why this step? Break-even: r ( d + k ) = d k ⇒ r = d + k d k = 8192 409 6 2 = 2048 .
Conclusion. For r > 2048 , LoRA is more expensive than full fine-tuning — pointless.
Verify: break-even r = d + k d k = 8192 16 , 777 , 216 = 2048 . ✓ This is the mathematical reason LoRA only helps when r ≪ d + k d k .
Worked example Example 5 — keeping update strength fixed
You tuned well at r = 8 , α = 16 . You want more capacity, so you switch to r = 32 . What α keeps the effective update strength r α the same?
Forecast: does α go up or down when you raise r ?
Read the current scale. r α = 8 16 = 2 .
Why this step? r α is the actual multiplier hitting B A ; that is what you must preserve.
Solve for new α . Want 32 α new = 2 ⇒ α new = 64 .
Why this step? Bigger r makes the raw B A entries grow; dividing by the bigger r compensates only if α scales up too.
Interpretation. Capacity (how many directions the update can use) rose from 8 to 32, but strength (how hard it pushes) stayed at 2 × .
Why this step? α / r decouples "capacity" from "magnitude" — you tune them independently.
Verify: 32 64 = 2 = 8 16 . ✓ Same effective scale.
Worked example Example 6 — the model is untouched at start
LoRA inits B = 0 and A ∼ N ( 0 , σ 2 ) . Take a concrete tiny case: W = [ 2 0 0 3 ] , x = [ 1 1 ] , r = 1 , α = 2 , A = [ 0.5 , − 0.4 ] , B = [ 0 0 ] . Show h at step 0 equals W x .
Forecast: does the random A leak into the output before training?
Compute B A . B A = [ 0 0 ] [ 0.5 , − 0.4 ] = [ 0 0 0 0 ] .
Why this step? Anything times a zero column is zero — A 's values are irrelevant while B = 0 .
Scaled update. r α B A = 1 2 ⋅ 0 = 0 .
Why this step? Zero matrix stays zero under any scaling.
Forward. h = W x + 0 = [ 2 3 ] .
Why this step? W x = [ 2 ⋅ 1 3 ⋅ 1 ] . LoRA contributes nothing at init — no knowledge destroyed.
Verify: h = W x = ( 2 , 3 ) exactly; the LoRA term is ( 0 , 0 ) . ✓ This is why zero-init B prevents Catastrophic Forgetting at the first step.
Worked example Example 7 — collapsing to one matrix
After training, W = [ 2 0 0 3 ] , B = [ 1 2 ] , A = [ 0.5 , − 1 ] , r = 1 , α = 1 . Compute the merged W ′ = W + r α B A and confirm W ′ x equals the two-step LoRA output for x = [ 1 1 ] .
Forecast: will the merged single matrix give the same answer as running W and B A separately?
Outer product B A . [ 1 2 ] [ 0.5 , − 1 ] = [ 0.5 1 − 1 − 2 ] .
Why this step? This dense 2 × 2 is the whole update, reconstructed from the two thin factors.
Merge. W ′ = [ 2 0 0 3 ] + [ 0.5 1 − 1 − 2 ] = [ 2.5 1 − 1 1 ] .
Why this step? r α = 1 , so just add. Now there is one matrix — no extra layer at inference.
Check output. W ′ x = [ 2.5 − 1 1 + 1 ] = [ 1.5 2 ] .
Two-step output. W x = ( 2 , 3 ) ; r α B A x = [ 0.5 − 1 1 − 2 ] = ( − 0.5 , − 1 ) ; sum = ( 1.5 , 2 ) .
Why this step? Same numbers ⇒ merging is exact, so inference latency is literally zero.
Verify: merged W ′ x = ( 1.5 , 2 ) equals split-path W x + r α B A x = ( 1.5 , 2 ) . ✓
Worked example Example 8 — budgeting a real deployment
You serve one 7B base model (stored as 14 GB in 16-bit) plus LoRA adapters for 5 tasks, each 8 MB. Compare total storage against saving a full fine-tuned copy per task. Give the ratio.
Forecast: roughly how many GB does the PEFT approach save versus 5 full copies?
PEFT storage. 14 , 000 MB + 5 × 8 MB = 14 , 040 MB .
Why this step? One shared frozen base plus five tiny plug-ins.
Full-copy storage. 5 × 14 , 000 MB = 70 , 000 MB .
Why this step? Full fine-tuning writes a whole new 14 GB checkpoint per task.
Savings. 70 , 000 − 14 , 040 = 55 , 960 MB ≈ 54.6 GB saved .
Ratio. 70 , 000/14 , 040 ≈ 4.99 × smaller.
Why this step? As you add more tasks the ratio approaches the number of tasks — the base cost is amortized.
Verify: PEFT = 14040 MB, full = 70000 MB, ratio ≈ 4.986 . ✓
Worked example Example 9 — 4-bit base, 16-bit adapters
A 7B-parameter base loaded in 4-bit (0.5 bytes/param) plus LoRA adapters totalling 4.19M params in 16-bit (2 bytes/param). Estimate weight-memory. Compare with loading the base in 16-bit.
Forecast: does the tiny 16-bit adapter or the huge 4-bit base dominate memory?
4-bit base. 7 × 1 0 9 × 0.5 B = 3.5 × 1 0 9 B = 3.5 GB .
Why this step? 4 bits = 0.5 bytes; only the frozen weights get quantized (see Quantization ).
16-bit adapters. 4.19 × 1 0 6 × 2 B = 8.38 × 1 0 6 B ≈ 8.4 MB .
Why this step? Adapters stay high-precision so gradients are meaningful — but they're tiny, so this is negligible.
Total. ≈ 3.5 GB + 0.008 GB ≈ 3.51 GB .
16-bit base for comparison. 7 × 1 0 9 × 2 B = 14 GB .
Why this step? Shows the 4-bit trick alone cuts weight memory ≈ 4 × , letting huge models fit one GPU.
Verify: 4-bit base = 3.5 GB, adapters ≈ 0.00838 GB, total ≈ 3.508 GB; 16-bit base = 14 GB; ratio = 4 . ✓
Worked example Example 10 — "at what rank is LoRA pointless?"
For a non-square weight W ∈ R 2048 × 8192 , find the rank r at which LoRA's parameter count equals the dense update. For which r does LoRA actually save memory?
Forecast: will break-even r be bigger or smaller than in the square case?
Set equal. r ( d + k ) = d k ⇒ r = d + k d k .
Why this step? Break-even is where the two counts match — solve the formula for r .
Plug in. r = 2048 + 8192 2048 × 8192 = 10 , 240 16 , 777 , 216 = 1638.4 .
Why this step? Direct substitution of the given dimensions.
Interpret. LoRA saves memory only for integer r ≤ 1638 . Typical r = 8 –16 is vastly below this, so the savings are enormous.
Why this step? Confirms why practical LoRA ranks are always deeply in the "cheap" region.
Verify: 2048 + 8192 2048 × 8192 = 1638.4 . ✓ Since 8 ≪ 1638 , LoRA is ≈ 8 × 10240 2048 × 8192 ≈ 204.8 × cheaper at r = 8 .
Recall Which cell does each idea belong to?
Setting r = 0 gives what update? ::: The zero matrix — pure base model (Cell C3).
The rank where LoRA stops saving memory is? ::: r = d + k d k (Cells C4, C10).
Why does merging add zero latency? ::: W ′ = W + r α B A is one matrix, same output (Cell C7).
If you double r , what keeps update strength fixed? ::: Double α so α / r is unchanged (Cell C5).
In QLoRA which part is 4-bit? ::: Only the frozen base; adapters stay 16-bit (Cell C9).
Mnemonic The two reflexes
Count → r ( d + k ) . Break-even → d + k d k . Every example on this page is one of these two arithmetic moves plus a story.