Nodes/comfyui-multiprompt-batch/Krea2 Attention Mask Patch
ComfyUI Node

Krea2 Attention Mask Patch

Krea2 rendering every prompt black except the longest? This patch is the fix

By JousiaPiha·Created 2 months ago·Updated 4 days ago· 0
Krea2 Attention Mask Patch
  • model
  • MODEL

You've built a Krea 2 workflow that renders several prompts in a single sampler run - one latent batch item per prompt - and every image comes out black except the one from the longest prompt. That's not bad luck and it's not the sampler. That's padding, and this node is the fix.

Here's what's happening. Krea 2's text encoder is Qwen3-VL, and to run a batch of prompts through it you have to give every row the same token length. Krea 2's layout is a fixed 512-token sequence, so shorter prompts get blank padding tokens shoved in to fill the row. The problem is the diffusion model: if nobody tells its attention layers which tokens are padding, it happily attends to that garbage, and the short prompts drown. Only the prompt that didn't need padding - the longest one - comes out clean. Krea2AttentionMaskPatch is the part that carries the "these tokens are padding, ignore them" memo through the whole sampling run.

What it actually does

Mechanically it's boring in the best way. You feed it the Krea 2 MODEL and it hands back a patched clone of that same model - the input is model, the output is MODEL, and that's the entire interface. No sliders, no weights, no modes.

Under the hood it checks the model is actually Krea 2 (it looks for the txtfusion and _unpack_context plumbing Krea 2 models expose - feed it anything else and it raises a clear "requires a Krea2 MODEL input" error), then registers a keyed diffusion-model wrapper using ComfyUI's model-wrapper API. On every diffusion step the wrapper reads the attention_mask riding on the conditioning, converts the padding positions into a key-padding attention bias, and splices that mask into both of Krea 2's attention paths: the text-fusion attention and the joint text/image attention. It scopes its method overrides to each call and restores them even when something throws. It does not modify any core ComfyUI file, and it only does anything when there's an actual mask to honor - on a single prompt it's effectively a no-op, which is why you can leave it in your graph without worrying.

You need the patch's sibling from the same pack, Multi Prompt Text Encode, to make this whole thing work: that node pads each prompt row to the fixed token layout before the Qwen encoder runs, so it produces a real batch dimension, and it's the one that attaches the boolean attention_mask to the conditioning in the first place.

Wiring it in

It belongs on the model path, not the CLIP path:

Krea2 model loader -> Krea2 Attention Mask Patch -> KSampler model
MultiPromptTextEncode (positive) -> KSampler positive
EmptyLatentImage (batch_size = prompt count) -> KSampler latent_image

One thing people trip on: you don't need to batch the negative. A negative conditioning batch of 1 broadcasts fine - keep your ConditioningZeroOut or empty negative as-is.

Install

ComfyUI Manager is the easy route - search "comfyui-multiprompt-batch" and install. Or the manual way:

cd ComfyUI/custom_nodes
git clone https://github.com/JousiaPiha/comfyui-multiprompt-batch

Restart ComfyUI and the nodes appear under conditioning/multi prompt batch. There are no Python dependencies and nothing extra to download - this is pure orchestration that reuses the three Krea 2 files you already need anyway (the model, the Qwen3-VL text encoder around 8GB, and the Qwen-Image VAE).

When it breaks

The failure you'll actually see: only the longest prompt renders, the rest are black. That's the exact symptom this node exists for, so if you hit it, confirm the patch is between the model loader and KSampler, that you're using Multi Prompt Text Encode rather than separate CLIPTextEncode nodes, and restart ComfyUI after updating the pack.

Two errors worth knowing. If you get a RuntimeError about lacking keyed diffusion-model wrappers, your ComfyUI is too old - update it, this relies on a fairly recent model-wrapper feature. And the shape-checking gotcha: if KSampler throws, verify the positive conditioning batch matches the latent batch (positive[0][0].shape[0] == latent["samples"].shape[0]). Equal-length prompts can slip through without the patch since nothing needs padding, but the moment one prompt is shorter than the rest, you're back to black images.

Categoryconditioning/multi prompt batch

Inputs (1)

NameTypeDefaultDescription
modelMODEL

Outputs (1)

NameTypeDescription
MODELMODEL