Nodes/m9-prompts-comfyui/TweakWeights_m9
ComfyUI Node

TweakWeights_m9

Reweight the keywords you name, leave the rest of the prompt alone

By MarcusNyne·Created 2 years ago·Updated 8 days ago· 1
TweakWeights_m9
  • clip
  • conditioning_optional
  • CONDITIONING
prompt
keywords
weight_range0.5
max_weight1.9
print_outputfalse
seed_optional0

Hand-editing prompt weights is fiddly. (cat:1.3) one run, (cat:1.1) the next, regenerate, squint. This node automates the boring part: you name the keywords, it randomly nudges the weight of every prompt chunk containing them, and encodes the result straight into conditioning for your KSampler. It's the sibling of ScramblePrompts_m9 in the same pack, and it's the more surgical one.

The difference matters. Scramble picks a random subset of everything and randomizes it, which is fun until the roulette keeps wrecking the one concept you care about. Tweak only touches what you name - and it hits all matches, not a random sample. That makes it the node you reach for when "cat" is consistently under-emphasized and you want to probe whether more attention actually helps.

How it works

You feed it a comma-delimited keywords list. The node splits your prompt into comma-chunks (parens-aware, same grammar as its sibling) and does a case-insensitive substring match against each chunk's text. Every chunk that matches gets its CLIP weight adjusted by a random amount up to ±weight_range, clamped so nothing drops below zero or exceeds max_weight. Chunks that don't match are untouched. LoRA tags are skipped entirely - the code passes them a zero adjustment range, so your <lora:...> lines survive intact.

The weight lands back in standard token:weight syntax before encoding. And the jitter is seeded: the same seed produces the same tweaks, so you can reproduce a result and tune weight_range up and down to see if stronger emphasis actually moves the image.

The inputs that matter

  • prompt and clip - your text and the CLIP model, same as a text encoder.
  • keywords - the whole node lives or dies here. Comma-delimited; matching is case-insensitive substring, so cat also catches cattle and scatter. Be specific if you're picky.
  • weight_range (default 0.5) - the maximum ± jitter. The practical CLIP weighting range is roughly 0.5–1.5, so start modest.
  • max_weight (default 1.9) - the ceiling. Changes that would push past it are skipped.
  • print_output - logs each "Weight changed from X to Y" to the console. If keywords is empty it prints a warning instead, which is how you'll discover you typo'd your way into a no-op.

Optional inputs: seed_optional and conditioning_optional, the latter letting you stack this node's output onto another prompt node's conditioning.

The caching trap (same one as its sibling)

Leave seed_optional unplugged and ComfyUI runs this node exactly once, then serves the cached result forever - the tweak appears to happen once and never again. It's not broken; the graph is caching. Wire a seed primitive into seed_optional and each seed gives you a fresh jitter. If anything about this pack confuses newcomers, it's this, and the README warns about it explicitly.

Install

ComfyUI Manager → search m9 Prompts → Install → restart. Or by hand:

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

then restart. No dependencies, no model downloads - pure Python on the standard library. It appears under the M9 Prompts category alongside ScramblePrompts.

The honest caveat

The output is CLIP attention syntax, which means this is an SD 1.5 / SDXL / Illustrious / NoobAI / Pony tool. On Flux, Z-Image and the other LLM-encoded models, token:weight is discarded by the encoder, so the node becomes a pointless text pass-through. On the CLIP lineage it earns its keep: name the under-performing concept, wire up a seed, batch a few runs, and let the console log tell you what changed.

CategoryM9 Prompts

Inputs (8)

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

Outputs (1)

NameTypeDescription
CONDITIONINGCONDITIONING