Skip to content
class

Embedding

extendsTinyLoraLayer
Embedding(base_layer: nn.Module, adapter_name: str, config: C)

Implementing kernel

C++ engine symbols that back this Python API.

An nn.Embedding with a TinyLoRA update: the table EE is looked up as E+BRAE + B R A.

The frozen SVD is that of the table, (num_embeddings, embedding_dim): BB has one row per token and AA one column per feature, and the update of a token is the row of BB it indexes, through RR and AA. The dropout acts on the looked-up rows.

Parameters

base_layernn.Embedding
The layer to adapt; the other parameters are those of TinyLoraLayer.
adapter_namestr
Name of the adapter created at once.
The adapter's config.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import TinyLoraConfig
>>> from lucid.peft.tuners.tinylora import Embedding
>>> base = nn.Embedding(10, 4)
>>> layer = Embedding(base, "default", TinyLoraConfig(r=2, u=3, target_modules=["x"]))
>>> tuple(layer.tinylora_A["default"].shape), tuple(layer.tinylora_B["default"].shape)
((2, 4), (10, 2))
>>> ids = lucid.tensor([[1, 2, 3]])
>>> bool((layer(ids) == base(ids)).all().item())   # v starts at zero
True

Used by 1