Fix: Normalize batch inputs to 5D tensors for Qwen-Image-Edit #12698
+114
−41
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 batch inference for
QwenImageEditPlusPipelineby normalizing input tensor shapes and handling variable-length prompt embeddings.Description
Addresses issue #12458.
I identified two blockers preventing batch inference in the current pipeline:
5D Tensor Requirement: The underlying Qwen2-VL model treats inputs as video
(B, C, F, H, W). The pipeline was passing 4D tensors(B, C, H, W), causing immediate shape mismatches.batch_size > 1.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 to the maximum sequence length in the batch before concatenating.This ensures robust batching for both images and prompts. I also added checks to handle the
tuplevslistinput ambiguity reported in the original issue.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"]):This ensures robust batching for both images and prompts. I also added checks to handle the
tuplevslistinput ambiguity reported in the original issue.Fixes #12458
Before submitting
Who can review?
@yiyixuxu @sayakpaul @DN6