8.3 LoRA, Adapters, and Federated Updates
Train BA, freeze W. r(d+k) trainable, not dk. Merge has no extra decode latency.
These notes match the lecture slides. Use (slides) on the course hub for the deck.
Full fine-tuning moves every entry of . LoRA (Hu et al., 2021) freezes and learns a low-rank residual. You store a few megabytes per task instead of a second copy of the 7B.
1. What LoRA is
Full fine-tuning copies every weight and walks off the old task (note 8.2). LoRA freezes and trains a low-rank residual . For a linear map ,
with , , and rank . Initialize so the adapter starts as the base model. Train only (and maybe a bias). The reason for LoRA is that a full has the same size as (GPT-3: 175B extra weights per task). Encode instead.
You are not inventing a new transformer. You are storing a few megabytes per skill instead of a second 7B. One adapter per skill is how you avoid the XOR-then-AND overwrite: the base stays, the skill is a file. QLoRA is the same algebra with stored in 4-bit and the adapters in float.
2. Why we use it
A full fine-tune is expensive to store and destructive to run. GPT-3-scale is 175B extra numbers per task. Even a 7B copy per hospital is the wrong footprint if the base can stay frozen. LoRA is the cheap “add B without moving A” answer that note 8.2 promised.
Small (4, 8, 16) is often enough for style and instruction shifts; harder domain shifts may want larger or more layers. At deploy time you can merge and throw the adapter away, or keep several adapters and swap them. Merge means no extra inference latency. Swap means one base, many skills.
For a project: report , which modules you adapted, , and whether you merged. Compare to a small full fine-tune if you can afford it. Lab 8 uses a frozen so you can print .
3. Architecture
Insert on attention projections and/or MLP up/down maps. The frozen still computes . The adapter adds . Init so step 0 is the base. Attention projections () are the usual insertion points; MLP maps are allowed too.


Trainable count for one matrix is , not , and not . QLoRA quantizes to 4-bit and still trains float adapters. Same picture: the big matrix is frozen (and cheap to store); the small factors move.
Why not init instead? Either factor zero works for a zero start; the usual recipe is Gaussian and zero so the first step can still move (nonzero , getting a gradient). If both start at 0, the product stays 0 until you break the deadlock (you would not).
4. How it works, step by step
- Freeze . Insert (Gaussian) and on the chosen projections.
- Train only on the new task (SFT, or later a preference loss). The base does not walk off task A.
- Scale with . That ratio does not add parameters; it is a knob on adapter strength.
- Deploy. Merge for a single file with base latency, or keep on disk and swap adapters by subtracting one and adding another. Merge loses easy unmerge unless you kept .
- Report , modules, , merged or not. Small may fail a hard domain shift; raising or adapting more layers is the next knob, not “LoRA does not work.”
Lab size: , . (4 numbers), (4 numbers), 8 trainable vs 16 in . At init . That printout is Lab 8 section 1.
5. Mathematical formulas
Forward with a scaled low-rank residual:
Trainable count per adapted matrix:
versus in a full . One map, , rank :
trainable numbers. Full has entries. Ratio (about 0.39%).
Merge at deploy:
which is again. Inference cost matches the base.
6. Positive points and negative points
Positive.
- Cheap: trainable numbers per matrix instead of , megabytes per task instead of a second 7B.
- Mergeable: after there is no extra inference latency.
- One adapter per skill keeps the base frozen, which is the forgetting fix replay cannot promise.
- QLoRA keeps the same algebra with 4-bit .
Negative.
- Small may fail hard domain shifts; you may need a larger rank or more layers.
- Init both factors randomly and the model is not the base at step 0.
- Counting LoRA as or as only is a report bug; it is per adapted matrix.
- Merge throws away easy unmerge unless you kept .
- Not a new architecture. A project that “used LoRA” still has to name , modules, and .
When not to. If you must change every feature and you can afford a full copy, full fine-tune is simpler. If the model already fits and you only needed fewer bits, that is quantization (note 7.3), not an adapter.
7. Federated adapters
Sites that cannot ship raw text can still train a LoRA locally and send to a server. The server averages adapters (or stacks them) without seeing documents. That is federated fine-tuning in the sense this course needs: communication is the adapter, not the corpus.

Privacy is not automatic. Adapters can leak. A hospital that trains a LoRA and sends it to you did not send the notes, but the adapter can still carry traces of them. Shipping a hospital adapter and calling it private is the usual overclaim. The footprint is the right size; the privacy theorem is not included.
8. Teaching this note
About 35–40 minutes at the board: write vs , init , merge vs swap. Play the full LoRA video as assigned (in class, first 20–25 min if the clip runs long; rest after). Lab 8 section 1 is the printout.
9. Worked example
One map, , rank :
trainable numbers. Full has entries. Ratio (about 0.39%). is a scale; it does not add parameters.
Lab size: , . (4 numbers), (4 numbers), 8 trainable vs 16 in . At init .
Why not init instead? Either factor zero works for a zero start; the usual recipe is Gaussian and zero so the first step can still move (nonzero , getting a gradient). If both start at 0, the product stays 0 until you break the deadlock (you would not).
Merge: is again. Inference cost matches the base; you lose easy unmerge unless you kept .
10. Where students get stuck
- Counting LoRA as or as only. It is per adapted matrix.
- Init both factors randomly so the model is not the base at step 0.
- Shipping a hospital adapter and calling it private. The corpus stayed, but adapters can still leak.
11. Video
Umar Jamil — LoRA, explained visually + PyTorch from scratch. Play the full video as assigned. In a two-hour class, run 0:00–~25:00 (math + the diagram) and leave the PyTorch walkthrough for after, or play through if time. Pause when is zeros: that is Lab 8’s first print.
12. Practice
-
If and , how many trainable numbers are in versus ?
-
Why initialize rather than ?
-
A hospital trains a LoRA and sends it to you. What did they not send, and what can still leak?
-
, , . Compute and the ratio to .
-
You adapt projections, each with , . Ignore . How many trainable parameters is that (four matrices)?