Skip to content
class

Linear

extendsIA3Layer
Linear(base_layer: nn.Module, adapter_name: str, config: IA3Config, is_feedforward: bool = False)

Implementing kernel

C++ engine symbols that back this Python API.

An nn.Linear with an (IA)^3 vector: y=ℓ⊙(Wx+b)y = \ell \odot (W x + b), or y=W(ℓ⊙x)+by = W(\ell \odot x) + b.

The vector is (out_features, 1) for an output-side layer and (1, in_features) for a feed-forward one, as in the reference; merging multiplies it into the weight's rows or columns.

Stackable: the vector scales the output (or input) of whatever layer it stands on, and merging multiplies it into the weight the layers below have already folded.

Parameters

base_layernn.Linear
The layer to adapt; kept as base_layer, its parameters shared.
adapter_namestr
Name of the adapter, the key in ia3_l.
configIA3Config
The adapter's config.
is_feedforwardbool= False
Scale the input instead of the output.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import IA3Config
>>> from lucid.peft.tuners.ia3 import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", IA3Config(target_modules=["x"]))
>>> tuple(layer.ia3_l["default"].shape)
(4, 1)
>>> x = lucid.randn(3, 8)
>>> bool((layer(x) == base(x)).all().item())   # the vector starts at ones
True

Used by 1