Skip to content
class

Linear

extendsPsoftLayer
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 PSOFT update: y=(W+UrΣr(C−I)Vr⊤) x+by = (W + U_r\Sigma_r (C - I) V_r^\top)\,x + b.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of PsoftLayer.
adapter_namestr
Name of the first adapter.
The rank, scale, SVD options, the options of the rotation and init_weights.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import PsoftConfig
>>> from lucid.peft.tuners.psoft import Linear
>>> base = nn.Linear(8, 6)
>>> layer = Linear(base, "default", PsoftConfig(r=3, target_modules=["x"]))
>>> sorted(layer.psoft_R["default"].state_dict()), tuple(layer.psoft_R["default"].weight.shape)
(['vector_a', 'vector_b', 'weight'], (3,))
>>> x = lucid.randn(4, 8)
>>> bool((layer(x) == base(x)).all().item())   # R = I and the vectors are one
True

Used by 1