Skip to content
data

PrefixTuningConfig

extendsPromptLearningConfig
PrefixTuningConfig(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

task_typeTaskType | str | None= None
As in lucid.peft.PeftConfig.
peft_typeTaskType | str | None= None
As in lucid.peft.PeftConfig.
auto_mappingTaskType | str | None= None
As in lucid.peft.PeftConfig.
peft_versionTaskType | str | None= None
As in lucid.peft.PeftConfig.
base_model_name_or_pathTaskType | str | None= None
As in lucid.peft.PeftConfig.
revisionTaskType | str | None= None
As in lucid.peft.PeftConfig.
inference_modeTaskType | str | None= None
As in lucid.peft.PeftConfig.
num_virtual_tokensint | None= None
As in lucid.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= None
As in lucid.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= None
As in lucid.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= None
As in lucid.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= None
As in lucid.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= None
As in lucid.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= None
Width of the projection MLP's hidden layer; token_dim when omitted.
prefix_projectionbool= False
Produce the prefix through the projection MLP while training.

Raises

TypeError
A field holds a value of the wrong type.

Examples

>>> 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)

Used by 2