class
Embedding
extends
HiraLayerEmbedding(base_layer: nn.Module, adapter_name: str, config: C)Implementing kernel
C++ engine symbols that back this Python API.An nn.Embedding with a HiRA update: the table is looked up as .
The factors are and
(hira_embedding_A, hira_embedding_B). They start as the reference starts them,
and , so the update is zero; init_weights=False
leaves both Gaussian. The modulated table is looked up as is: the base's padding_idx and
max_norm apply to the base lookup only, and hira_dropout has nothing to act on.
Parameters
base_ layernn.EmbeddingThe layer to adapt; the other parameters are those of
HiraLayer.adapter_ namestrName of the first adapter.
configHiraConfigr, hira_dropout and init_weights (the per-module ranks are the tuner's to resolve).Examples
>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import HiraConfig
>>> from lucid.peft.tuners.hira import Embedding
>>> base = nn.Embedding(10, 4)
>>> layer = Embedding(base, "default", HiraConfig(r=2, target_modules=["x"]))
>>> tuple(layer.hira_embedding_A["default"].shape), tuple(layer.hira_embedding_B["default"].shape)
((2, 10), (4, 2))
>>> ids = lucid.tensor([[1, 2, 3]])
>>> bool((layer(ids) == base(ids)).all().item()) # A starts at zero
True