LoRA rank is a parameter budget, not a quality guarantee
Count a declared low-rank update while separating trainable weights from the full training-memory footprint.
On this page
The question for today
What you’ll understand
- Use a consistent input/output orientation for LoRA factors.
- Count parameters per target matrix and across selected modules.
- Explain what rank and quantization do not remove from memory or evaluation needs.
Low-Rank Adaptation freezes a base matrix and learns a factored update instead of training every entry directly. That can greatly reduce trainable parameters, but the result still runs inside a complete model with activations, gradients, optimizer state, and frozen weights. Rank determines a structural capacity and cost budget, not guaranteed instruction quality. Specify the target matrices, orientation, scaling, and dtype before interpreting a small adapter file as a complete training plan.
A factored update has explicit dimensions
Use column-vector convention: a base weight W₀ maps din inputs to dout outputs. Choose A with shape r×din and B with shape dout×r, so BA has the same shape as W₀. Standard LoRA adds a scaled BA update. Libraries may store some matrices transposed or provide different module wrappers, so verify actual target names and conventions. The formula here excludes biases, embedding-specific adapters, DoRA, and other variants unless explicitly added to the budget.
The rank bound limits the update matrix, not the rank of the complete adapted model or a universal set of behaviors it can learn. Increasing r adds parameters but can change optimization and overfitting as well as capacity. Targeting attention projections, MLP matrices, or another module changes which computations adapt. A configuration with a valid rank and no matching target modules can train nothing useful. Inspect matched modules and actual trainable tensors before starting a long job.
Count the memory categories separately
For one ordinary dense target, the two factors contain r(din+dout) parameters instead of din×dout fully trained entries. Sum that count across actual matched targets, including any separately trained biases or saved modules. Trainable parameter count alone omits frozen base storage and forward activations. Depending on optimizer and precision, gradients, moment estimates, master copies, temporary buffers, and distributed communication can add substantial memory. Measure peak live use at representative sequence lengths and batch settings.
QLoRA combines low-bit frozen-base storage with trainable adapters under a defined computation and quantization scheme. Four-bit payload arithmetic is not a complete GPU-memory estimate: scales, metadata, compute dtype, activations, and allocator/workspace behavior remain. Quantization and adaptation introduce implementation-dependent numerical changes that require evaluation. The original paper reports experiments under its own conditions;do not turn them into a promise that every dataset, rank, target module, or quantized merge preserves quality.
Choose targets with controlled comparisons
Compare rank and target selections with the same base, data, masks, token budget, and evaluation protocol. A larger adapter trained for more supervised tokens is not a clean rank-only comparison. Include retention tasks and task-specific failure cases, not just training loss. Record optimizer steps, learning-rate schedule, and effective target tokens because those can explain differences that otherwise look like representation capacity. Keep a safe baseline and stop configurations that violate memory or correctness checks.
The matrix lab shows a fixed two-dimensional transform rather than a trainable adapter. Reset and set both a=1, b=1, predict determinant 1 and a shear, then Step. Its matrix [[a, b], [0,1]] is not a general BA factorization, and playback changes geometry rather than learning weights. Use the diagram to track row/column orientation and input/output roles only. Calculate actual adapter factors separately;the visual cannot choose rank, target modules, or predict instruction quality.
Work it through
A 4096-by 4096 target with rank eight
One frozen 4096×4096 dense weight uses standard rank-eight LoRA with no biases. Adapter parameters are two bytes each. For an illustrative training budget, also allocate two-byte gradients and two four-byte optimizer moments per adapter parameter, with no master copy.
The dense matrix contains 16,777,216 entries. Adapter factors contain 8×(4096+4096)=65,536 parameters, or 1/256≈0.390625% of the dense count.
Adapter weight payload is 65,536×2=131,072 bytes, or 128 KiB. Adding the declared gradients and moments makes 12 bytes per parameter, total 786,432 bytes, or 768 KiB.
A two-byte frozen dense base alone adds 33,554,432 bytes, or 32 MiB, for this target before activations or other layers. The small trainable count therefore does not establish total model memory or an accuracy guarantee.
The rank count is useful only inside a complete, explicit state budget and a measured adaptation experiment.
The living notebook
Explore the model
Interactive lab · matrix
Keep matrix orientation explicit
Reset, set a=1, b=1, predict determinant 1 and shear, then Step. This selected 2 D triangular matrix is not a LoRA factorization, training loop, or target-module selector.
- Area scale · det A
- 1.4
- Singular values · σmax, σmin
- 1.597, 0.876
- Condition number · κ₂(A)
- 1.823
The selected matrix is A = [[a,b],[0,1]]. Playback interpolates geometry between the identity and A; readouts always describe A. Its determinant is a and its singular values come from AᵀA. Positive a makes every supported matrix invertible. This two-dimensional family is not a general eigensolver or a learned network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forState input/output dimensions and count actual factors before reasoning about adapter size.
Pause & reason
Check your understanding
Your turn
Try it yourself
For a 1024-input,2048-output bias-free target at rank four, count standard LoRA parameters and compare with the dense count. Name one training-memory category absent from that ratio.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Use r(din+dout)rather than multiplying r by the dense matrix's element count.
Compare with the solution
LoRA has 4×(1024+2048)=12,288 parameters versus 1024×2048=2,097,152 dense entries, about 0.58594%. The ratio excludes frozen base storage, activations, gradients, optimizer states, and workspaces. It also excludes other matched targets and any biases or separately saved modules. A lower ratio is not a prediction of better or worse instruction performance.
Keep the idea
Take it with you
- Factor orientation, scaling, and actual matched targets define the adapter.
- Trainable parameter ratios are not whole-training memory ratios.
- Rank and quantization need controlled quality and retention evaluation.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.