CPTConfig
PromptLearningConfigCPTConfig(task_type: TaskType | str | None = None, peft_type: PeftType | str | None = None, auto_mapping: dict[str, str] | None = None, peft_version: str | None = None, base_model_name_or_path: str | None = None, revision: str | None = None, inference_mode: bool = False, num_virtual_tokens: int | None = None, token_dim: int | None = None, num_transformer_submodules: int | None = None, num_attention_heads: int | None = None, num_layers: int | None = None, modules_to_save: list[str] | None = None, cpt_token_ids: list[int] | None = None, cpt_mask: list[int] | None = None, cpt_tokens_type_mask: list[int] | None = None, opt_weighted_loss_type: Literal['none', 'decay'] = 'none', opt_loss_decay_factor: float = 1.0, opt_projection_epsilon: float = 0.1, opt_projection_format_epsilon: float = 0.1, tokenizer_name_or_path: str | None = None)How lucid.peft.get_peft_model adapts a causal language model with context-aware prompt tuning.
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").
Field names, their order, defaults and adapter_config.json are the reference adapter library's. num_virtual_tokens is len(cpt_token_ids) whatever is passed.
Parameters
lucid.peft.PeftConfig.lucid.peft.PeftConfig.lucid.peft.PeftConfig.lucid.peft.PeftConfig.lucid.peft.PeftConfig.lucid.peft.PeftConfig.lucid.peft.PeftConfig.num_ virtual_ tokensint | None= Nonelucid.peft.PromptLearningConfig.token_ dimint | None= Nonelucid.peft.PromptLearningConfig.num_ transformer_ submodulesint | None= Nonelucid.peft.PromptLearningConfig.num_ attention_ headsint | None= Nonelucid.peft.PromptLearningConfig.num_ layersint | None= Nonelucid.peft.PromptLearningConfig.modules_ to_ saveint | None= Nonelucid.peft.PromptLearningConfig.cpt_ token_ idslist of int= None[0] by default.cpt_ masklist of int= Nonecpt_ tokens_ type_ masklist of int= Noneopt_ weighted_ loss_ type(none, decay)= "none""decay" weights the loss of each earlier output segment of an example by a further
factor of opt_loss_decay_factor.opt_ loss_ decay_ factorfloat= 1.0"decay".opt_ projection_ epsilonfloat= 0.1opt_ projection_ format_ epsilonfloat= 0.1tokenizer_ name_ or_ pathstr= NoneRaises
TypeErrorValueErrortask_type is not "CAUSAL_LM", or the three per-token lists differ in length.Examples
>>> from lucid.peft import CPTConfig
>>> config = CPTConfig(cpt_token_ids=[5, 6, 7], cpt_tokens_type_mask=[1, 2, 4], task_type="CAUSAL_LM")
>>> config.num_virtual_tokens, config.cpt_mask
(3, [1, 1, 1])
>>> CPTConfig.from_dict(config.to_dict()) == config
True