CPT
3 memberslucid.peft.tuners.cptlucid.peft.tuners.cpt — context-aware prompt tuning: a prompt of in-context examples with a bounded learned offset.
CPT (Blau et al., 2024, arXiv:2410.17222) tunes a prompt that is itself a few in-context examples.
Its tokens start as the embeddings of cpt_token_ids and each gets a trainable delta, held near
zero by a projection after every step (templates and inputs may move, outputs may not), so the
examples keep their meaning while the prompt adapts. The loss counts the output tokens of the
prompt as well as of the batch, optionally weighting earlier examples less. Pick it for few-shot
fine-tuning of a causal language model when the examples should stay in context; for a free
prompt that starts anywhere, use prompt tuning.
Like the other prompt methods it adds no layer: the prompt is put in front of the input by hooks
on the model's call, so model(...) and generate both carry it, and the adapter file holds
the finished prompt as prompt_embeddings. CPTConfig and CPTModel are here and exported
from lucid.peft; CPTEmbedding is the learned part. Importing the package registers the
method under PeftType.CPT.
Blau, Tsachi, et al. "Context-Aware Prompt Tuning: Advancing In-Context Learning with Adversarial Methods." [arXiv:2410.17222](https://arxiv.org/abs/2410.17222), 2024.
CPT (Blau et al., 2024, arXiv:2410.17222) tunes a prompt made of in-context examples: the
prompt's tokens start as the embeddings of cpt_token_ids and a trainable delta is
added to each. Each token has a type (cpt_tokens_type_mask, read modulo 4: 1 an input
template, 2 an input, 3 an output template, 0 or 4 an output or padding) that
says which deltas train (types 1-3 only) and how far a delta may move: after every step its
norm is projected back onto a ball of radius opt_projection_epsilon (inputs) or
opt_projection_format_epsilon (templates), scaled by . The loss
covers the output tokens of the prompt and of the batch, optionally down-weighted for earlier
examples (opt_weighted_loss_type="decay").
Classes
CPTConfigHow lucid.peft.get_peft_model adapts a causal language model with context-aware prompt tuning.
CPTEmbedding12 methodsThe prompt of CPT: frozen token embeddings plus a trainable delta kept near zero.
CPTModel11 methodsThe tuner of context-aware prompt tuning: a CPTEmbedding per adapter, in front of the input.