Nodes/m9-prompts-comfyui/TweakWeightsText [m9]
ComfyUI Node

TweakWeightsText [m9]

Nudge Only the Words You Name

By MarcusNyne·Created 3 years ago·Updated 3 days ago· 1
TweakWeightsText [m9]
    • prompt
    prompt
    keywords
    weight_range0.5
    max_weight1.9
    print_outputfalse
    seed_optional0

    ScramblePrompts varies the whole prompt. Sometimes that's too much - you get a different composition, a different framing, and you can't tell whether the change you're hunting for came from the hair weight or from the tag that got dropped. TweakWeights [m9] is the scalpel: you name keywords, and only the prompts matching them get their weights moved. Everything else in the prompt is untouched.

    This is the text-in, text-out variant, so it sits in a string pipeline rather than replacing your encoder. Same pack as the rest of the m9 nodes - the ComfyUI successor to the author's older sd-scramble-prompts-m9 extension for A1111/Forge.

    How it works

    The prompt model is the pack's usual one: a prompt is a phrase between commas, but not inside parentheses. (long hair, braided), red dress is two prompts, not three. Matching is case-insensitive and matches anywhere inside a prompt - hair finds long hair, and it also finds hairband. A prompt qualifies if it matches any one of your keywords.

    For each qualifying prompt, the node draws a random delta anywhere between minus and plus weight_range and applies it, with two brakes: a change that would push the weight below zero is discarded and the prompt is left as it was, and a change that would push the final weight over max_weight is not made. LoRA weights are never changed, even when a LoRA matches your keyword - a deliberate exemption, since a LoRA's weight is a load-strength slider and quietly wandering it would be a nasty surprise.

    So the randomness is in how much, never in which - the difference between this and ScramblePrompts, and why it's the better exploration tool when you already know which attribute you're tuning.

    The fields

    • prompt - an input socket, not a widget. The text lives upstream: a PrimitiveString, a prompt node, or a ScramblePromptsText m9 if you want to scramble the whole prompt and then tweak the parts you care about.
    • keywords - comma-delimited, matched as substrings. This is the field that does the work; get it wrong and the node is a no-op.
    • weight_range - the maximum adjustment in either direction, default 0.5. That's a big swing in practice.
    • max_weight - the ceiling, default 1.9. Here's the thing: community practice puts usable attention in the 0.5–1.5 band, and above 1.5 you start buying oversaturation and distortion rather than adherence. A 1.9 ceiling is a safety rail, not a target. If you're tuning a face and getting waxy results, lower this to 1.4 and see what happens.
    • print_output - logs each changed prompt with its before and after weight. With keywords left empty, this also prints a warning telling you to specify keywords, which is the node's only signal that nothing happened.
    • seed_optional - same trap as the rest of the pack: unconnected means 0, which means deterministic and cached, so you'll rerun and get the identical tweak until you wire a seed primitive into it with control_after_generate set to randomize.

    One output: prompt (STRING). Feed a CLIP Text Encode, a preview node, or another text node.

    Read this before you build a workflow on it

    Weight syntax is CLIP-era. On SD1.5, SDXL, Illustrious, Pony and anything else with a CLIP encoder, (word:1.3) is genuine attention and this node is doing real work. On the 2026 LLM-encoded models - Z-Image, Flux 2 Klein, Anima, Krea 2 - the text encoder wrapper passes disable_weights=True, and the parenthesised text arrives at the encoder as literal punctuation inside your instruction. Not weakened; discarded, and arguably worse than nothing.

    The node will still run happily and still rewrite your string. On those models you're just paying for punctuation. That's not a knock on the pack - no weight-editing node can do better, because the capability was removed in the encoder, not in the node - but it's the single most common reason someone concludes this node "does nothing".

    Installing it

    ComfyUI Manager → search m9-prompts-comfyui → install, then restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MarcusNyne/m9-prompts-comfyui
    

    Nothing else to install. No requirements.txt, no model files, no build - pure Python over torch/numpy/Pillow, all already present. The pack's string transforms are filed under the utils category (not text, which is where the pack puts StepReplace and Prefix), so search the node name from the canvas if you can't find it in the menu.

    Troubleshooting

    Nothing changed? Almost always one of three things: keywords is empty or misspelled (substring matching is forgiving, but hair won't match mane); weight_range is 0; or you're on an LLM-encoded model, where the whole mechanism is inert. Turn on print_output and it tells you which - the log prints each prompt it changed, and prints a warning when there were no keywords at all.

    A related surprise: the text coming out is normalised, not preserved. Parentheses get rewritten as the shortest equivalent form plus a :weight to three significant digits, so a hand-tuned bracket stack will look different after a pass. Copy the output text somewhere if the exact string matters to you.

    Categoryutils

    Inputs (6)

    NameTypeDefaultDescription
    promptSTRING
    keywordsSTRING
    weight_rangeFLOAT0.50–2
    max_weightFLOAT1.90–3
    print_outputBOOLEANfalse
    seed_optionaloptINT00–18446744073709550000

    Outputs (1)

    NameTypeDescription
    promptSTRING