Skip to content
class

Linear

extendsShiraLayer
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 SHiRA update: y=(W+s Δ) x+by = (W + s\,\Delta)\,x + b.

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

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of ShiraLayer.
adapter_namestr
The first adapter's name.
Its mask_fn picks the entries; r sizes them.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft.tuners.shira import Linear, ShiraConfig
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", ShiraConfig(r=1, random_seed=3, target_modules=["x"]))
>>> tuple(layer.shira_weight["default"].shape), tuple(layer.shira_indices["default"].shape)
((12,), (2, 12))
>>> x = lucid.randn(2, 8)
>>> bool((layer(x) == base(x)).all().item())   # the values start at zero
True

Used by 1