Skip to content
class

Linear

extendsBeftLayer
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 BEFT bias: y=Wx+b+βy = W x + b + \beta.

Stackable: the bias reads nothing of the weight, so the layer may stand on another method's layer (and one may stand on it).

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of BeftLayer.
adapter_namestr
Name of the first adapter.
init_weights chooses a zero start (the default) or a standard normal draw.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import BeftConfig
>>> from lucid.peft.tuners.beft import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", BeftConfig(target_modules=["x"]))
>>> tuple(layer.beft_bias["default"].shape)
(1, 4)
>>> x = lucid.randn(3, 8)
>>> bool((layer(x) == base(x)).all().item())   # the bias starts at zero
True

Used by 1