Skip to content

[fix] Flux Kontext resize method #11863

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Net-Mist
Copy link
Contributor

@Net-Mist Net-Mist commented Jul 4, 2025

What does this PR do?

Hello !

When working on Flux-Kontext, I discovered a silent bug regarding the resizing of the image, when calling the pipeline with several images.

  • The __call__ method of the FluxKontextPipeline class takes an image of type Optional[PipelineImageInput]. This variable can be a list in case of batch size > 1
  • then the resize method of the VaeImageProcessor class is called (image = self.image_processor.resize(image, image_height, image_width)). But this method does not support lists as input. Due to the way this method is written (overriding the image variable and then returning it), it doesn't resize the image and return it as-is.

In this fix, I corrected this by changing a minimal number of lines of code to handle lists. However, please let me know if you'd prefer that I also add additional input checks or safeguards.

Fixes # (issue)

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@Net-Mist
Copy link
Contributor Author

Net-Mist commented Jul 4, 2025

@yiyixuxu @asomoza
If I'm not mistaken, you are the 2 most relevant people for this PR. Else, sorry for the noise, and please redirect me to the right people

@Net-Mist Net-Mist changed the title [fix] VaeImageProcessor.resize method can take list as input [fix] Flux Kontext resize method Jul 7, 2025
@Net-Mist
Copy link
Contributor Author

Hi @asomoza !
Just following up on this PR to get your feedback. Apologies if this isn’t the right process—if that’s the case, could you please let me know the proper steps?

@asomoza
Copy link
Member

asomoza commented Jul 21, 2025

thanks @Net-Mist the resize function is more of an internal method that's called from the preprocess function, in that case, it resizes the image correctly even if it is a list.

I think the best option here is to refactor the pipeline which is the only case that this happens instead of the resize function that all the pipelines use which will add one more check they don't need.

Also I don't understand fully why the kontext pipeline uses the resize and the preprocess separately, so ccing @a-r-r-o-w who is better suited to do a review of this PR.

@asomoza asomoza requested a review from a-r-r-o-w July 21, 2025 12:57
@@ -523,6 +523,16 @@ def resize(
size=(height, width),
)
image = self.pt_to_numpy(image)
elif isinstance(image, list):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think resize is intended to only accept single image
@a-r-r-o-w any reason we run resize sepereately here? (instead of being part of the preprocess)?

image = self.image_processor.resize(image, image_height, image_width)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think preprocess should be okay. I don't remember why I used resize (maybe I just forgot that preprocess existed when I wrote this code. either way I don't remember the context now, but I'll check original repo again)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants