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
- 参考文档references/methods.md6.9 KB
- 参考文档references/troubleshooting.md4.9 KB
- 参考文档references/workflows.md4.4 KB
- 脚本scripts/prompt_config_sanity.py7.6 KB
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
PromptTuningConfigfor directly learned virtual-token embeddings prepended to model embeddings; chooseRANDOM,SAMPLE_VOCAB, orTEXTinitialization. - Use
PrefixTuningConfigfor learned key/value prefixes injected aspast_key_values; it is prefix-style and incompatible with gradient checkpointing in PEFT setup. - Use
PromptEncoderConfigfor P-tuning, where an MLP or LSTM encoder reparameterizes virtual prompt tokens. - Use
MultitaskPromptTuningConfigwhen one prompt table is factorized across multiple task IDs or initialized from a source multitask prompt state dict. - Use
CPTConfigfor Context-aware Prompt Tuning on causal LM only; itsnum_virtual_tokensis derived fromcpt_token_ids. - Use
AdaptionPromptConfigfor LLaMA-adapter-style attention prompts on supported model types (llama,mistral,gpt2). - Use
CartridgeConfigfor KV-cache-parameterized prefix adapters that can be initialized from a text prefill or existingpast_key_values. - Use
TrainableTokensConfigfor 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_typematches the base model head and use case, such asCAUSAL_LM,SEQ_2_SEQ_LM,SEQ_CLS,TOKEN_CLS, orQUESTION_ANS.- Prompt-learning methods have a positive
num_virtual_tokens, except CPT where PEFT derives it fromlen(cpt_token_ids). PromptTuningConfig(prompt_tuning_init="TEXT")includes bothprompt_tuning_init_textandtokenizer_name_or_path.- Prefix-style methods (
PrefixTuningConfig,CartridgeConfig) have compatibletoken_dim,num_layers, andnum_attention_headswhen manually overriding inferred values. MultitaskPromptTuningConfigreceivestask_idsin forward/generation calls when task-specific factors are intended.TrainableTokensConfig.token_indicesare 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.mdfor method distinctions, config fields, and constraints. - See
references/workflows.mdfor choosing settings and integrating withget_peft_modeland generation. - See
references/troubleshooting.mdfor common failure modes involving task types, initialization, CPT, generation, and trainable tokens.
04 同仓库更多 Skills
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.
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.
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.
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.
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.
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).