Skip to content
class

Linear

extendsAdamssLayer
Linear(base_layer: nn.Module, adapter_name: str, config: C)

Implementing kernel

C++ engine symbols that back this Python API.

An nn.Linear whose rows are split into subspaces, each with its own low-rank update.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of AdamssLayer.
adapter_namestr
Name of the first adapter.
The rank, the number of subspaces and their rank, the initialisation and the seed.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import AdamssConfig
>>> from lucid.peft.tuners.adamss import Linear
>>> base = nn.Linear(8, 6)
>>> layer = Linear(base, "default", AdamssConfig(r=4, num_subspaces=2, target_modules=["x"]))
>>> layer.num_subspaces["default"], sum(b.shape[0] for b in layer.adamss_B["default"].parameters())
(2, 6)
>>> x = lucid.randn(3, 8)
>>> bool((layer(x) == base(x)).all().item())   # every B starts at zero
True

Used by 1