Skip to content
class

Linear

extendsPeanutLayer
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 PEANuT update: y=(W+f(W;θ)) x+by = (W + f(W;\theta))\,x + b.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of PeanutLayer.
adapter_namestr
Name of the first adapter.
r, depth, act_fn, scaling and init_weights.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import PeanutConfig
>>> from lucid.peft.tuners.peanut import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", PeanutConfig(r=2, depth=1, target_modules=["x"]))
>>> sorted(layer.peanut_A["default"].state_dict()), tuple(layer.peanut_B["default"].weight.shape)
(['weight'], (4, 2))
>>> x = lucid.randn(3, 8)
>>> bool((layer(x) == base(x)).all().item())   # B starts at zero
True

Used by 1