class
SVDLinear
extends
AdaLoraLayerSVDLinear(base_layer: nn.Module, adapter_name: str, config: AdaLoraConfig, r: int = 0, lora_alpha: float = 1)An nn.Linear with an SVD-parameterised update: .
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.LinearThe layer to adapt; kept as
base_layer, its parameters shared.adapter_ namestrName of the adapter, the key in every table.
configAdaLoraConfigThe adapter's config.
rint= 0Initial rank.
lora_ alphafloat= 1Numerator 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