class
MultitaskPromptEmbedding
extends
PromptEmbeddingMultitaskPromptEmbedding(config: MultitaskPromptTuningConfig, word_embeddings: nn.Module | None, tokenizer: _TextEncoder | None = None)The prompt of multitask prompt tuning: a shared prompt scaled by a low-rank factor pair per task.
For a row of task the prompt is embedding(ids) * (cols[k] @ rows[k]) —
the shared (num_virtual_tokens, token_dim) prompt times the product of
(num_virtual_tokens, num_ranks) and (num_ranks, token_dim) factors.
Parameters
Sizes (
num_virtual_tokens, num_transformer_submodules and
token_dim set), the tasks and ranks, and the initialisation.word_ embeddingsnn.ModuleThe model's token table, which
"TEXT" copies rows of.tokenizerobject with encode(text) -> list[int]= NoneAs for
lucid.peft.PromptEmbedding.Attributes
embeddingnn.EmbeddingThe shared prompt.
prefix_ task_ colsParameter(num_tasks, num_virtual_tokens * num_transformer_submodules, num_ranks).prefix_ task_ rowsParameter(num_tasks, num_ranks, token_dim).Raises
ValueErrorA source initialisation without
prompt_tuning_init_state_dict_path, a source file
that is not .safetensors, lacks a tensor, or whose shapes do not fit this adapter.Examples
>>> import lucid
>>> import lucid.nn as nn
>>> from lucid.peft import MultitaskPromptEmbedding, MultitaskPromptTuningConfig
>>> config = MultitaskPromptTuningConfig(
... num_virtual_tokens=3, token_dim=8, num_transformer_submodules=1, num_tasks=2
... )
>>> prompt = MultitaskPromptEmbedding(config, nn.Embedding(10, 8))
>>> prompt(lucid.arange(3).long().reshape(1, 3), lucid.tensor([1])).shape
(1, 3, 8)Used by 1
Constructors
1dunder
__init__
→None__init__(config: MultitaskPromptTuningConfig, word_embeddings: nn.Module | None, tokenizer: _TextEncoder | None = None)Build the shared prompt and each task's low-rank pair.
The pair is and for each of config.num_tasks tasks; the
shared prompt starts as PromptEmbedding's does, or from a source-task prompt
when config.prompt_tuning_init asks.
Class methods
1Instance methods
2The prompt of each row's task: (B, rows) ids and (B,) task ids to (B, rows, token_dim).
Raises
ValueErrortask_ids is missing, or is not one integer per row.IndexErrorA task id is not in
[0, num_tasks).