Skip to content
class

Linear

extendsBOFTLayer
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 BOFT rotation of its input and a scale of its output: y=s⊙(WM⊤x)+by = s \odot (W M^\top x) + b.

boft_s is (out_features, 1).

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of BOFTLayer.
adapter_namestr
Name of the first butterfly.
Block size or count, butterfly factors, dropout, init_weights.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import BOFTConfig
>>> from lucid.peft.tuners.boft import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", BOFTConfig(boft_block_size=4, target_modules=["x"]))
>>> tuple(layer.boft_R["default"].shape), tuple(layer.boft_s["default"].shape)
((1, 2, 4, 4), (4, 1))
>>> x = lucid.randn(3, 8)
>>> bool(lucid.allclose(layer(x), base(x), atol=1e-6))   # identity rotation, unit scale
True

Used by 1