Skip to content
class

Linear

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

Implementing kernel

C++ engine symbols that back this Python API.

An nn.Linear with a Lily update: y=Wx+b+s (xA)∑eSeBey = W x + b + s\,(x A) \sum_e S_e B_e.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of LilyLayer.
adapter_namestr
Name of the adapter created at once.
The adapter's config.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import LilyConfig
>>> from lucid.peft.tuners.lily import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", LilyConfig(r=3, num_B=2, target_modules=["x"]))
>>> tuple(layer.lily_A["default"].weight.shape), tuple(layer.lily_B["default"].weight.shape)
((3, 8), (6, 4))
>>> x = lucid.randn(2, 8)
>>> bool((layer(x) == base(x)).all().item())   # the up-projections start at zero
True

Used by 1