Skip to content
class

Linear

extendsLoHaLayer
Linear(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: y=Wx+b+s ((W1aW1b)⊙(W2aW2b)) xy = W x + b + s\,((W_{1a}W_{1b}) \odot (W_{2a}W_{2b}))\,x.

Stackable: the Hadamard update runs beside the layer below and merges after it.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of LoHaLayer.
adapter_namestr
Name of the adapter, the key in every table.
The adapter's config (dropouts, init_weights, use_effective_conv2d).
rint= 0
Rank. The default is the reference's and is refused: pass a positive rank.
alphafloat= 0.0
Numerator 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

Used by 1

Instance methods

1
fn

supports_lora_conversion

→bool
supports_lora_conversion(adapter_name: str = 'default')

Whether adapter_name on this LoHa linear layer can be converted to LoRA.