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

High school / LONGER LESSON qlora

QLoRA: train adapters around a quantized base

Separate frozen storage from trainable adapters, trace quantization residuals, budget metadata and explain why one fitted example is insufficient.

Preparation: LoRA; quantization, reconstruction and gradients.

Plan 25–40 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

Combine two savings without confusing their roles

High-school path. Separate frozen storage from trainable adapters, trace quantization residuals, budget metadata and explain why one fitted example is insufficient. Preparation: LoRA; quantization, reconstruction and gradients. Move between Signal Room, Workbench and Field Notes without losing your section. Pause before each worked solution.

LoRA reduces the parameters updated during adaptation. Quantization reduces the storage precision of selected values. QLoRA combines a frozen quantized pretrained base with trainable low-rank adapters. The base still participates in computation, and learning signals pass through its operations into the adapter path. This is not ordinary full training of all weights as four-bit integers. Distinguish the compact stored base, the arithmetic used to apply it, and the trainable adapter state. They can use different precisions and have different memory costs.

Worked example. Imagine keeping a compact approximation of a reference map and learning corrections beside it. The approximation saves base storage, while the adapter controls the number of trained values. Neither mechanism alone tells you how much activation memory a long training example requires or how well the adapted model performs.

y = dequantize(W_codes)x + sBAx

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Does a frozen quantized base mean training can skip all computations through it?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. Its operations affect outputs and the signals needed by trainable components. Freezing avoids updating those base parameters; it does not make their forward role disappear.

Section 02 / 07

Storage, computation and optimizer state are different

A four-bit code is a compact representation, not necessarily the format used for every multiplication. A kernel can reconstruct values into a suitable computation format while using compact storage. Adapter weights, gradients and optimizer moments consume additional memory. Some optimizers retain higher-precision state even when model values are stored at lower precision. Therefore, multiplying the base parameter count by half a byte does not give total training memory. Activations, temporary buffers, gradients and allocator behavior must also be considered.

Worked example. For one selected 1,024 by 1,024 matrix, four-bit code payload is 524,288 bytes before scales. A rank-eight adapter has 16,384 parameters. If each uses two bytes for its weight, two for its gradient and eight for two optimizer moments, that illustrative adapter state adds 196,608 bytes. Those assumptions are explicit, not a universal runtime layout.

Training memory = frozen representation + trainable state + activations + workspace

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Why is base code payload alone an incomplete training-memory estimate?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

It excludes metadata, adapter state, activations and temporary allocations. A smaller frozen base can coexist with large training peaks elsewhere.

Section 03 / 07

NF4 is not a uniform integer ruler

The original QLoRA method uses NormalFloat four-bit quantization, usually called NF4. Its code values are designed around a normal-distribution assumption and are not uniformly spaced like a simple integer grid. The representation also needs block scaling. That design choice is distinct from the fact that there are sixteen possible four-bit codes. Data distributions and block normalization matter. Our numerical experiment deliberately uses a transparent symmetric uniform grid so every reconstruction is easy to inspect; it is not an implementation or benchmark of NF4.

Worked example. For the teaching grid, threshold 1.4 and positive code limit seven give scale 0.2. Weight 0.95 reconstructs as 1.0; minus 0.45 reconstructs as minus 0.4. An NF4 codebook generally has different representative levels, so these exact reconstructions must not be attributed to QLoRA’s NF4 format.

This fixture: s=A/7; q=clip(round(w/s),−7,7); ŵ=sq

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. If two formats both use four bits, must they reconstruct a stored code to the same value?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. Their codebooks, scales and conventions can differ. Bit width counts available codes; it does not specify their numerical meaning.

Section 04 / 07

Double quantization compresses metadata

Quantization scales themselves take space. Double quantization reduces part of that overhead by quantizing quantization constants. This is different from repeatedly quantizing model weights until they become smaller. A second layer of representation still needs its own metadata, so account for it rather than treating scales as free. The paper’s detailed scheme has specific block sizes and precision choices. Our budget is an illustrative two-level accounting example that makes the savings visible without claiming to reproduce an exact model package.

Worked example. Use 1,048,576 weights and groups of sixty-four: there are 16,384 first-level scales. Four-byte scales cost 65,536 bytes. In our alternative budget, one-byte scale codes cost 16,384 bytes, and one four-byte second-level scale per 256 codes adds 256 bytes. Total metadata becomes 16,640 bytes, not zero.

Metadata example = first-level code bytes + second-level scale bytes

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Why does the second-level scale need to be counted?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

Without it, the scale codes cannot be interpreted correctly. Compression moves some information into another representation; it does not remove all metadata.

Section 05 / 07

Fit a residual, then test a different input

An adapter can change outputs of a quantized base, but fitting one input does not prove that every quantization error has been repaired. Our base matrix is [[0.95,-0.45],[0.35,1.15]]. At scale 0.2 it reconstructs as [[1,-0.4],[0.4,1.2]]. Use input [2,1]. The original output is [1.45,1.85], while the quantized output is [1.6,2]. A rank-one adapter with A=[1,0] and both B entries equal to minus 0.075 adds [-0.15,-0.15], matching this particular original output.

Worked example. Change the adapter coefficient in Workbench until the selected input matches the original output. Then inspect the separate probe error. It stays nonzero at the default grid because the adapter’s chosen input direction misses that residual. This makes a limitation visible even before considering a large neural network.

A[0,1]ᵀ=0: this adapter cannot change that probe’s output

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Does zero error on the fitted input prove that the adapter restored the original matrix?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. Different matrices can agree on one input and disagree elsewhere. Probe other directions and evaluate held-out task examples.

Section 06 / 07

Paged optimizers manage peaks, not unlimited capacity

The QLoRA paper also uses paged optimizers to manage memory spikes through unified-memory mechanisms. This does not mean a machine gains unlimited fast memory. Moving state between memory levels can have costs, and activations still depend on sequence length, batch size and training configuration. A compact base may make a run feasible while leaving other bottlenecks. Account for steady state and peaks, and measure the actual configuration rather than treating a paper’s demonstration as a hardware guarantee for every model.

Worked example. At rank eight, our illustrative total with compressed scale metadata is 524,288 base-code bytes plus 16,640 metadata bytes plus 196,608 adapter-state bytes: 737,536 bytes. Doubling rank increases the adapter-state component but does not change the frozen base payload. The formula still does not include the rest of a model.

Component estimate ≠ full-model peak training memory

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Can this component budget certify that a full QLoRA job fits on a particular GPU?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. It describes one selected matrix under stated assumptions. A real job needs model-wide peak-memory and runtime measurements.

Section 07 / 07

Package the adaptation and evaluate the deployment

A QLoRA adapter depends on a particular base model and configuration. Preserve the base revision, quantization settings, adapter targets, tokenizer and training setup. Evaluate both held-out task performance and behavior that should remain from the original model. If deployment merges an adapter or changes the quantization format, check the resulting artifact again. The arithmetic of adding an update is not automatically identical after rounding into a different low-bit representation. Keep storage savings, learning quality and inference behavior as separate conclusions.

Worked example. Save the default Workbench result. Set the adapter coefficient to zero and observe the fitted-input error return. Change the grid threshold and see that the old adapter coefficient may no longer cancel the error. Then change only budget rank: the numerical fixture remains fixed while its separate state estimate changes.

Evaluate quantized base → adapted model → actual deployment artifact

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Why should a quantization-format change trigger renewed evaluation of an existing adapter?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

It changes the base computation around which the adapter operates. Compatibility, numerical error and task behavior can change even when tensor shapes remain the same.

Final checkpoint. Which description matches the core QLoRA setup? Option 1: Frozen quantized base with trainable low-rank adapters. Option 2: All weights trained directly as four-bit integer codes. Option 3: No gradients are needed.

Pause and choose an answer before continuing.

Reveal worked solution

Option 1 is correct. Stored base codes stay frozen while higher-precision computation supports adapter learning.

Continue the learning path

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.