Nodes/ComfyUI DenseDiffusion/DenseDiffusion Apply
ComfyUI Node

DenseDiffusion Apply

DenseDiffusion Apply is where your region masks finally bite into attention

By huchenlei·Created 2 years ago·Updated about a year ago· 161
DenseDiffusion Apply
  • model
  • MODEL
  • CONDITIONING

Every regional prompting setup has a boring-looking node that does the actual heavy lifting, and in this pack that's DenseDiffusion Apply. Its sibling Add Cond just collects per-region prompts and masks; this is the node that takes all of them and forces the model to respect them. One input, two outputs, and if you're coming from the core-node way of doing regional conditioning (ConditioningSetMask + stacking conditions), this is the point where the two approaches diverge.

What it does

Apply clones your model and swaps the cross-attention layers in the UNet - all of them, across input, middle, and output blocks - for a masked attention function borrowed from the Omost project. Normal attention is roughly y = softmax(q@k)@v. DenseDiffusion rewrites it as y = softmax(modify(q@k))@v, where modify() masks out anything outside each region and rescales the scores inside it. A token in the left region's mask literally cannot pay attention to the image area you assigned to the right region's prompt. That's the whole trick, and it's why this beats hoping a long prompt sorts itself out: it's intervention inside attention, not after the fact.

The author is upfront that this is the Omost implementation, not the original Naver DenseDiffusion - in their testing the original didn't perform well, so they ported the version that ships in lllyasviel/Omost. The node detects your model's SD version (SD 1.5 vs SDXL) and applies the right attention layout automatically.

The one input and the two outputs that confuse everyone

Input: just model - the output of your last DenseDiffusion Add Cond node (or the plain base model if you have zero regions, which is pointless; it asserts that conditioning exists).

Outputs:

  • MODEL - wire this to your KSampler's model input.
  • CONDITIONING - this is the sneaky one. Apply gathers every region's text embeddings, concatenates them, and hands you a single conditioning tensor. Wire it to the sampler's positive input. People regularly miss this and feed the sampler the original text encode instead - then wonder why the masks did nothing.

So the tail of a working workflow looks like: a chain of Add Conds → Apply → MODEL and CONDITIONING both into the KSampler. Negative stays a normal (unmasked) empty conditioning.

How to install

ComfyUI Manager → search "DenseDiffusion" → install → restart. Terminal route:

cd ComfyUI/custom_nodes
git clone https://github.com/huchenlei/ComfyUI_densediffusion

No model files, no pip requirements beyond ComfyUI itself - the whole pack is a couple of Python files riding on ComfyUI's set_model_attn2_replace patching. It just works.

Troubleshooting

  • "No DenseDiffusion conditioning found!" - you fed Apply a model that never passed through an Add Cond. Chain at least one region node before it.
  • It doesn't compose with IPAdapter. The README flags this loudly: ComfyUI's attention replacements don't stack, so this regional method and IPAdapter conflict. If you need both, they don't play together yet; the author says a universal model patcher is on the way.
  • Works best on SD 1.5 / SDXL. Regional prompting is architecture-dependent, and this pack targets the cross-attention layout of classic Stable Diffusion. It's not a Flux tool.

Real-world usage is modest but real: on r/comfyui the pack gets recommended specifically when someone wants regional prompting on SDXL, with the bundled example workflow cited as the cleanest way to compare it against core-node ConditioningSetMask. For two cleanly-separated characters it's the pack people point to - just remember regional prompting always struggles once subjects overlap or touch. If that's your use case, no attention trick fully rescues it.

CategoryDenseDiffusion

Inputs (1)

NameTypeDefaultDescription
modelMODEL

Outputs (2)

NameTypeDescription
MODELMODEL
CONDITIONINGCONDITIONING