Skip to content
SUNSETThe commons
Open app
SUNSET · A copy you can keep

Low-Rank Adaptation Notebook

Derive a LoRA update, count the trainable parameters and weight bytes, and test the rank constraint with an explicit matrix. Separate useful savings from total-memory claims.

Replace a dense update with two factors

Let a frozen linear layer use W₀ with shape d_out × d_in. A low-rank adapter represents its change as ΔW = (α/r) B A, where A has shape r × d_in and B has shape d_out × r. The layer computes W₀ x + (α/r) B(Ax). The base weights stay frozen while the factors are trained. The factorization uses r(d_in + d_out) trainable parameters. A separate full dense update would use d_in d_out parameters. The ratio is favorable when r is small relative to both dimensions. The rank of B A cannot exceed r, so the smaller parameter count also restricts the updates that can be represented. For a concrete shape check, choose d_in = 4, d_out = 3 and r = 2. A maps a four-dimensional input to two dimensions; B maps those two dimensions to three. Their product has the same 3 × 4 shape as W₀. This notebook describes the core linear-algebra construction. Actual adapter configurations choose which layers to target and may include other trained parameters.

Procedure checklist

0 of 8 checks complete. Checks stay on this device when browser storage is available.

Content: CC0-1.0 · Runtime: MIT. No wallet or account is needed to read. Checklist progress stays on this device. Commands are plain text; this guide never runs them.
MAKE THE NUMBERS MOVE

The interactive lab.

Calculated in your browser. No model API or wallet.

Dense projection 16,777,216 parameters
Trainable adapter 65,536 parameters
Trainable / base
0.390625%
Two-byte base weights
32 MiB
Two-byte adapter weights
128 KiB

Weight storage only. The frozen base, activations, gradients, optimizer state and temporary buffers still affect total memory.

FOLLOW THE ORIGINAL WORK

Primary references.

Original SUNSET explanations and exercises, released under CC0. The references below retain their own licenses.

LoRA · Hu et al.

Your offline copy includes the complete reading guide and worked examples. Chapter progress stays on your device.