Skip to content
class

Embedding

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

Implementing kernel

C++ engine symbols that back this Python API.

An nn.Embedding whose chosen rows are trained: F.embedding(x, E').

Parameters

base_layernn.Embedding
The table to adapt; the other parameters are those of TrainableTokensLayer.
adapter_namestr
Name of the adapter created at once.
The adapter's config; its token_indices are this layer's.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft.tuners.trainable_tokens import Embedding, TrainableTokensConfig
>>> table = nn.Embedding(10, 4)
>>> layer = Embedding(table, "default", TrainableTokensConfig(token_indices=[2, 5], target_modules=["x"]))
>>> tuple(layer.trainable_tokens_delta["default"].shape)
(2, 4)
>>> ids = lucid.tensor([[1, 2, 5]])
>>> bool((layer(ids) == table(ids)).all().item())   # the rows start as the table's
True

Used by 1