Skip to content
class

Linear

extendsFrodLayer
Linear(base_layer: nn.Module, adapter_name: str, config: FrodConfig, deferred: bool = False)

Implementing kernel

C++ engine symbols that back this Python API.

An nn.Linear whose weight is re-expressed as U(Σ+S)V⊤U(\Sigma + S)V^\top: y=x W′⊤+by = x\,W'^\top + b.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of FrodLayer.
adapter_namestr
Name of the first adapter.
sparse_rate, projection_prng_key, regularization_alpha, frod_dropout, init_weights.
deferredbool= False
The tuner will bind the layer to its tables and start the adapter; nothing is derived yet.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import FrodConfig
>>> from lucid.peft.tuners.frod import Linear
>>> base = nn.Linear(6, 4)
>>> layer = Linear(base, "default", FrodConfig(sparse_rate=0.5, target_modules=["x"]))
>>> tuple(layer.frod_lambda_l["default"].shape), tuple(layer.frod_lambda_s_values["default"].shape)
((6,), (18,))
>>> x = lucid.randn(3, 6)
>>> bool(lucid.allclose(layer(x), base(x), atol=1e-5))   # S starts at zero: W' = W up to rounding
True

Used by 1