Fix silent feature mixing bug in IP-Adapter batch processing by removing redundant batch_size multiplication (#9813)#13959
Open
Liauuu wants to merge 1 commit into
Open
Fix silent feature mixing bug in IP-Adapter batch processing by removing redundant batch_size multiplication (#9813)#13959Liauuu wants to merge 1 commit into
Liauuu wants to merge 1 commit into
Conversation
…ing redundant batch_size multiplication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
This PR fixes a silent feature mixing bug in IP-Adapter batch processing across all pipeline variants (57 files in total).
Cause of the Bug
When invoking
prepare_ip_adapter_image_embeds, the pipelines were incorrectly passingbatch_size * num_images_per_prompt(orbatch_size * num_videos_per_prompt) as thenum_images_per_promptargument.Since the input
ip_adapter_image_embedstensor provided by the user already incorporates the batch dimension, this redundant multiplication caused the tensor to be duplicated/replicated exponentially inside the function.Downstream, the cross-attention layer (
IPAdapterAttnProcessor2_0) reshaped this bloated tensor using a flexible.view(batch_size, -1, ...)operation. Instead of throwing a shape mismatch error, the redundant tensors were quietly appended along the sequence length dimension, causing cross-batch feature blending (e.g., identity mixing in generation outputs).Solution
Removed the redundant
batch_size *(andnum_videos_per_promptequivalents) multiplication from allprepare_ip_adapter_image_embedscall sites acrosssrc/diffusers/pipelines/. Now, onlynum_images_per_prompt(ornum_videos_per_prompt) is passed, maintaining the strict 1:1 correspondence for each reference image in batch mode without breaking single-image generations.Fixes #9813
Before submitting