Skip to content

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
huggingface:mainfrom
Liauuu:pr4
Open

Fix silent feature mixing bug in IP-Adapter batch processing by removing redundant batch_size multiplication (#9813)#13959
Liauuu wants to merge 1 commit into
huggingface:mainfrom
Liauuu:pr4

Conversation

@Liauuu

@Liauuu Liauuu commented Jun 15, 2026

Copy link
Copy Markdown

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 passing batch_size * num_images_per_prompt (or batch_size * num_videos_per_prompt) as the num_images_per_prompt argument.
Since the input ip_adapter_image_embeds tensor 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 * (and num_videos_per_prompt equivalents) multiplication from all prepare_ip_adapter_image_embeds call sites across src/diffusers/pipelines/. Now, only num_images_per_prompt (or num_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

  • This PR fixes a bug or adds a feature rather than fixing formatting.
  • Did you read the contributor guideline?
  • Did you write tests? (N/A, validated via existing batch-mode structure and user reproduction)
  • Was this discussed before in an issue? (Linked above)

@github-actions github-actions Bot added fixes-issue pipelines size/M PR with diff < 200 LOC and removed fixes-issue labels Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pipelines size/M PR with diff < 200 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prepare_ip_adapter_image_embeds Bug Causes Feature Mixing During Batch Processing in IP-Adapter

1 participant