Skip to content

12.6 LoRA: low-rank adaptation with PiSSA initialization and merging

A BERT encoder can now be trained, and the fine-tuning heads make it classify sentences. Fine-tuning every weight works on a laptop for a 50k-parameter model, but the habit does not scale. The AdamW state is two extra copies of every weight, and each fine-tuned task stores a full copy of the model. At the 135M parameters of SmolLM2, which the engine serves later, that is half a gigabyte of optimizer state and of checkpoint per task. The end of this chapter needs the opposite: a classifier fine-tune in which less than 5% of the parameters train.

Concepts from other sections (7)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

LoRA is the tool for that, and it is built from a piece already in place: the low-rank approximation of SVD, Eckart-Young low rank, and least squares in Mathematics. This section builds the LoRA layer, its two initializations (zero and PiSSA), freezing, merging for serving, and PEFT-compatible adapter files.

Beyond the SVD, you need only the Part 0 foundations: the Tensor, the op library, and Linear, Dropout, and Module. The reference implementation is python/tinyllm/obj/lora.py (LoRALinear, inject_lora, merge_lora, lora_state_dict, load_lora_state_dict, trainable_fraction), with the contract in course/contracts/py/tinyllm/obj/lora.pyi.

Learning objectives

  • Compute a LoRA forward pass and its merged weight by hand, including the scale s=α/rs = \alpha / r.
  • Explain why zero-initialized BB makes the adapted model equal the base bit for bit.
  • Derive PiSSA’s split of WW into a trainable top-rr part and a frozen residual.
  • Freeze a model so that only adapters (and an explicit head) train, while every weight stays in the checkpoint.
  • Merge adapters for serving and save them under PEFT’s key names.

Here is the notation for this section.

SymbolMeaningType / shape
WWthe base Linear’s weight, frozenfloat32[out, in]
bbthe base Linear’s bias, frozenfloat32[out]
xxone input rowfloat32[in]
rrthe adapter rank, 1≤r≤min⁡(in,out)1 \le r \le \min(\text{in}, \text{out})int
AAlora_A.weight, the down projectionfloat32[r, in]
BBlora_B.weight, the up projectionfloat32[out, r]
α\alphaalpha, the adapter’s scale knobfloat >0> 0
s=α/rs = \alpha / rscalingfloat
ΔW=sBA\Delta W = s B Athe update the adapter adds, rank at most rrfloat32[out, in]
U,S,V⊤U, S, V^\topthe SVD of WW: W=U diag(S) V⊤W = U\,\mathrm{diag}(S)\,V^\topas svd returns
WrW_rthe best rank-rr approximation of WW (Eckart-Young)[out, in]

A fine-tune changes WW into W+ΔWW + \Delta W. Hu et al. observed that the useful ΔW\Delta W of a fine-tune has low “intrinsic” rank, so they write it as a product ΔW=sBA\Delta W = s B A with rr much smaller than either dimension. The layer computes

y=Wx+b+s B(A x).y = W x + b + s\,B (A\,x).

The order of the product matters for cost. AxA x is rr numbers, so the adapter costs r(in+out)r(\text{in} + \text{out}) multiply-adds per row instead of in⋅out\text{in} \cdot \text{out}. The parameters are AA and BB, r(in+out)r(\text{in} + \text{out}) numbers per layer. For a 768×768768 \times 768 projection at r=8r = 8 that is 12 288 trainable numbers instead of 589 824, about 2%.

The scale s=α/rs = \alpha / r is a convention with a reason. With AA initialized at a fixed size, the update BAxB A x sums rr terms, so its size grows with rr. Dividing by rr keeps the adapter’s effective learning rate roughly independent of the rank, so α\alpha is tuned once.

LoRA’s dropout acts on the adapter’s input only: y=Wx+b+sBA dropout(x)y = W x + b + s B A\,\mathrm{dropout}(x). The frozen path must see exactly the base model’s input.

The update’s form is fixed; the next question is where AA and BB start.

With the default initialization, AA is drawn like any Linear weight and B=0B = 0. Then ΔW=0\Delta W = 0 exactly: the adapted model starts as the pretrained one, and sBAxs B A x is a vector of exact zeros, so yy is bit for bit the base output. The first gradient step moves BB only (∂y/∂A\partial y / \partial A contains BB, which is zero), and after that both.

PiSSA, from Meng et al., starts the adapter at the most important part of WW instead. With the SVD W=U diag(S) V⊤W = U\,\mathrm{diag}(S)\,V^\top and singular values in decreasing order, Eckart-Young says the best rank-rr approximation is Wr=U:,:r diag(S:r) V:,:r⊤W_r = U_{:, :r}\,\mathrm{diag}(S_{:r})\,V_{:, :r}^\top. low_rank(W, r) returns it as balanced factors P=U:,:rS:rP = U_{:, :r}\sqrt{S_{:r}} and Q=S:r V:,:r⊤Q = \sqrt{S_{:r}}\,V_{:, :r}^\top, with PQ=WrP Q = W_r. PiSSA sets

B=P/s,A=Q/s,W←W−Wr,B = P / \sqrt{s}, \qquad A = Q / \sqrt{s}, \qquad W \leftarrow W - W_r,

so sBA=Wrs B A = W_r and the frozen weight keeps only the residual. At step 0 the layer computes (W−Wr)x+Wrx=Wx(W - W_r)x + W_r x = W x, the base function again (to float32 rounding, since it is now a sum of two products). What changed is which directions train. The adapter now owns the top singular directions of WW, the ones a fine-tune most often needs to move, and PiSSA converges faster than zero-initialized LoRA in the paper’s experiments. Dividing by s\sqrt{s} is what makes sBAs B A come out as WrW_r and not sWrs W_r.

An adapter is only cheap if nothing else trains. Freezing is requires_grad = False on a registered parameter. The module system registers a Tensor when it is assigned with requires_grad set, and it stays registered afterwards. A frozen weight is therefore still in named_parameters and state_dict, so the checkpoint keeps it, but it produces no gradient: an op (from_op in the Tensor) records a vjp only when some input requires grad.

inject_lora freezes the whole model first, then wraps the targeted Linears. After it, the adapters are the only trainable parameters, and an optimizer built from p for p in model.parameters() if p.requires_grad holds AA and BB only. trainable_fraction counts elements: trainable over all registered, frozen included.

A LoRALinear reuses the base Linear’s own Tensors under the base’s names (weight, bias) and adds lora_A.weight and lora_B.weight. That keeps every base checkpoint key valid on the adapted model.

For serving, fold the update into the weight: W′=W+sBAW' = W + s B A, computed in float64 and stored in float32, then put the original Linear object back in its parent. The merged model has the base’s keys in the base’s order, no adapter left, and the same outputs as the adapted model up to float32 rounding (the two compute W′xW' x and Wx+sB(Ax)W x + s B (A x), which round differently). A merged model never runs the adapter again; forgetting to remove it counts the update twice.

Adapters are shared without the base, under PEFT’s names in adapter_model.safetensors: base_model.model.<module name>.lora_A.weight and .lora_B.weight. lora_state_dict writes those keys; load_lora_state_dict reads them back and refuses a mismatched file before copying anything.

Start with a forward pass and merge. Let W=(1234)W = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, b=(0.5,−0.5)b = (0.5, -0.5), r=1r = 1, α=2\alpha = 2, so s=2s = 2. Take A=(1,−1)A = (1, -1), B=(0.5,1)⊤B = (0.5, 1)^\top, and x=(2,1)x = (2, 1). The table follows the computation.

stepvalue
frozen path Wx+bW x + b(1⋅2+2⋅1,3⋅2+4⋅1)+b=(4,10)+(0.5,−0.5)=(4.5,9.5)(1 \cdot 2 + 2 \cdot 1, 3 \cdot 2 + 4 \cdot 1) + b = (4, 10) + (0.5, -0.5) = (4.5, 9.5)
AxA x2−1=12 - 1 = 1
B(Ax)B (A x)(0.5,1)(0.5, 1)
times s=2s = 2(1,2)(1, 2)
yy(5.5,11.5)(5.5, 11.5)
ΔW=sBA\Delta W = s B A2(0.5−0.51−1)=(1−12−2)2 \begin{pmatrix} 0.5 & -0.5 \\ 1 & -1 \end{pmatrix} = \begin{pmatrix} 1 & -1 \\ 2 & -2 \end{pmatrix}
merged W′W'(2152)\begin{pmatrix} 2 & 1 \\ 5 & 2 \end{pmatrix}, and W′x+b=(5,12)+b=(5.5,11.5)W' x + b = (5, 12) + b = (5.5, 11.5)

The merged layer gives the same output as the adapted one, as it must.

Now a PiSSA split. Let W=diag(3,1)W = \mathrm{diag}(3, 1), r=1r = 1, α=4\alpha = 4, so s=4s = 4. The SVD is U=V=IU = V = I, S=(3,1)S = (3, 1), so W1=diag(3,0)W_1 = \mathrm{diag}(3, 0), P=(3,0)⊤P = (\sqrt 3, 0)^\top, and Q=(3,0)Q = (\sqrt 3, 0). Divide each by s=2\sqrt s = 2: B=(3/2,0)⊤B = (\sqrt 3 / 2, 0)^\top, A=(3/2,0)A = (\sqrt 3 / 2, 0), and sBA=4⋅34diag(1,0)=diag(3,0)s B A = 4 \cdot \tfrac{3}{4} \mathrm{diag}(1, 0) = \mathrm{diag}(3, 0). The frozen residual is diag(0,1)\mathrm{diag}(0, 1). (The pair (−B,−A)(-B, -A) is the same split.)

class LoRALinear(Module):
def __init__(self, base: Linear, r: int, alpha: float, dropout: float = 0.0,
init: Literal["default", "pissa"] = "default", rng=None) -> None: ...
def delta_weight(self) -> NDArray: ... # s * B @ A, float32 [out, in]
def forward(self, x: Tensor) -> Tensor: ...
def inject_lora(model, target: Callable[[str, Module], bool], r: int, alpha: float,
dropout: float = 0.0, init="default", rng=None) -> list[str]: ...
def merge_lora(model) -> list[str]: ...
def lora_state_dict(model) -> dict[str, NDArray]: ... # PEFT key names
def load_lora_state_dict(model, sd) -> None: ...
def trainable_fraction(model) -> float: ...

inject_lora takes a predicate over module names and modules rather than a list of names, so callers can say “every q_proj and v_proj under the backbone” once and have it apply to any architecture.

The reasoning runs as follows.

  1. The goal is a fine-tune whose trainable state is small. If the useful update ΔW\Delta W has low rank, write it as BAB A with A∈Rr×inA \in \mathbb{R}^{r \times \text{in}} and B∈Rout×rB \in \mathbb{R}^{\text{out} \times r}: r(in+out)r(\text{in} + \text{out}) numbers instead of in⋅out\text{in} \cdot \text{out}.
  2. The base must not change, so WW and bb are frozen and the layer adds sB(Ax)s B (A x). Computing AxA x first keeps the cost at r(in+out)r(\text{in} + \text{out}) per row and never materializes BAB A.
  3. Fine-tuning should start from the pretrained function, so at default init ΔW=0\Delta W = 0. Setting B=0B = 0 (not AA) is the right zero: then AA is random and ∂L/∂B=s (∂L/∂y)(Ax)⊤\partial L / \partial B = s\,(\partial L/\partial y)(A x)^\top is non-zero, so training can start. With A=0A = 0 and BB random the same holds the other way, but the convention, and PEFT, use B=0B = 0.
  4. The size of BAxB A x grows with rr, so s=α/rs = \alpha / r keeps the effective step roughly rank-independent.
  5. PiSSA instead puts the best rank-rr part WrW_r into the adapter and freezes W−WrW - W_r. Eckart-Young says WrW_r comes from the top rr singular triples, which low_rank returns as balanced factors P,QP, Q; dividing each by s\sqrt s makes sBA=Wrs B A = W_r. In the worked example s=4s = 4, s=2\sqrt s = 2, and sBA=diag(3,0)s B A = \mathrm{diag}(3, 0).
  6. For checkpoint compatibility, the wrapped layer must still expose weight and bias under the old names, so a base checkpoint loads into an adapted model. The wrapper therefore re-registers the base’s own Tensors, frozen.
  7. Only adapters train and everything else is frozen: inject_lora freezes the whole model first, then wraps. A caller that adds a new head unfreezes it explicitly.
  8. Serving should not pay for the adapter, so merge W′=W+sBAW' = W + s B A and put the plain Linear back, so that the keys and module tree are the base’s again.

The module system registers a Tensor as a parameter only when it is assigned with requires_grad set. The helper uses that, then freezes:

def _register_frozen(owner, name, t):
"""Register t under name, then freeze it: L0.4 registers a parameter when
it is assigned with requires_grad True, and keeps it registered after."""
if t is None:
setattr(owner, name, None)
return
t.requires_grad = True
setattr(owner, name, t) # now in named_parameters and the state_dict
t.requires_grad = False # ... but no gradient, so out of the optimizer
t.grad = None
class LoRALinear(Module):
def __init__(self, base, r, alpha, dropout=0.0, init="default", rng=None):
super().__init__()
# ... base must be a Linear; 1 <= r <= min(in, out); alpha > 0; init known ...
out_f, in_f = base.weight.shape
self.in_f, self.out_f, self.r = in_f, out_f, int(r)
self.alpha = float(alpha)
self.scaling = self.alpha / self.r
# The base's own Tensors, registered here under the base's names and
# frozen: the checkpoint keys stay "<name>.weight" and "<name>.bias".
object.__setattr__(self, "_base", base) # kept for merging, NOT registered as a child
_register_frozen(self, "weight", base.weight)
_register_frozen(self, "bias", base.bias)
self.lora_A = Linear(in_f, self.r, bias=False, rng=rng) # A: a normal Linear init
self.lora_B = Linear(self.r, out_f, bias=False, rng=rng)
self.lora_B.weight.data[...] = 0.0 # B = 0: the adapted model starts as the base
self.lora_dropout = Dropout(dropout, rng=rng)
if init == "pissa":
# W = U S V^T. low_rank gives balanced factors P = U_r sqrt(S_r),
# Q = sqrt(S_r) V_r^T with P Q = W_r. Divide each by sqrt(s) so
# s B A = W_r exactly, and keep only the residual W - W_r frozen.
W = self.weight.data.astype(np.float64)
P, Q = low_rank(W, self.r)
root = math.sqrt(self.scaling)
self.lora_B.weight.data[...] = (P / root).astype(np.float32)
self.lora_A.weight.data[...] = (Q / root).astype(np.float32)
self.weight.data[...] = (W - P @ Q).astype(np.float32)

object.__setattr__ bypasses Module’s registration, so _base is not a child module and its Tensors are not listed twice. The SVD runs in float64, and the residual is written in place into the same Tensor the base Linear holds.

def forward(self, x):
y = F.matmul(x, F.transpose(self.weight, 0, 1))
if self.bias is not None:
y = y + self.bias
# Dropout on the adapter's input only: the frozen path sees x as it is.
h = self.lora_B(self.lora_A(self.lora_dropout(x))) # B (A x): r-wide in the middle
return y + h * self.scaling

With B=0B = 0, h is exact zeros, and y+0⋅sy + 0 \cdot s is yy bit for bit. The bitwise-equal start is a consequence of floating point adding exact zeros, not of a tolerance.

def inject_lora(model, target, r, alpha, dropout=0.0, init="default", rng=None):
# A LoRALinear's own lora_A and lora_B are never adapted again.
inside = [n + "." for n, _ in _lora_modules(model)]
chosen = [
n for n, m in list(model.named_modules())
if n and isinstance(m, Linear) and not any(n.startswith(p) for p in inside) and target(n, m)
]
if not chosen:
raise ValueError("inject_lora: target matched no Linear")
# Freeze everything first; the adapters built below are the only
# trainable parameters (a caller may unfreeze a head afterwards).
for p in model.parameters():
p.requires_grad = False
p.grad = None
for n in chosen:
parent, attr = _resolve(model, n) # walk the dotted name to the parent module
setattr(parent, attr, LoRALinear(getattr(parent, attr), r, alpha, dropout, init, rng))
return chosen

The list of targets is computed before any replacement, so wrapping does not change what is being iterated. Freezing happens before wrapping, so the new lora_A and lora_B (created trainable) are the only parameters with requires_grad.

def merge_lora(model):
merged = []
for n, m in _lora_modules(model):
base = m._base
W = m.weight.data.astype(np.float64) # for PiSSA, this is the residual
base.weight.data[...] = (W + m.delta_weight().astype(np.float64)).astype(np.float32)
parent, attr = _resolve(model, n)
setattr(parent, attr, base) # the plain Linear again: no adapter left
merged.append(n)
return merged

delta_weight computes sBAs B A in float64 and returns float32. Because m.weight and base.weight are the same Tensor, the merged weight is W+sBAW + s B A both in the default case, where WW is the original, and for PiSSA, where it is W−Wr+WrW - W_r + W_r up to rounding. Putting base back restores the original module and therefore the original key order.

PEFT_PREFIX = "base_model.model."
def lora_state_dict(model):
out = {}
for n, m in _lora_modules(model):
out[f"{PEFT_PREFIX}{n}.lora_A.weight"] = m.lora_A.weight.data.copy()
out[f"{PEFT_PREFIX}{n}.lora_B.weight"] = m.lora_B.weight.data.copy()
return out
def load_lora_state_dict(model, sd):
own = lora_state_dict(model)
missing = sorted(set(own) - set(sd))
unexpected = sorted(set(sd) - set(own))
if missing or unexpected: # checked before anything is copied
raise KeyError(f"adapter mismatch: missing {missing}, unexpected {unexpected}")
# ... copy each array into its adapter, checking shapes ...
def trainable_fraction(model):
total = trainable = 0
for _, p in model.named_parameters(): # frozen parameters are still listed
total += p.data.size
trainable += p.data.size if p.requires_grad else 0
# ... a model with no parameters raises ...
return trainable / total

The full solution is in lora.py.

Per adapted layer, LoRA stores r(in+out)r(\text{in} + \text{out}) parameters, gradients, and two AdamW moments, against in⋅out\text{in} \cdot \text{out} for a full fine-tune, and the forward pass adds r(in+out)r(\text{in} + \text{out}) multiply-adds per row. PiSSA adds one SVD per layer at injection, O(in⋅out⋅min⁡(in,out))O(\text{in} \cdot \text{out} \cdot \min(\text{in}, \text{out})), paid once.

The solution wraps rather than subclasses: replacing the Linear with a wrapper that reuses its Tensors keeps every base key valid and lets merge_lora restore the exact original object. It freezes the whole model rather than only the wrapped layers, because otherwise embeddings, norms, and untargeted Linears would still train, and the “small” fine-tune would hold a full optimizer state. It merges in float64, so the merged weight differs from the unmerged computation only by the final rounding. The tradeoff accepted is that a rank-rr update cannot express every fine-tune; for this chapter’s classifier at r=8r = 8 it is enough, and the full-rank alternative costs about 50 times more trainable state.

A correct solution has to pass these checks.

CaseKind of checkChecksWhy it matters downstream
hand-worked forward and mergeunity=(5.5,11.5)y = (5.5, 11.5) before and after merging, W′=[[2,1],[5,2]]W' = [[2, 1], [5, 2]]everyone agrees on the formula and on ss
hand-worked PiSSA splitunitBB, AA, and the residual diag(0,1)\mathrm{diag}(0, 1)the PiSSA split, sign aside
default init equals the base bit for bitdifferentialadapted outputs equal the base’s bit for bit; B=0B = 0, A≠0A \ne 0fine-tuning starts from the pretrained function
scaling is α/r\alpha / runits=α/rs = \alpha / r and ΔW=sBA\Delta W = s B A for four (r,α)(r, \alpha)one α\alpha works across ranks
only adapter parameters get gradientspropertyflags and gradients: frozen weight and bias get nonethe optimizer state is the adapter’s only
injection freezes everything elsepropertyembeddings, norms, untargeted Linears frozen; a target matching nothing raisesLoRA trains adapters, nothing else
adapter gradientsgradcheck∂/∂A\partial / \partial A and ∂/∂B\partial / \partial B against central differencesthe gradients the classifier trains with
PiSSA reproduces the basedifferentialPiSSA outputs equal the base’s within float32step 0 is still the pretrained model
PiSSA’s adapter is the top singular partgoldensBA=Wrs B A = W_r from LAPACK; BB‘s columns are ±Sj/s uj\pm\sqrt{S_j / s}\,u_jPiSSA’s point: train the principal directions
merged equals unmergeddifferentialmerged plain Linears give the adapted outputs within 1e-5, default and PiSSAserving pays nothing for the adapter
merging restores the base keyspropertysame keys, same order as before injection; with B=0B = 0 the same valuesevery loader reads a merged checkpoint
PEFT key namesgoldenbase_model.model.q_proj.lora_A.weight and friends, shapes [r,in][r, \text{in}] and [out,r][\text{out}, r]adapters move between tools
adapter roundtrippropertyan adapter file restores the adapter; wrong keys fail before copyingresuming and sharing adapters
dropout only on the adapter pathpropertywith B=0B = 0 dropout changes nothing; in eval mode it is the identitythe frozen path sees the true input
trainable fractionunit16 trainable elements out of the totalthe chapter’s “under 5% trainable” target
bad argumentsboundaryrank bounds, α≤0\alpha \le 0, unknown init, a non-Linear basecaller bugs fail loudly

The model tests in test_lora.py use numpy itself as the oracle: xW⊤+b+s xA⊤B⊤x W^\top + b + s\,x A^\top B^\top, LAPACK’s np.linalg.svd for PiSSA, and float64 finite differences for the gradients.

Most LoRA bugs either start the fine-tune from a damaged model or quietly train far more than the adapters.

PitfallSymptomHow the solution avoids it
scaling by α\alpha instead of α/r\alpha / ra learning rate that works at r=4r = 4 diverges at r=16r = 16self.scaling = self.alpha / self.r
a random BB at default initthe “fine-tune” starts from a damaged model; step-0 loss above the base’sself.lora_B.weight.data[...] = 0.0
the wrapped weight left trainable, or only the wrapped layers frozenthe whole model trains: optimizer memory and checkpoints as large as a full fine-tune_register_frozen for weight and bias; inject_lora freezes every parameter first
PiSSA without the residual, or without dividing by s\sqrt sstep 0 computes W+WrW + W_r or W−Wr+sWrW - W_r + s W_r: not the base modelthe frozen weight becomes W - P @ Q; both factors are divided by sqrt(scaling)
merging without ss, or leaving the adapter in placemerged outputs differ, or the update is counted twicedelta_weight includes scaling; merge_lora puts the plain Linear back
adapter keys without PEFT’s prefix; dropout on the frozen pathadapters that no other tool loads; a noisy base model in trainingkeys start with base_model.model.; dropout wraps only the input of lora_A

Tip: trainable_fraction is the cheapest LoRA test there is. If it reports more than a few percent after inject_lora, something other than the adapters is still trainable.

The fine-tuning heads use lora_classifier to adapt a classifier’s attention queries and values while keeping the new head trainable. Later, supervised fine-tuning of the chat model trains LoRA adapters (optional). A natural extension is multi-LoRA serving, in which the engine serves many adapters over one base, unmerged.

The production tools build on the same core. Hugging Face PEFT’s LoraConfig and get_peft_model (peft/tuners/lora/layer.py, peft/tuners/lora/model.py) add adapters for Conv1D and embeddings, several named adapters per layer, modules_to_save, and per-module rank patterns. PEFT’s init_lora_weights="pissa" and "pissa_niter_4" use a fast randomized SVD for large weights, alongside the OLoRA, LoftQ, and EVA initializations. Its merge_and_unload() and add_weighted_adapter merge several adapters with weights (TIES, DARE). vLLM (vllm/lora/) and S-LoRA serve thousands of adapters over one base, batched with custom kernels (Punica SGMV). And QLoRA and DoRA put adapters over a 4-bit base or split WW into magnitude and direction.

Further reading:

  • Hu et al., “LoRA: Low-Rank Adaptation of Large Language Models” (2021), sections 4 and 7.
  • Meng, Wang, and Zhang, “PiSSA: Principal Singular Values and Singular Vectors Adaptation” (2024), sections 3 and 4.
  • Aghajanyan et al., “Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-Tuning” (2020).
  • Sheng et al., “S-LoRA” (2023).
  • Dettmers et al. (2023), QLoRA; Liu et al. (2024), DoRA.
  • LoRA: a frozen Linear plus a trainable low-rank update sBAs B A.
  • Rank rr: the inner dimension of the adapter, bounding the rank of ΔW\Delta W.
  • Scaling s=α/rs = \alpha / r: the multiplier on the adapter output that keeps the effective step rank-independent.
  • PiSSA: initializing the adapter at the top-rr singular part of WW and freezing the residual.
  • Merging: folding sBAs B A into WW and restoring the plain Linear for serving.
  • A LoRA layer computes Wx+b+s BAxW x + b + s\,B A x with the base WW frozen; at default init B=0B = 0, so the adapted model equals the base bit for bit.
  • The scale is s=α/rs = \alpha / r, not α\alpha: doubling the rank at a fixed α\alpha halves each direction’s step.
  • Only AA and BB get gradients; the frozen weight stays in the checkpoint but out of the optimizer.
  • PiSSA starts the adapter at the top-rr singular part of WW and freezes the residual, so step 0 still computes the base function.
  • Merging folds sBAs B A into WW and puts the plain Linear back: same outputs, same keys, no serving cost.
  1. Why is BB set to zero and not AA?
    AnswerEither makes $\Delta W = 0$. With $B = 0$ and $A$ random, the first gradient reaches $B$ (it is proportional to $A x$, which is non-zero), so training starts; $A$ starts moving once $B$ is non-zero. This is the LoRA paper's and PEFT's convention, so adapters are compatible.
  2. Why does PiSSA divide both factors by s\sqrt s?
    AnswerThe layer multiplies $B A$ by $s$. `low_rank` returns $P Q = W_r$; with $B = P/\sqrt s$ and $A = Q/\sqrt s$, $s B A = W_r$ exactly. Without the division the adapter would contribute $s W_r$, and step 0 would not be the base function.
  3. A frozen weight is still in state_dict. Why does that not make it trainable?
    AnswerRegistration and training are separate. The weight is registered (so it is saved and loaded) but `requires_grad` is False, so no op records a vjp for it and an optimizer built from parameters that require grad never sees it.
  4. What goes wrong if merge_lora folds sBAs B A into WW but leaves the LoRALinear in place?
    AnswerThe forward would compute $(W + sBA)x + sBAx$: the update counted twice. Swapping the plain `Linear` back removes the adapter path.
  5. Why is dropout applied only to the adapter’s input?
    AnswerThe frozen path must compute exactly what the base model computes. Dropping inputs there would add noise to the pretrained function in training; on the adapter path it regularizes only what is being learned.