Skip to content
class

Linear

extendsPolyLayer
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 task-routed mixture of low-rank skills.

Parameters

base_layernn.Linear
The layer to adapt; kept as base_layer, its parameters shared.
adapter_namestr
Name of the adapter, the key in poly_lora_A and the other tables.
The adapter's config.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import PolyConfig
>>> from lucid.peft.tuners.poly import Linear
>>> base = nn.Linear(8, 4)
>>> layer = Linear(base, "default", PolyConfig(r=2, n_tasks=2, target_modules=["x"]))
>>> x = lucid.randn(3, 5, 8)
>>> out = layer(x, task_ids=lucid.tensor([0, 1, 0]))
>>> bool((out == base(x)).all().item())   # B starts at zero
True

Used by 1