Skip to content
class

Linear

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

Parameters

base_layernn.Linear
The layer to adapt; the other parameters are those of DeloraLayer.
adapter_namestr
Name of the first adapter.
r, delora_lambda, module_dropout and init_weights (the per-module patterns are the tuner's to resolve).

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import DeloraConfig
>>> from lucid.peft.tuners.delora import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", DeloraConfig(r=2, target_modules=["x"]))
>>> tuple(layer.delora_A["default"].shape), tuple(layer.delora_B["default"].shape)
((2, 8), (4, 2))
>>> x = lucid.randn(3, 8)
>>> bool((layer(x) == base(x)).all().item())   # B starts at zero
True

Used by 1