Skip to content
class

Linear

extendsPveraLayer
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 PVeRA update: y=Wx+b+λb⊙B zy = W x + b + \lambda_b \odot B\,z, zz the Gaussian latent.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of PveraLayer.
adapter_namestr
Name of the adapter created at once.
The adapter's config.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import PveraConfig
>>> from lucid.peft.tuners.pvera import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", PveraConfig(r=3, target_modules=["x"]))
>>> tuple(layer.pvera_lambda_d["default"].shape), tuple(layer.pvera_lambda_b["default"].shape)
((6,), (4,))
>>> x = lucid.randn(2, 8)
>>> bool((layer(x) == base(x)).all().item())   # lambda_b starts at zero
True

Used by 1