Nodes/comfyui_LLM_schools/P or Prompt Arguments
ComfyUI Node

P or Prompt Arguments

Prompt tuning args — where 'RANDOM vs TEXT' decides your whole run

By heshengtao·Created 2 years ago·Updated 2 years ago· 7
P or Prompt Arguments
    • peft_args
    num_virtual_tokens20
    token_dim768
    num_transformer_submodules1
    num_attention_heads12
    num_layers12
    prompt_tuning_initRANDOM
    prompt_tuning_init_text
    tokenizer_name_or_pathbert-base-uncased
    is_enabletrue

    P_or_Prompt_Arguments builds the PEFT PromptTuningConfig for the LLM School trainer. Prompt tuning is the minimalist end of the parameter-efficient spectrum: you add a small set of trainable soft tokens in front of your input, freeze everything else, and train only those tokens. In this pack it backs two of the trainer's fine_tuning_method options - p-tuning and prompt_tuning both map to PromptTuningConfig in the training core - so this one node serves both. If you want to adapt a model to a task with the absolute minimum of trainable parameters, this is the method.

    The one genuinely interesting decision here is how the prompt starts. prompt_tuning_init gives you RANDOM (the soft tokens begin as random vectors and learn everything from scratch) or TEXT (they're initialized from the embeddings of an actual sentence you provide in prompt_tuning_init_text). The TEXT option is the practical one for a real task - starting from a sensible sentence ("Answer the question based on the context:") puts the tokens in the neighborhood of the right semantic space and trains faster and more stably than random noise. For most people, that's the difference between a run that works and a run that wanders.

    The inputs that matter

    • prompt_tuning_init - RANDOM or TEXT. The fork in the road; see above.
    • prompt_tuning_init_text - the sentence used when init is TEXT. Make it task-relevant and it pays off.
    • tokenizer_name_or_path - default bert-base-uncased. This is the tokenizer used to encode your init text, and it must be compatible with your model's vocabulary - feeding a BERT tokenizer's IDs to a GPT-2 model is a recipe for nonsense. Set it to your model's tokenizer, not the default, if you're using TEXT init.
    • num_virtual_tokens - default 20. How many soft tokens to prepend. 20 is a sane default; shorter for easier tasks.
    • token_dim, num_transformer_submodules, num_attention_heads, num_layers - the GPT-2-shaped PEFT defaults again. Set token_dim to your model's hidden size if you're not on GPT-2.

    A bug you'll hit on first use

    The node's Argument method signature requires a task_type parameter, but that field isn't in the node's inputs - so when ComfyUI calls the node it raises TypeError: Argument() missing 1 required positional argument: 'task_type' and the node fails on execution. There's no workaround in the UI; you have to patch the source. The cleanest fix: edit the method signature in train.py to give it a default, e.g. task_type="CAUSAL_LM", or delete the task_type parameter from the signature and from the args dict it builds. It's a small edit, but it's the difference between this node working and being a brick - and it's a good reminder that this pack is early-stage and unpolished.

    Install

    ComfyUI Manager, search "comfyui_LLM_schools", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/heshengtao/comfyui_LLM_schools
    

    then restart. Deps: huggingface_hub, datasets, transformers, peft.

    Other things that'll trip you up

    • The trainer's full_fine_tuning default raises ValueError in the current code - you'll be picking p-tuning/prompt_tuning explicitly anyway.
    • Missing config.ini in the pack folder (copy from config.ini.example) breaks node loading entirely.
    • If a run starts but quality is bad, suspect the tokenizer_name_or_path mismatch before anything else.

    It's the most promising method in the pack and the least finished. If you're willing to patch one line, prompt tuning from TEXT init is a great way to adapt a causal LM cheaply - just don't expect it to work untouched.

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

    Inputs (9)

    NameTypeDefaultDescription
    num_virtual_tokensINT201–100
    token_dimINT7681–4096
    num_transformer_submodulesINT11–12
    num_attention_headsINT121–16
    num_layersINT121–24
    prompt_tuning_initCOMBORANDOM2 options: RANDOM, TEXT
    prompt_tuning_init_textSTRING
    tokenizer_name_or_pathSTRINGbert-base-uncased
    is_enableBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    peft_argsARGS