class
Linear
extends
LoHaLayerLinear(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 LoHa update: .
Stackable: the Hadamard update runs beside the layer below and merges after it.
Parameters
base_ layernn.LinearThe layer to adapt; the other parameters are those of
LoHaLayer.adapter_ namestrName of the adapter, the key in every table.
configLoHaConfigThe adapter's config (dropouts,
init_weights, 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 LoHaConfig
>>> from lucid.peft.tuners.loha import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", LoHaConfig(target_modules=["x"]), r=2, alpha=4)
>>> layer.scaling["default"], tuple(layer.hada_w1_a["default"].shape)
(2.0, (4, 2))
>>> x = lucid.randn(3, 8)
>>> bool((layer(x) == base(x)).all().item()) # hada_w2_b starts at zero
True