Configuration
PeftConfigMixin
is the base configuration class for storing the adapter configuration of a PeftModel, and PromptLearningConfig is the base configuration class for soft prompt methods (p-tuning, prefix tuning, and prompt tuning). These base classes contain methods for saving and loading model configurations from the Hub, specifying the PEFT method to use, type of task to perform, and model configurations like number of layers and number of attention heads.
PeftConfigMixin
class peft.config.PeftConfigMixin
< source >( peft_type: Optional = None auto_mapping: Optional = None )
This is the base configuration class for PEFT adapter models. It contains all the methods that are common to all
PEFT adapter models. This class inherits from PushToHubMixin which contains the methods to
push your model to the Hub. The method save_pretrained
will save the configuration of your adapter model in a
directory. The method from_pretrained
will load the configuration of your adapter model from a directory.
from_json_file
< source >( path_json_file: str **kwargs )
Loads a configuration file from a json file.
from_peft_type
< source >( **kwargs )
This method loads the configuration of your adapter model from a set of kwargs.
The appropriate configuration type is determined by the peft_type
argument. If peft_type
is not provided,
the calling class type is instantiated.
from_pretrained
< source >( pretrained_model_name_or_path: str subfolder: Optional = None **kwargs )
This method loads the configuration of your adapter model from a directory.
save_pretrained
< source >( save_directory: str **kwargs )
Parameters
- save_directory (
str
) — The directory where the configuration will be saved. - kwargs (additional keyword arguments, optional) — Additional keyword arguments passed along to the push_to_hub method.
This method saves the configuration of your adapter model in a directory.
Returns the configuration for your adapter model as a dictionary.
PeftConfig
class peft.PeftConfig
< source >( peft_type: Union = None auto_mapping: Optional = None base_model_name_or_path: Optional = None revision: Optional = None task_type: Union = None inference_mode: bool = False )
This is the base configuration class to store the configuration of a PeftModel.
PromptLearningConfig
class peft.PromptLearningConfig
< source >( peft_type: Union = None auto_mapping: Optional = None base_model_name_or_path: Optional = None revision: Optional = None task_type: Union = None inference_mode: bool = False num_virtual_tokens: int = None token_dim: int = None num_transformer_submodules: Optional = None num_attention_heads: Optional = None num_layers: Optional = None )
Parameters
- num_virtual_tokens (
int
) — The number of virtual tokens to use. - token_dim (
int
) — The hidden embedding dimension of the base transformer model. - num_transformer_submodules (
int
) — The number of transformer submodules in the base transformer model. - num_attention_heads (
int
) — The number of attention heads in the base transformer model. - num_layers (
int
) — The number of layers in the base transformer model.
This is the base configuration class to store the configuration of PrefixTuning
, PromptEncoder, or
PromptTuning
.