CPTEmbedding
_PromptEncoderCPTEmbedding(config: CPTConfig, word_embeddings: nn.Module | None)The prompt of CPT: frozen token embeddings plus a trainable delta kept near zero.
Built to train it holds embedding (the model's embeddings of cpt_token_ids, frozen)
and delta_embedding (zeros). Each call first projects every delta row onto the ball of
radius — the input or template epsilon of its token type, times
— writing the result back into the parameter (the optimiser steps from
the projected value, as the reference's does), then returns embedding + delta. Only the
deltas of types 1 to 3 (templates and inputs) receive a gradient. Built for
inference_mode it holds embedding alone, whose rows are the finished prompt.
Parameters
Attributes
embeddingnn.Embedding(num_virtual_tokens, token_dim), never trained.delta_ embeddingnn.Embedding or NoneNone for an inference adapter.Raises
TypeErrornn.Embedding.Examples
>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import CPTConfig
>>> from lucid.peft.tuners.cpt import CPTEmbedding
>>> config = CPTConfig(cpt_token_ids=[1, 2], cpt_tokens_type_mask=[2, 4], token_dim=8,
... task_type="CAUSAL_LM")
>>> prompt = CPTEmbedding(config, nn.Embedding(5, 8))
>>> prompt(lucid.arange(2).long()).shape
(2, 8)
>>> [p.requires_grad for p in prompt.parameters()]
[False, True]Used by 2
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
5The prompt rows embedding + delta of the virtual-token ids indices.
The virtual-token ids (1, num_embeddings) the encoder is called with.
Pull every delta row back inside its ball and write that into the parameter.
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.