Macalinao StudioLearnAll enriched lessons ↗
High school path · 7 sectionsSwitch to college ↗

High school / LONGER LESSON 18

LoRA and QLoRA: small updates, complete accounting

Count adapter parameters, trace their gradients and distinguish storage from training memory.

Preparation: Matrix dimensions and multiplication.

Plan 20–35 minutes with the activities; this is a study estimate, not a timed requirement. Both paths have complete narration. Your notes and progress are kept separately for each level.

Section 01 / 07

Factor the update

High-school path. Count adapter parameters, trace their gradients and distinguish storage from training memory.

Preparation: Matrix dimensions and multiplication. Work through one section at a time. Predict the experiment result before changing its controls, then explain what the example leaves out.

LoRA represents an update with two thinner matrices while keeping the base matrix frozen. Low rank constrains the update; it does not make the entire model small. Replace a large editable grid with two narrow grids whose product supplies a correction.

ΔW = (α/r)BA; parameters = r(n+m)

Worked step 1. W is 8 by 6 and rank is 2.

Worked step 2. A has 12 entries; B has 16.

Worked step 3. The adapter has 28 entries versus 48 in W.

Try it yourself. Would increasing rank always save parameters?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. No. At sufficiently large rank, the two factors can exceed the dense matrix’s parameter count.

Section 02 / 07

Compute a small forward pass

The adapter acts on the same input as the base layer. Its output is added after applying the chosen scale. Track dimensions before interpreting the numbers. One route gives the original answer; a second narrow route supplies an adjustment.

Worked step 1. Let x=[1,2], A=[1,0], B=[2,3] as a column.

Worked step 2. Ax=1; B(Ax)=[2,3].

Worked step 3. Scale one half gives correction [1,1.5].

Try it yourself. What changes if alpha doubles at fixed rank?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. The correction doubles in this fixture. Training dynamics and quality do not necessarily improve.

Section 03 / 07

Trace initialization and gradients

One common initialization makes one factor zero so the initial adapter update is zero. Gradient flow into the two factors is then asymmetric on the first step. An initially closed output gate can learn to open before the upstream route receives a nonzero signal through it.

Worked step 1. Set B=0 and nonzero A.

Worked step 2. BA is zero.

Worked step 3. B can receive a nonzero gradient while A initially receives zero.

Try it yourself. Does this mean A stays frozen forever?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. No. After B changes, gradients can reach A. Both are trainable parameters.

Section 04 / 07

Quantization changes the frozen base storage

QLoRA combines low-bit base storage with adapter training. Arithmetic and intermediate representations are not simply all four-bit values. Memory still includes activations and optimizer states. Packing the textbook tightly does not pack every scratch calculation into the same small boxes.

Worked step 1. Count base storage separately.

Worked step 2. Count adapters and their optimizer states.

Worked step 3. Then measure activations and peak workspace.

Try it yourself. Can four-bit weight size alone prove the run fits memory?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. No. Peak memory includes the other components and implementation overhead.

Section 05 / 07

Merge with the right assumptions

For a compatible linear layer, a trained adapter can be merged into its base weight using the same scale. Quantized bases and multiple adapters need additional care. Write the correction onto a copy of the original sheet, keeping the unmodified original available.

Worked step 1. Save the base and adapter revisions.

Worked step 2. Compare merged and unmerged outputs on fixed inputs.

Worked step 3. Measure numerical tolerances.

Try it yourself. Can an adapter be safely attached to any same-sized model?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. No. Matching shape is insufficient; the adapter was trained for specific base weights and conventions.

Section 06 / 07

Evaluate rank as a trade-off

More rank provides more update capacity and more trainable parameters. It does not guarantee better generalization. Compare held-out tasks while controlling data and training budget. A larger notebook can hold more corrections, including mistakes learned from the practice set.

Worked step 1. In Workbench compare rank 4 and 8.

Worked step 2. Count parameters before training.

Worked step 3. Evaluate both on untouched examples.

Try it yourself. If training loss falls but validation worsens, what should you conclude?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. The extra capacity may be overfitting or the setup may need adjustment. Do not select solely by training loss.

Section 07 / 07

Mastery and transfer

Bring the pieces together. First answer the checkpoint without the worked solutions. Then explain the mechanism in your own words, using one numerical example from this lesson.

LoRA’s trainable matrix count is… Option 1: Always the dense weight count. Option 2: Rank times input plus output widths. Option 3: Only the rank itself.

Pause here and choose an answer before continuing. The checkpoint explanation follows.

Reveal worked solution

The correct choice is option 2: Rank times input plus output widths. A contributes rank times input width and B contributes output width times rank.

Transfer task. Change one assumption in the worked example. State your prediction, calculate or test it in Workbench, then explain whether the result supports your prediction.

Reveal worked solution

Self-check rubric. Name the changed assumption, keep the other inputs fixed, show at least one intermediate calculation, and distinguish what the toy example guarantees from what would require a trained model or a real measurement.

LONGER ADAPTATION LESSONS

Learn the update and the teaching signal

Worked examples, local narration and connected experiments at your level.

Sources and scope

Original worked examples and teaching text, grounded in these primary references. Numerical fixtures explain mechanisms; model quality and hardware performance require separate measurements. Both levels share key examples, with different explanations and checkpoints.

EXTENDED FIELD NOTES

Smaller numbers, larger consequences

Understand the storage saving, reconstruction error, and runtime accounting behind quantization.

Additional reading · original lesson audio remains unchanged.

Read the full explanation · 580 words
Round, reconstruct, compare

This toy quantizer introduces +0.04 error. Clipping is a separate source of error.

  1. Original: 0.26
  2. Scale: 0.1
  3. Code: 3
  4. Reconstructed: 0.30

Original: 0.26

A ruler with fewer marks

Imagine measuring a length with a ruler marked every millimeter and then recording it only to the nearest centimeter. The object has not changed, but your representation has become less precise. Quantization makes an analogous trade: it maps numerical values onto a more limited set of representable values. The analogy has limits because neural computations combine many values, and their errors can interact. Still, it explains why a smaller representation can save memory without being numerically identical to the original.

Take a toy scale of 0.1. A weight of 0.26 is rounded to the integer code 3 and reconstructed as 0.3. The reconstruction error is 0.04. If the representable range ends at 0.3, a value of 0.9 may be clipped to that boundary. Its error is much larger. Rounding and clipping are different problems. Choosing a wider range can reduce clipping while leaving fewer representable values near zero; choosing a narrower range can improve local resolution but lose outliers.

One number cannot describe every tensor

A model contains many kinds of tensors, and a quantization method may treat them differently. Some can remain at higher precision while others use fewer bits. Groups of values may share scales or other metadata needed to reconstruct approximate values. That metadata consumes space too. Therefore, multiplying the parameter count by a nominal bit width provides an estimate, not a promise of an exact file size.

For a deliberately simplified example, 122 billion values at exactly four bits each occupy 488 billion bits. Dividing by eight gives 61 billion bytes, or 61 decimal gigabytes. This excludes scales, other metadata, unquantized tensors, and everything required while the model runs. Decimal gigabytes also differ from binary gibibytes. The arithmetic is useful because it makes assumptions explicit; it should not be presented as the measured size or memory requirement of a particular Ornith artifact.

The file and the computation have different jobs

A file format packages information. A numerical format describes how values are represented. A runtime must understand both the architecture and the stored representation, then provide operations that execute on the available hardware. A smaller download does not automatically produce a faster answer. Unpacking values, transferring data, or using a slower fallback operation can outweigh a theoretical arithmetic saving.

Nor is runtime memory limited to the weights. The system needs temporary activations, attention state, workspaces, and output buffers. Multiple simultaneous requests can increase those requirements. A model that loads successfully can still run out of memory when given a longer prompt. This is why a useful comparison reports context length and concurrency alongside the weight format. “It fits” should mean that the intended workload fits, not merely that startup reaches a ready message.

Evaluate the approximation where it matters

Small weight errors do not translate into an identical amount of answer error. Some computations tolerate approximation better than others. A rounding change can alter a token score slightly; when candidate scores are close, a different token can be selected, and the later continuation can diverge. Conversely, different wording does not necessarily mean worse quality. Evaluation must examine whether the answer still satisfies the task.

Use the Workbench to compare original and reconstructed numbers before discussing whole-model quality. Then consider a task suite: factual questions, calculations, structured output, and the actual applications you care about. Hold the prompts and evaluation method stable. Report memory savings separately from measured quality and speed. QLoRA adds another distinction: it trains adapters around a quantized base; it is not simply a new label for running a four-bit model. Keeping representation, training, and execution separate makes technical comparisons much easier to understand.

Sources and further investigation

Source review: October 28, 2026. Model-release claims are attributed to their publishers.

Open the focused reading page →

Reset this high school path?

This removes only this path’s notes, progress and experiments from this browser.