Skip to content
class

Linear

extendsLoKrLayer
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 LoKr update: y=Wx+b+s (W1⊗W2) xy = W x + b + s\,(W_1 \otimes W_2)\,x.

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

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of LoKrLayer.
adapter_namestr
Name of the adapter, the key in every table.
The adapter's config (dropouts, init_weights, decompose_both, decompose_factor, 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 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

Used by 1

Instance methods

1
fn

supports_lora_conversion

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

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