Skip to content
class

MultitaskPromptTuningModel

extends_PromptLearningTuner
MultitaskPromptTuningModel(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 multitask prompt tuning: a MultitaskPromptEmbedding per adapter, in front of the input.

Used by 1

Properties

1
prop

active_adapters

→list[str]from _PromptLearningTuner
active_adapters: list[str]

The adapter the model is prompted with, as a list.

Prompt learning applies one at a time.

Static methods

1
static

get_model_config

→dict of str to objectfrom _AdapterHost
get_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

The model to read the config of.

Returns

dict of str to object

The config's entries; a new dict, whose changes do not reach the model.

Raises

TypeError
model.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

9
fn

add_adapter

→Nonefrom _PromptLearningTuner
add_adapter(adapter_name: str, config: PeftConfig)

Add a prompt beside the ones held; it starts frozen, and set_adapter switches to it.

Raises

ValueError
The name is taken, or the config is another method's.
fn

delete_adapter

→Nonefrom _PromptLearningTuner
delete_adapter(adapter_name: str)

Remove a prompt and its modules_to_save copies; another takes over if it was in use.

fn

disable_adapter_layers

→Nonefrom _PromptLearningTuner
disable_adapter_layers()

Stop prompting.

The model runs as the base does, and its modules_to_save modules run their originals.

fn

enable_adapter_layers

→Nonefrom _PromptLearningTuner
enable_adapter_layers()

Prompt the model again, and run the trained modules_to_save copies.

fn

forward

→objectfrom _PromptLearningTuner
forward(args: object = (), kwargs: object = {})

Call the model.

The prompt is put in by hooks on the model's own call, so nothing is applied here.

fn

merge_and_unload

→nn.Modulefrom _PromptLearningTuner
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.

fn

set_adapter

→Nonefrom _PromptLearningTuner
set_adapter(adapter_name: str | list[str], inference_mode: bool = False)

Apply the named prompt — one at a time — and train it unless inference_mode.

fn

set_requires_grad

→Nonefrom _PromptLearningTuner
set_requires_grad(adapter_names: str | Sequence[str], requires_grad: bool = True)

Set requires_grad on the named adapters' encoders and modules_to_save copies.

fn

unload

→nn.Modulefrom _PromptLearningTuner
unload()

Take the hooks and the modules_to_save copies out and give every parameter its old requires_grad.