Skip to content
class

Linear

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

Implementing kernel

C++ engine symbols that back this Python API.

An nn.Linear whose output a RoAd rotation turns: y=R (Wx+b)y = R\,(W x + b).

Stackable: the rotation turns the output of whatever layer it stands on.

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of RoadLayer.
adapter_namestr
Name of the first adapter.
variant, group_size and init_weights.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import RoadConfig
>>> from lucid.peft.tuners.road import Linear
>>> base = nn.Linear(4, 8)
>>> layer = Linear(base, "default", RoadConfig(group_size=4, target_modules=["x"]))
>>> tuple(layer.road_theta["default"].shape), tuple(layer.road_alpha["default"].shape)
((4,), (4,))
>>> x = lucid.randn(3, 4)
>>> bool((layer(x) == base(x)).all().item())   # angle 0 and scale 1 start at the identity
True

Used by 1