Skip to content
class

Linear

extendsOSFLayer
Linear(base_layer: nn.Module, adapter_name: str, config: C)

Implementing kernel

C++ engine symbols that back this Python API.

An nn.Linear whose low singular directions train: y=(W+UΣV⊤−U0Σ0V0⊤) x+by = (W + U\Sigma V^\top - U^0\Sigma^0 V^{0\top})\,x + b.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of OSFLayer.
adapter_namestr
Name of the first adapter.
configOSFConfig
effective_rank (a count, a fraction of the smaller side, or None for half of it) and init_weights.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import OSFConfig
>>> from lucid.peft.tuners.osf import Linear
>>> base = nn.Linear(8, 6)
>>> layer = Linear(base, "default", OSFConfig(effective_rank=2, target_modules=["x"]))
>>> {name: tuple(p.shape) for name, p in layer.osf_svd_params["default"].items()}
{'U_low': (6, 4), 'S_low': (4,), 'V_low': (4, 8)}
>>> x = lucid.randn(3, 8)
>>> bool((layer(x) == base(x)).all().item())   # the trained part starts as the weight's own
True

Used by 1