Skip to content
class

Linear

extendsSupertuningLayer
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 Super-Tuning update: y=(W+Δ+αrBA) x+by = (W + \Delta + \tfrac{\alpha}{r} B A)\,x + b.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of SupertuningLayer.
adapter_namestr
Name of the first adapter.
sparsity, select_top, the LoRA options and save_precomputed_indices.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import SupertuningConfig
>>> from lucid.peft.tuners.supertuning import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", SupertuningConfig(sparsity=0.75, target_modules=["x"]))
>>> tuple(layer.supertuning_values["default"].shape), tuple(layer.supertuning_indices["default"].shape)
((8,), (8,))
>>> x = lucid.randn(3, 8)
>>> bool((layer(x) == base(x)).all().item())   # the values start at zero
True

Used by 1