PromptEncoderModel
_PromptLearningTunerPromptEncoderModel(model: nn.Module, peft_config: PeftConfig, adapter_name: str = 'default', low_cpu_mem_usage: bool = False, state_dict: dict[str, Tensor] | None = None)The tuner of p-tuning: a PromptEncoder per adapter, whose prompt goes in front of the input.
Used by 1
Properties
1Static methods
1get_model_config
→dict of str to objectfrom _AdapterHostget_model_config(model: nn.Module)model's config as a dict, whatever it is held as.
A config with a to_dict method is converted by it, a dataclass by asdict, a
mapping is copied. A model with no config (or one that is None) has the
reference's stand-in, {"model_type": "custom"}, which is what the default target
modules and the prompt geometry read for a model of no known type.
Parameters
modelnn.ModuleReturns
dict of str to objectThe config's entries; a new dict, whose changes do not reach the model.
Raises
TypeErrormodel.config is none of a mapping, a dataclass or an object with to_dict.Examples
>>> import lucid.nn as nn
>>> from lucid.peft import LoraModel
>>> LoraModel.get_model_config(nn.Linear(2, 2))
{'model_type': 'custom'}Instance methods
9add_adapter
→Nonefrom _PromptLearningTuneradd_adapter(adapter_name: str, config: PeftConfig)Add a prompt beside the ones held; it starts frozen, and set_adapter switches to it.
Raises
ValueErrorRemove a prompt and its modules_to_save copies; another takes over if it was in use.
Stop prompting.
The model runs as the base does, and its modules_to_save modules run their originals.
Prompt the model again, and run the trained modules_to_save copies.
Call the model.
The prompt is put in by hooks on the model's own call, so nothing is applied here.
merge_and_unload(progressbar: bool = False, safe_merge: bool = False, adapter_names: list[str] | None = None)Refused: a prompt has no weight to fold into the model.
set_adapter
→Nonefrom _PromptLearningTunerset_adapter(adapter_name: str | list[str], inference_mode: bool = False)Apply the named prompt — one at a time — and train it unless inference_mode.
set_requires_grad
→Nonefrom _PromptLearningTunerset_requires_grad(adapter_names: str | Sequence[str], requires_grad: bool = True)Set requires_grad on the named adapters' encoders and modules_to_save copies.
Take the hooks and the modules_to_save copies out and give every parameter its old requires_grad.