Skip to content
class

Linear

extendsC3ALayer
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 block-circulant update: y=Wx+b+C(w) x/diny = W x + b + \mathcal C(w)\,x / d_{in}.

Parameters

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

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft.tuners.c3a import C3AConfig, Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", C3AConfig(block_size=4, init_weights=True, target_modules=["x"]))
>>> tuple(layer.c3a_kernel["default"].shape)
(1, 2, 4)
>>> x = lucid.randn(2, 8)
>>> bool((layer(x) == base(x)).all().item())   # the kernels start at zero
True

Used by 1