-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Fix: Normalize batch inputs to 5D tensors for Qwen-Image-Edit #12698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Hey @sayakpaul @yiyixuxu, let me know if I have to make any changes. But the functionality works as intended! |
|
the mask output from encode_prompt is not used in attention calculation https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/transformers/transformer_qwenimage.py#L338 (it's always None here) we will not move forward with this PR. |
|
Thanks for the clarification, that helps. Edit: |
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