CLIP Text Encode Batch KV Multiply ๐
Split what the model attends to from what it renders
- model
- clip
- MODEL
- CONDITIONING
If you've ever wondered what happens if you feed a diffusion model two different prompts at once - one for what it pays attention to, one for what it actually paints - this node is that experiment made clickable. It lives in cgem156-ComfyUI's for_test folder, which is the author's own way of labeling it: this is a lab bench node, not a load-bearing part of anyone's production workflow.
What it's poking at
Cross-attention in a diffusion U-Net works by projecting your text embedding into two things: keys (K) and values (V). Keys decide where in the image the model looks when a given word matters; values decide what gets written there once it's decided to look. Normally both come from the same text encoding, so "a red fox" steers attention toward fox-shaped regions and also supplies the "red fox" content to paint into them. This node decouples that: you give it text_k for the key side and text_v for the value side separately, and it patches the model so attention is computed with one prompt's keys but another prompt's values.
Practically, that means you could ask the model to attend the way prompt A would (its composition, its spatial focus) while rendering the content prompt B describes. Whether that produces something coherent or just noise depends heavily on how far apart the two prompts are - this is squarely in "try it and see" territory, which is exactly what a for_test node is for.
Inputs and outputs
Four required inputs, no optional ones:
- model / clip - your usual MODEL and CLIP, same as any text encode node.
- text_k - the prompt whose embedding drives the attention keys.
- text_v - the prompt whose embedding drives the attention values.
Two outputs: a patched MODEL (wire it into your KSampler in place of the checkpoint's model) and a CONDITIONING (the encoding of text_v, wired in as your positive conditioning the normal way). Both outputs need to go somewhere - the model patch and the conditioning are two halves of the same trick, and using one without the other just gives you a normal encode.
Installing it
Search "cgem156-ComfyUI" in ComfyUI Manager, or do it by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/laksjdjf/cgem156-ComfyUI
Restart ComfyUI. The pack ships as one shared install - you get all its scripts (attention_couple, the Dart nodes, the WD-tagger tools, custom samplers, and this one) in a single clone, no per-feature setup. Nothing here needs extra model downloads; it's pure attention-graph surgery on whatever checkpoint you already have loaded.
Where this actually goes wrong
Because it's untouched by any real userbase, there's no accumulated troubleshooting wisdom to lean on here - the honest answer is you're the QA team. A few things worth knowing going in: this only makes sense with SD 1.5/SDXL-style cross-attention (the UNet architecture the pack targets), not on DiT/flow-matching checkpoints like Flux or Z-Image, whose attention wiring is different and which cgem156 wasn't built for. And if text_k and text_v describe wildly different scenes, don't be surprised by melted, incoherent results - that's the attention mechanism getting genuinely confused, not a bug. Start with two prompts that differ in one axis (say, same subject, different pose description for the keys) rather than two unrelated scenes, so you can actually tell what the split did.
Worth knowing about the wider pack while you're in here: cgem156 is also where attention_couple comes from - the regional-prompting node that Forge Couple and ComfyUI's ComfyCouple both trace back to. The author tends to ship the working idea first and let other people build the friendlier version later, and this KV-multiply node reads like an earlier-stage entry in that same pipeline.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | โ | |
| clip | CLIP | โ | |
| text_k | STRING | โ | |
| text_v | STRING | โ |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | โ |
| CONDITIONING | CONDITIONING | โ |