Skip to content
class

Linear

extendsHRALayer
Linear(base_layer: nn.Module, adapter_name: str, config: C)

Implementing kernel

C++ engine symbols that back this Python API.

An nn.Linear with HRA reflections of its input: y=(WD) x+by = (W D)\,x + b.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of HRALayer.
adapter_namestr
Name of the first chain.
configHRAConfig
r, apply_GS and init_weights.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import HRAConfig
>>> from lucid.peft.tuners.hra import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", HRAConfig(r=2, target_modules=["x"]))
>>> tuple(layer.hra_u["default"].shape)
(8, 2)
>>> x = lucid.randn(3, 8)
>>> bool(lucid.allclose(layer(x), base(x), atol=1e-6))   # equal pairs of vectors cancel
True

Used by 1