Prefix Arguments
Prefix tuning's config dials, exposed as a node
- peft_args
Prefix_Arguments builds the PEFT PrefixTuningConfig for the LLM School trainer's prefix-tuning method. Prefix tuning is one of the soft-prompt family of parameter-efficient methods: instead of inserting trainable matrices into attention layers the way LoRA does, it prepends a set of learned virtual tokens to the hidden states at every layer, and only those tokens get trained while the base model stays frozen. The node's output is a JSON peft_args string that goes into CausalLM_trainer's optional peft_args input - and it's the only source of those args for prefix-tuning.
You'd reach for it over LoRA when you want minimal trainable parameters and don't need the model to "remember" a lot of new behavior - prefix tuning shines on instruction-following style adaptations. It's also slower per step than LoRA in practice because the prefix runs through every layer, so it's the niche pick, not the default.
The inputs that matter
num_virtual_tokens- default 20. How many learned tokens the prefix contains. This is the one knob that changes what the model can express: too few and the prefix can't carry the behavior, too many and you're paying attention cost for diminishing returns. The 10–30 range is the usual playground.prefix_length- default 10, and it's not the same thing as the virtual-token count. In PEFT'sPrefixTuningConfigthe prefix length is derived fromnum_virtual_tokenswhen not set; here the node passes both through as-is. If you set them inconsistently, the config is whatever PEFT decides to do with it, so keep them aligned or just leave the defaults.prefix_dropout- default 0.1. Regularization on the prefix tokens; same instinct as LoRA dropout.token_dim/num_transformer_submodules/num_attention_heads/num_layers- the PEFT config's defaults (768 / 1 / 12 / 12) baked into node form. These are GPT-2-shaped numbers. If yourmodel_name_or_pathis anything else, they need to match its hidden size, heads, and layer count orget_peft_modelwill throw shape errors. For a non-GPT-2 model, settoken_dimto the model's hidden size at minimum.flat- boolean, default false. Passes through toPrefixTuningConfig'sflatoption; leave it false unless you know why you want flat prefix embeddings.
Install
Same as every node in the pack - ComfyUI Manager, search "comfyui_LLM_schools":
cd ComfyUI/custom_nodes
git clone https://github.com/heshengtao/comfyui_LLM_schools
then restart, letting Manager pull in huggingface_hub, datasets, transformers, peft.
Common issues
- Shape errors at training start. The classic symptom when your model isn't GPT-2 - the hardcoded
token_dim/num_layersdefaults don't match. Checkmodel.config(hidden_size, num_hidden_layers, num_attention_heads) and set the node's fields to match. - Method mismatch. This node only matters when
CausalLM_trainer'sfine_tuning_methodisprefix-tuning. And remember the pack'sfull_fine_tuningdefault crashes with aValueErrorin the current code, so you'll be selecting an explicit method anyway. - The config.ini gotcha. If the pack's nodes don't load at all, copy
config.ini.exampletoconfig.iniin the pack folder - the pack reads it at import time.
One honest caveat: this node passes prefix_length and num_virtual_tokens into PEFT together, which is redundant in some PEFT versions. If you hit an unexpected error, try removing prefix_length from the args dict (or setting both to the same value) - then the remaining fields are exactly what PrefixTuningConfig expects.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| prefix_length | INT | 101–100 | — |
| prefix_dropout | FLOAT | 0.100–1 | — |
| num_virtual_tokens | INT | 201–100 | — |
| token_dim | INT | 7681–4096 | — |
| num_transformer_submodules | INT | 11–12 | — |
| num_attention_heads | INT | 121–16 | — |
| num_layers | INT | 121–24 | — |
| flat | BOOLEAN | false | — |
| is_enable | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| peft_args | ARGS | — |