Skip to content
class

Linear

extendsTinyLoraLayer
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 TinyLoRA update: y=Wx+b+BRA drop(x)y = W x + b + B R A\,\mathrm{drop}(x), R=∑iviPiR = \sum_i v_i P_i.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of TinyLoraLayer.
adapter_namestr
Name of the adapter created at once.
The adapter's config.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import TinyLoraConfig
>>> from lucid.peft.tuners.tinylora import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", TinyLoraConfig(r=2, u=3, target_modules=["x"]))
>>> tuple(layer.tinylora_A["default"].shape), tuple(layer.tinylora_B["default"].shape)
((2, 8), (4, 2))
>>> x = lucid.randn(2, 8)
>>> bool((layer(x) == base(x)).all().item())   # v starts at zero
True

Used by 1