Fix FluxControlNet img2img/inpainting with num_images_per_prompt>1#13519
Open
Ricardo-M-L wants to merge 1 commit intohuggingface:mainfrom
Open
Fix FluxControlNet img2img/inpainting with num_images_per_prompt>1#13519Ricardo-M-L wants to merge 1 commit intohuggingface:mainfrom
Ricardo-M-L wants to merge 1 commit intohuggingface:mainfrom
Conversation
`FluxControlNet[Img2Img|Inpaint]Pipeline` pre-resize `control_image` to `batch_size * num_images_per_prompt` but only reshape `control_mode` to `[1, 1]`, so the ControlNet-Union embedding emitted shape `[1, 1, inner_dim]` fails to concat with `encoder_hidden_states` of shape `[B*num_images_per_prompt, seq, inner_dim]`: RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 2 but got size 1 for tensor number 1 in the list. Mirror `FluxControlNetPipeline`: reject non-int `control_mode` for a single ControlNet, then `.view(-1, 1).expand(control_image.shape[0], 1)` so the mode broadcasts to every image in the batch. Fixes huggingface#10741
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?
FluxControlNetImg2ImgPipelineandFluxControlNetInpaintPipelinealready pre-resizecontrol_imagetobatch_size * num_images_per_prompt, but only reshapecontrol_modeto[1, 1]:Inside
FluxControlNetModelthe union branch feedscontrol_modetonn.Embeddingand concatenates the result toencoder_hidden_states:So when
num_images_per_prompt > 1the embedded mode stays at[1, 1, inner_dim]whileencoder_hidden_statesis[B*num_images_per_prompt, seq, inner_dim], and the concat fails:This matches the behaviour already implemented in
FluxControlNetPipeline(non-img2img), which validates thatcontrol_modeis a singleintand broadcasts it to the full image batch:This PR brings the img2img and inpainting pipelines in line with the same validation + broadcast so
num_images_per_prompt > 1works end-to-end.Fixes #10741
Before submitting
Who can review?
@sayakpaul @yiyixuxu