Skip to content
class

Linear

extendsDeftLayer
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 DEFT update: y=((I−Pproj) W+QPR) x+by = ((I - P_{proj})\,W + Q_P R)\,x + b.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of DeftLayer.
adapter_namestr
Name of the first adapter.
r, decomposition_method, init_scale, alpha, para, deft_dropout and init_weights.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import DeftConfig
>>> from lucid.peft.tuners.deft import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", DeftConfig(r=2, target_modules=["x"]))
>>> tuple(layer.deft_P["default"].shape), tuple(layer.deft_R["default"].shape)
((4, 2), (2, 8))
>>> x = lucid.randn(3, 8)
>>> bool(lucid.allclose(layer(x), base(x), atol=1e-5))   # R starts where the update is zero
True

Used by 1