Nodes/comfyui_LLM_schools/Prefix Arguments
ComfyUI Node

Prefix Arguments

Prefix tuning's config dials, exposed as a node

By heshengtao·Created 2 years ago·Updated 2 years ago· 7
Prefix Arguments
    • peft_args
    prefix_length10
    prefix_dropout0.10
    num_virtual_tokens20
    token_dim768
    num_transformer_submodules1
    num_attention_heads12
    num_layers12
    flatfalse
    is_enabletrue

    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's PrefixTuningConfig the prefix length is derived from num_virtual_tokens when 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 your model_name_or_path is anything else, they need to match its hidden size, heads, and layer count or get_peft_model will throw shape errors. For a non-GPT-2 model, set token_dim to the model's hidden size at minimum.
    • flat - boolean, default false. Passes through to PrefixTuningConfig's flat option; 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_layers defaults don't match. Check model.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's fine_tuning_method is prefix-tuning. And remember the pack's full_fine_tuning default crashes with a ValueError in 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.example to config.ini in 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.

    Category大模型学校(llm_schools)/模型训练(Model Training)

    Inputs (9)

    NameTypeDefaultDescription
    prefix_lengthINT101–100
    prefix_dropoutFLOAT0.100–1
    num_virtual_tokensINT201–100
    token_dimINT7681–4096
    num_transformer_submodulesINT11–12
    num_attention_headsINT121–16
    num_layersINT121–24
    flatBOOLEANfalse
    is_enableBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    peft_argsARGS