Implementing kernel
C++ engine symbols that back this Python API.An nn.Linear with a SHiRA update: .
Stackable: the sparse update runs beside the layer below and merges after it.
Parameters
base_ layernn.LinearThe layer to adapt; the other parameters are those of
ShiraLayer.adapter_ namestrThe first adapter's name.
configShiraConfigIts
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