class
Linear
extends
LoKrLayerLinear(base_layer: nn.Module, adapter_name: str, config: _LycorisConfig, r: int = 0, alpha: float = 0.0)Implementing kernel
C++ engine symbols that back this Python API.An nn.Linear with a LoKr update: .
Stackable: the Kronecker update runs beside the layer below and merges after it.
Parameters
base_ layernn.LinearThe layer to adapt; the other parameters are those of
LoKrLayer.adapter_ namestrName of the adapter, the key in every table.
configLoKrConfigThe adapter's config (dropouts,
init_weights, decompose_both,
decompose_factor, use_effective_conv2d).rint= 0Rank. The default is the reference's and is refused: pass a positive rank.
alphafloat= 0.0Numerator of the scale.
Examples
>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import LoKrConfig
>>> from lucid.peft.tuners.lokr import Linear
>>> base = nn.Linear(8, 6)
>>> layer = Linear(base, "default", LoKrConfig(target_modules=["x"]), r=2, alpha=4)
>>> tuple(layer.lokr_w1["default"].shape), tuple(layer.lokr_w2["default"].shape)
((2, 2), (3, 4))
>>> x = lucid.randn(3, 8)
>>> bool((layer(x) == base(x)).all().item()) # lokr_w1 starts at zero
True