comfyui-multiprompt-batch
ComfyUI custom nodes for true multi-prompt batch conditioning.
Nodes (4)
The batch aligner
Krea2 rendering every prompt black except the longest? This patch is the fix
The seed-sharing knob for batches
One sampler run, a whole grid of different images
ComfyUI Multi Prompt Batch
ComfyUI custom nodes for true multi-prompt batch conditioning.
This is not queue automation. The goal is one sampler execution where latent batch item 1 uses prompt 1, latent batch item 2 uses prompt 2, and so on.
prompt 1 -> conditioning batch item 1 -> image 1
prompt 2 -> conditioning batch item 2 -> image 2
prompt 3 -> conditioning batch item 3 -> image 3
Nodes
Multi Prompt Text Encode
Encodes one prompt per line with the connected CLIP object and returns:
CONDITIONING conditioning
INT batch_size
STRING prompt_list_text
Use batch_size as the value for EmptyLatentImage.batch_size.
For two or more Krea2 prompts, this node tokenizes every line first, pads or truncates each token row to Krea2's fixed 512-token post-prefix layout, and invokes the underlying Qwen encoder once with a real batch dimension. The five-token assistant suffix is preserved at the end of every row. A single Krea2 prompt continues to use ComfyUI's stock encoding path for parity.
Conditioning Batch Stack
Stacks 2 to 9 existing simple CONDITIONING inputs into one batch-aligned conditioning entry.
This is useful for proving sampler compatibility:
CLIPTextEncode("a red sports car")
CLIPTextEncode("a blue medieval castle")
|
Conditioning Batch Stack
|
KSampler positive
For Krea2 prompts of different lengths, use Multi Prompt Text Encode instead. Once Krea2 prompts have already been encoded separately, this stack node cannot reconstruct the fixed token layout or true batched Qwen encoder call.
Krea2 Attention Mask Patch
Krea2 requires an attention mask when prompts have different token lengths. Connect this node between the Krea2 model loader and KSampler:
Krea2 model loader -> Krea2 Attention Mask Patch -> KSampler model
Multi Prompt Text Encode creates the fixed-length Krea2 token batch and its boolean mask before Qwen encoding. This model patch applies that mask in Krea2's text-fusion attention and its joint text/image attention. It uses ComfyUI's model-wrapper API and does not modify core ComfyUI files.
Without this node on ComfyUI versions that do not propagate Krea2's mask internally, shorter prompts can produce black images while only the longest prompt succeeds.
Latent Batch Index
Controls KSampler noise reuse through latent["batch_index"].
different_noise_per_prompt clears batch_index and keeps normal ComfyUI batch noise behavior
same_noise_for_all_prompts sets [0, 0, 0, ...]
custom_batch_indices parses comma/whitespace integers such as 0, 0, 1, 1
Install
Place this folder under:
ComfyUI/custom_nodes/comfyui-multiprompt-batch/
Restart ComfyUI. The nodes appear under:
conditioning/multi prompt batch
Minimal Krea2 Workflow
For the official Krea2 FP8 workflow, keep the normal model, VAE, sampler, and save nodes. Replace the positive prompt encoder with Multi Prompt Text Encode.
Multi Prompt Text Encode
|
v
KSampler positive
Krea2 diffusion model
|
v
Krea2 Attention Mask Patch
|
v
KSampler model
ConditioningZeroOut
|
v
KSampler negative
EmptyLatentImage, batch_size = prompt count
|
v
KSampler latent_image
Example prompts:
a red sports car on a white studio background
a blue medieval castle on a snowy mountain
a green alien forest with glowing mushrooms
Set EmptyLatentImage.batch_size to 3.
The Krea2 Attention Mask Patch is required for unequal-length prompts with the current native Krea2 implementation. Equal-length prompts may appear to work without it because no batch item needs padding.
Krea2 multi-prompt conditioning is shaped like:
(B, 512, 12*2560)
The prompt token rows are padded or truncated before the Qwen text encoder runs. The Qwen hidden states therefore retain a real batch dimension instead of being encoded separately and padded afterward. The resulting attention_mask is propagated through ComfyUI's sampler model conditions.
Noise Control
Normal batch generation uses different initial noise per image. You do not need Latent Batch Index for that.
Use Latent Batch Index only when you want explicit control:
EmptyLatentImage -> Latent Batch Index -> KSampler latent_image
For same initial noise across different prompts, choose:
same_noise_for_all_prompts
For custom reuse patterns, choose:
custom_batch_indices
and enter one index per latent item.
Known Limitations
The first implementation intentionally supports simple text conditioning only:
[
[cond_tensor, metadata_dict]
]
It rejects complex conditioning lists, regional prompts, masks, ControlNet, GLIGEN, hooks, and scheduled prompt conditioning in the stack step. Add those later in the workflow after the core prompt batch is working.
Non-tensor metadata must match across prompts. Tensor metadata is concatenated across batch when its first dimension matches the source conditioning batch or is 1.
Krea2 multi-prompt encoding does not support scheduled CLIP hooks or prompt weighting. Krea2's tokenizer disables prompt weighting in the normal ComfyUI path as well.
The Krea2 encoder and model patches scope temporary method overrides to each call and restore them even if encoding or sampling raises an error. This matches ComfyUI's standard serialized prompt execution. Do not concurrently encode or sample patched and unpatched clones that share the same underlying Krea2 instances.
Troubleshooting
Only the longest prompt works; shorter outputs are black
Use Multi Prompt Text Encode, add Krea2 Attention Mask Patch to the model path, and restart ComfyUI after installing or updating this extension:
MODEL -> Krea2 Attention Mask Patch -> KSampler
This symptom occurs when variable-length prompts are encoded separately and their Qwen hidden states are padded only afterward. Krea2 batching must instead align the token rows before one batched Qwen encoder call, then preserve the resulting mask through diffusion attention.
If KSampler raises a shape error, check:
latent["samples"].shape[0]
positive[0][0].shape[0]
positive[0][1].keys()
positive[0][1]["attention_mask"].shape, if present
negative[0][0].shape[0]
latent.get("batch_index")
The positive conditioning batch should match the latent batch:
latent["samples"].shape[0] == positive[0][0].shape[0]
A shared negative conditioning batch of 1 is expected to broadcast through ComfyUI's sampler conditioning path.
Development Check
This package includes unittest coverage for parsing, conditioning tensor stacking, metadata padding, Krea2 fixed token layout and true batch encoding, Krea2 mask propagation, multiline encoding behavior, and latent batch index modes.
Run from this directory:
../../venv/bin/python -m unittest discover -s tests -v