The prompt of p-tuning: virtual-token embeddings through an MLP, or a bidirectional LSTM and an MLP.
Built for a trainable adapter it holds the whole encoder; built with
inference_mode it holds embedding alone, whose rows are then the
prompt (as an adapter file stores it).
Parameters
configPromptEncoderConfignum_virtual_tokens, num_transformer_submodules,
token_dim, encoder_hidden_size set) and the encoder's type.Attributes
embeddingnn.Embedding(num_virtual_tokens * num_transformer_submodules, token_dim).mlp_ headnn.Modulenn.Identity.lstm_ headnn.LSTM or None"LSTM" type.Examples
>>> import lucid
>>> from lucid.peft import PromptEncoderConfig
>>> from lucid.peft.tuners.p_tuning import PromptEncoder
>>> config = PromptEncoderConfig(num_virtual_tokens=3, token_dim=8, encoder_hidden_size=16,
... num_transformer_submodules=1)
>>> PromptEncoder(config)(lucid.arange(3).long().reshape(1, 3)).shape
(1, 3, 8)Used by 1
Constructors
1Properties
2Attributes
2Whether the prompt depends on the task each batch row belongs to (task_ids).
The tensors an adapter file holds, by the encoder's own key and the file's: the prompt always, and whatever else the method keeps beside it.
Class methods
1Instance methods
4Prompt rows of the virtual-token ids: (B, total) ids to (B, total, token_dim).
The virtual-token ids (1, num_embeddings) the encoder is called with.
The prompt as an adapter file stores it: (rows, width), one row per virtual token.
A per-task encoder's is the shared prompt its tasks scale, which is what the file holds.
The prompt of each of batch rows: (batch, num_embeddings, width).
tasks is the task of each row, which a per_task encoder needs and the others
do not read.