Skip to content
class

Linear

extendsHiraLayer
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 HiRA update: y=(W+W⊙BA) x+by = (W + W \odot BA)\,x + b.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of HiraLayer.
adapter_namestr
Name of the first adapter.
r, hira_dropout and init_weights (the per-module ranks are the tuner's to resolve).

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import HiraConfig
>>> from lucid.peft.tuners.hira import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", HiraConfig(r=2, target_modules=["x"]))
>>> tuple(layer.hira_A["default"].shape), tuple(layer.hira_B["default"].shape)
((2, 8), (4, 2))
>>> x = lucid.randn(3, 8)
>>> bool((layer(x) == base(x)).all().item())   # B starts at zero
True

Used by 1