Skip to content
class

Linear

extendsGloraLayer
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 GLoRA update: y=(W+WA+B) x+b+bD+E+WCy = (W + W A + B)\,x + b + b D + E + W C.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of GloraLayer.
adapter_namestr
Name of the first adapter.
r, config_A_B, config_C, config_D_E and init_weights.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import GloraConfig
>>> from lucid.peft.tuners.glora import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", GloraConfig(r=2, target_modules=["x"]))
>>> sorted(layer.glora_A["default"].state_dict()), tuple(layer.glora_C["default"].Xu.shape)
(['Xd', 'Xu'], (2, 1))
>>> x = lucid.randn(3, 8)
>>> bool((layer(x) == base(x)).all().item())   # the supports start at zero
True

Used by 1