Skip to content
class

SVDLinear

extendsAdaLoraLayer
SVDLinear(base_layer: nn.Module, adapter_name: str, config: AdaLoraConfig, r: int = 0, lora_alpha: float = 1)

An nn.Linear with an SVD-parameterised update: y=Wx+b+αranknum P diag(λ) Q drop(x)y = W x + b + \tfrac{\alpha}{\mathrm{ranknum}}\,P\,\mathrm{diag}(\lambda)\,Q\,\mathrm{drop}(x).

The update is applied as three small products, never as an (out, in) matrix, so a layer pruned to a few triplets costs a few triplets. Stackable: the triplets' update is added to the output of whichever layer it stands on.

Parameters

base_layernn.Linear
The layer to adapt; kept as base_layer, its parameters shared.
adapter_namestr
Name of the adapter, the key in every table.
The adapter's config.
rint= 0
Initial rank.
lora_alphafloat= 1
Numerator of the scale.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft.tuners.adalora import AdaLoraConfig
>>> from lucid.peft.tuners.adalora import SVDLinear
>>> base = nn.Linear(8, 4)
>>> layer = SVDLinear(base, "default", AdaLoraConfig(total_step=10), r=3, lora_alpha=6)
>>> tuple(layer.lora_A["default"].shape), tuple(layer.lora_E["default"].shape)
((3, 8), (3, 1))
>>> x = lucid.randn(2, 8)
>>> bool((layer(x) == base(x)).all().item())   # the singular values start at zero
True

Used by 1