Fix: Normalize batch inputs to 5D tensors for Qwen-Image-Edit #12698
+188
−78
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Enables robust batch inference for
QwenImageEditPlusPipelineby normalizing input tensor shapes, implementing a "resize" strategy, and handling variable-length prompt embeddings. Adds a new batch inference capability that did not exist previously. Also accepts list, tuples as input now, which didn't exist previously. Enables QwenImageEditPlusPipeline to be used for parallel production workflows.Description
Addresses issue #12458.
I identified four blockers preventing batch inference in the current pipeline:
5D Tensor Requirement: The underlying VAE for Qwen2-VL model treats inputs as video
(B, C, F, H, W)when batched. The pipeline was passing 4D tensors(B, C, H, W), causing immediate shape mismatches.batch_size > 1.Tensors require images in a batch to be of equal size
height/width(first priority) to ensure tensor stackability without padding artifacts.[removed padding methodology from my previous commit and went ahead with upscaling/ resizing.Tokenizer Batching Issues: The
Qwen2VLProcessorproduces variable-length embeddings for different prompts, which causedRuntimeErrororIndexErrorwhen trying to batch encode them directly.encode_promptto process prompts individually in a loop, then pad the resulting embeddings up to the maximum sequence length in the batch before concatenating.The pipeline would crash if users accidentally passed a tuple of images.
_sanitize_imageswhich recursively unwraps inputs into a clean list.Note on Batching Logic
To resolve the ambiguity between "Multi-Image Conditioning" and "Batch Inference", I implemented the following routing logic in
encode_prompt:Single String Prompt (
prompt="string"):List of Prompts (
prompt=["s1", "s2"]):Fixes #12458
Before submitting
Who can review?
@yiyixuxu @sayakpaul @DN6