Skip to content
data

PromptEncoderConfig

extendsPromptLearningConfig
PromptEncoderConfig(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, encoder_reparameterization_type: PromptEncoderReparameterizationType | str = PromptEncoderReparameterizationType.MLP, encoder_hidden_size: int | None = None, encoder_num_layers: int = 2, encoder_dropout: float = 0.0)

How lucid.peft.get_peft_model adapts a model with p-tuning.

P-tuning (Liu et al., 2021, arXiv:2103.10385) puts num_virtual_tokens learned embeddings in front of the input like prompt tuning, but produces them through an encoder — an MLP, or a bidirectional LSTM followed by one — so the tokens depend on each other. The encoder is only used while training: the file stores the prompt it produced.

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.
encoder_reparameterization_type(MLP, LSTM)= "MLP"
The encoder.
encoder_hidden_sizeint= None
Its hidden width; token_dim when omitted.
encoder_num_layersint= 2
LSTM layers (an MLP always has two hidden layers; a different value warns).
encoder_dropoutfloat= 0.0
LSTM dropout between layers.

Raises

TypeError
A field holds a value of the wrong type.

Examples

>>> from lucid.peft import PromptEncoderConfig
>>> config = PromptEncoderConfig(num_virtual_tokens=4, encoder_reparameterization_type="LSTM")
>>> config.peft_type, config.encoder_reparameterization_type
(<PeftType.P_TUNING: 'P_TUNING'>, <PromptEncoderReparameterizationType.LSTM: 'LSTM'>)

Used by 2