AGENT SKILL

prompt-and-soft-methods

Configure and troubleshoot PEFT prompt-learning and soft-token methods: prompt tuning, prefix tuning, P-tuning, multitask prompt tuning, CPT, adaption prompt, CARTRIDGE, and trainable tokens.

License 许可
Apache-2.0
最近更新
2026-09-03
Stars
★ 351
Forks
27

01 前言 Front Matter

name
prompt-and-soft-methods
license
Apache 2.0
metadata
{ "disco-role": "operating" }
description
Configure and troubleshoot PEFT prompt-learning and soft-token methods: prompt tuning, prefix tuning, P-tuning, multitask prompt tuning, CPT, adaption prompt, CARTRIDGE, and trainable tokens.
disable-model-invocation
true

02 资源文件 4

03 SKILL.md 正文

PEFT Prompt And Soft Methods

Use this sub-skill when the task is about PEFT methods that add trainable virtual tokens, prompt encoders, KV-prefix parameters, adaption prompts, or selected trainable vocabulary rows. It focuses on choosing and constructing configs, handling prompt initialization, task and virtual-token settings, and prompt-specific generation caveats.

For generic PeftModel lifecycle, adapter activation, mixed adapters, or get_peft_model mechanics, use the root PEFT skill and the adapter-core sub-skill. For save_pretrained, from_pretrained, merge behavior, and checkpoint formats, use save-load-merge. For training launchers, Trainer, Accelerate, DeepSpeed, or distributed jobs, use training-and-integrations.

Method Routing

  • Use PromptTuningConfig for directly learned virtual-token embeddings prepended to model embeddings; choose RANDOM, SAMPLE_VOCAB, or TEXT initialization.
  • Use PrefixTuningConfig for learned key/value prefixes injected as past_key_values; it is prefix-style and incompatible with gradient checkpointing in PEFT setup.
  • Use PromptEncoderConfig for P-tuning, where an MLP or LSTM encoder reparameterizes virtual prompt tokens.
  • Use MultitaskPromptTuningConfig when one prompt table is factorized across multiple task IDs or initialized from a source multitask prompt state dict.
  • Use CPTConfig for Context-aware Prompt Tuning on causal LM only; its num_virtual_tokens is derived from cpt_token_ids.
  • Use AdaptionPromptConfig for LLaMA-adapter-style attention prompts on supported model types (llama, mistral, gpt2).
  • Use CartridgeConfig for KV-cache-parameterized prefix adapters that can be initialized from a text prefill or existing past_key_values.
  • Use TrainableTokensConfig for making specific vocabulary embedding rows trainable without training the full embedding matrix.

Minimal Config Patterns

from peft import PromptTuningConfig, TaskType

config = PromptTuningConfig(
    task_type=TaskType.SEQ_2_SEQ_LM,
    num_virtual_tokens=20,
    prompt_tuning_init="TEXT",
    prompt_tuning_init_text="Classify the sentiment of the input.",
    tokenizer_name_or_path="t5-small",
)
from peft import PrefixTuningConfig, TaskType

config = PrefixTuningConfig(
    task_type=TaskType.CAUSAL_LM,
    num_virtual_tokens=16,
    prefix_projection=True,
    encoder_hidden_size=512,
)
from peft import CPTConfig, TaskType

config = CPTConfig(
    task_type=TaskType.CAUSAL_LM,
    cpt_token_ids=[0, 1, 2, 3],
    cpt_mask=[1, 1, 1, 1],
    cpt_tokens_type_mask=[1, 2, 3, 4],
    opt_weighted_loss_type="decay",
)

Required Checks

Before wrapping the base model with get_peft_model, verify these points:

  • task_type matches the base model head and use case, such as CAUSAL_LM, SEQ_2_SEQ_LM, SEQ_CLS, TOKEN_CLS, or QUESTION_ANS.
  • Prompt-learning methods have a positive num_virtual_tokens, except CPT where PEFT derives it from len(cpt_token_ids).
  • PromptTuningConfig(prompt_tuning_init="TEXT") includes both prompt_tuning_init_text and tokenizer_name_or_path.
  • Prefix-style methods (PrefixTuningConfig, CartridgeConfig) have compatible token_dim, num_layers, and num_attention_heads when manually overriding inferred values.
  • MultitaskPromptTuningConfig receives task_ids in forward/generation calls when task-specific factors are intended.
  • TrainableTokensConfig.token_indices are real tokenizer IDs and the target embedding module is the one used by the model forward path.

Run scripts/prompt_config_sanity.py to validate config construction and surface method-specific constraints without loading a model.

Cross-Links

  • See references/methods.md for method distinctions, config fields, and constraints.
  • See references/workflows.md for choosing settings and integrating with get_peft_model and generation.
  • See references/troubleshooting.md for common failure modes involving task types, initialization, CPT, generation, and trainable tokens.

04 同仓库更多 Skills

VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-triton-opt

Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-solve

END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-skill

PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-pattern-fusion

Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-orchestrate

Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-feedback

Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).

★ 351