Extensions/comfyui-multiprompt-batch
ComfyUI Extension

comfyui-multiprompt-batch

ComfyUI custom nodes for true multi-prompt batch conditioning.

By JousiaPiha·Created 2 months ago·Updated 2 months ago· 0
JousiaPiha/comfyui-multiprompt-batch
Nodes
On cloudLocal install
Stars0
Updated2 months ago
Readme

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.

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

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

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.

Krea2 conditioning in this ComfyUI checkout is shaped like:

(B, seq, 12*2560)

The nodes stack that first batch dimension and pad sequence length where needed. attention_mask metadata is stacked and padded with invalid values for padded tokens.

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.

Troubleshooting

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, multiline encoding behavior, and latent batch index modes.

Run from this directory:

../../venv/bin/python -m unittest discover -s tests -v