Skip to content
class

Linear

extendsFourierFTLayer
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 FourierFT update: y=Wx+b+ΔW xy = W x + b + \Delta W\,x.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of FourierFTLayer.
adapter_namestr
Name of the adapter created at once.
The adapter's config (its n_frequency is this layer's).

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import FourierFTConfig
>>> from lucid.peft.tuners.fourierft import Linear
>>> base = nn.Linear(8, 4)
>>> config = FourierFTConfig(n_frequency=5, init_weights=True, target_modules=["x"])
>>> layer = Linear(base, "default", config)
>>> tuple(layer.fourierft_spectrum["default"].shape)
(5,)
>>> x = lucid.randn(3, 8)
>>> bool((layer(x) == base(x)).all().item())   # the coefficients start at zero
True

Used by 1