Skip to content
data

PromptTuningConfig

extendsPromptLearningConfig
PromptTuningConfig(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, prompt_tuning_init: PromptTuningInit | str = PromptTuningInit.RANDOM, prompt_tuning_init_text: str | None = None, tokenizer_name_or_path: str | None = None, tokenizer_kwargs: dict[str, object] | None = None)

How lucid.peft.get_peft_model adapts a model with prompt tuning.

Prompt tuning (Lester et al., 2021, arXiv:2104.08691) freezes the model and learns num_virtual_tokens embedding vectors that are put in front of the input embeddings: the only trained parameters are num_virtual_tokens * token_dim numbers, and a task is a file of that size. An encoder-decoder model gets them in front of the encoder's input.

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.
token_dimint | None= None
As in lucid.peft.PromptLearningConfig.
num_transformer_submodulesint | None= None
As in lucid.peft.PromptLearningConfig.
num_attention_headsint | None= None
As in lucid.peft.PromptLearningConfig.
num_layersint | None= None
As in lucid.peft.PromptLearningConfig.
modules_to_saveint | None= None
As in lucid.peft.PromptLearningConfig.
prompt_tuning_initPromptTuningInit or str= "RANDOM"
"RANDOM" keeps the embedding table's initialisation; "SAMPLE_VOCAB" starts from the embeddings of random vocabulary tokens; "TEXT" starts from those of prompt_tuning_init_text's tokens (cut or repeated to num_virtual_tokens).
prompt_tuning_init_textstr= None
The text "TEXT" starts from; required then.
tokenizer_name_or_pathstr= None
Names the tokenizer that turns that text into ids; required for "TEXT".
tokenizer_kwargsdict= None
Keyword arguments for loading that tokenizer; only with "TEXT".

Raises

TypeError
A field holds a value of the wrong type.
ValueError
"TEXT" without its text or tokenizer, or tokenizer_kwargs without "TEXT".

Examples

>>> from lucid.peft import PromptTuningConfig
>>> config = PromptTuningConfig(num_virtual_tokens=8, task_type="CAUSAL_LM")
>>> config.peft_type, config.prompt_tuning_init
(<PeftType.PROMPT_TUNING: 'PROMPT_TUNING'>, <PromptTuningInit.RANDOM: 'RANDOM'>)
>>> PromptTuningConfig.from_dict(config.to_dict()) == config
True

Used by 3