PrefixTuningConfig
PromptLearningConfigPrefixTuningConfig(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, init_weights: str | None = None, encoder_hidden_size: int | None = None, prefix_projection: bool = False)How lucid.peft.get_peft_model adapts a model with prefix tuning.
Prefix tuning (Li and Liang, 2021, arXiv:2101.00190) learns
num_virtual_tokens key and value vectors for every attention layer
and puts them in front of that layer's own, so the whole network can attend
to them: num_virtual_tokens * 2 * num_layers * token_dim numbers. With
prefix_projection the vectors are produced from a smaller embedding by a
two-layer MLP while training, which the paper found steadier; the file
still stores the finished vectors. An encoder-decoder model gets the prefix
on the decoder's self-attention, so num_layers left out is the decoder's
layer count when the model's config declares one (num_decoder_layers).
Field names, their order, defaults and adapter_config.json are the reference adapter
library's.
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, except that token_dim is the width of
the model's attention — num_attention_heads times the head width its config declares
(head_dim, num_key_value_heads) — which is the hidden size for most models and not
for one whose heads are wider (T5-3B, T5-11B). Left out, it is read that way; given, it
must agree with a declared attention, or ValueError names both widths. (The reference
library reads the hidden size, and fails on such a model unless token_dim is set to
this width, the config derived here.)token_ dimint | None= Nonelucid.peft.PromptLearningConfig, except that token_dim is the width of
the model's attention — num_attention_heads times the head width its config declares
(head_dim, num_key_value_heads) — which is the hidden size for most models and not
for one whose heads are wider (T5-3B, T5-11B). Left out, it is read that way; given, it
must agree with a declared attention, or ValueError names both widths. (The reference
library reads the hidden size, and fails on such a model unless token_dim is set to
this width, the config derived here.)num_ transformer_ submodulesint | None= Nonelucid.peft.PromptLearningConfig, except that token_dim is the width of
the model's attention — num_attention_heads times the head width its config declares
(head_dim, num_key_value_heads) — which is the hidden size for most models and not
for one whose heads are wider (T5-3B, T5-11B). Left out, it is read that way; given, it
must agree with a declared attention, or ValueError names both widths. (The reference
library reads the hidden size, and fails on such a model unless token_dim is set to
this width, the config derived here.)num_ attention_ headsint | None= Nonelucid.peft.PromptLearningConfig, except that token_dim is the width of
the model's attention — num_attention_heads times the head width its config declares
(head_dim, num_key_value_heads) — which is the hidden size for most models and not
for one whose heads are wider (T5-3B, T5-11B). Left out, it is read that way; given, it
must agree with a declared attention, or ValueError names both widths. (The reference
library reads the hidden size, and fails on such a model unless token_dim is set to
this width, the config derived here.)num_ layersint | None= Nonelucid.peft.PromptLearningConfig, except that token_dim is the width of
the model's attention — num_attention_heads times the head width its config declares
(head_dim, num_key_value_heads) — which is the hidden size for most models and not
for one whose heads are wider (T5-3B, T5-11B). Left out, it is read that way; given, it
must agree with a declared attention, or ValueError names both widths. (The reference
library reads the hidden size, and fails on such a model unless token_dim is set to
this width, the config derived here.)modules_ to_ saveint | None= Nonelucid.peft.PromptLearningConfig, except that token_dim is the width of
the model's attention — num_attention_heads times the head width its config declares
(head_dim, num_key_value_heads) — which is the hidden size for most models and not
for one whose heads are wider (T5-3B, T5-11B). Left out, it is read that way; given, it
must agree with a declared attention, or ValueError names both widths. (The reference
library reads the hidden size, and fails on such a model unless token_dim is set to
this width, the config derived here.)init_ weightszero= "zero""zero" starts the prefix at zeros (the output layer of the
projection, when there is one) so the keys and values it adds are null.encoder_ hidden_ sizeint= Nonetoken_dim when omitted.prefix_ projectionbool= FalseRaises
TypeErrorExamples
>>> from lucid.peft import PrefixTuningConfig
>>> config = PrefixTuningConfig(num_virtual_tokens=4, prefix_projection=True)
>>> config.peft_type, config.prefix_projection
(<PeftType.PREFIX_TUNING: 'PREFIX_TUNING'>, True)