Skip to content

Commit de10be4

Browse files
committed
Expose max_area for condition images in Flux2 pipelines
The condition/reference image downscale threshold was hardcoded to 1024*1024 in Flux2Pipeline, Flux2KleinPipeline and Flux2KleinKVPipeline, silently downscaling any reference image above ~1MP. Expose it as a max_area __call__ argument (default unchanged), mirroring the existing max_area parameter of FluxKontextPipeline.
1 parent cbdb637 commit de10be4

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/diffusers/pipelines/flux2/pipeline_flux2.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,7 @@ def __call__(
765765
max_sequence_length: int = 512,
766766
text_encoder_out_layers: tuple[int] = (10, 20, 30),
767767
caption_upsample_temperature: float = None,
768+
max_area: int = 1024**2,
768769
):
769770
r"""
770771
Function invoked when calling the pipeline for generation.
@@ -832,6 +833,9 @@ def __call__(
832833
caption_upsample_temperature (`float`):
833834
When specified, we will try to perform caption upsampling for potentially improved outputs. We
834835
recommend setting it to 0.15 if caption upsampling is to be performed.
836+
max_area (`int`, defaults to `1024 ** 2`):
837+
The maximum area (in pixels) allowed for each condition image. Condition images whose area exceeds
838+
this value are downscaled to fit it while preserving their aspect ratio.
835839
836840
Examples:
837841
@@ -891,8 +895,8 @@ def __call__(
891895
condition_images = []
892896
for img in image:
893897
image_width, image_height = img.size
894-
if image_width * image_height > 1024 * 1024:
895-
img = self.image_processor._resize_to_target_area(img, 1024 * 1024)
898+
if image_width * image_height > max_area:
899+
img = self.image_processor._resize_to_target_area(img, max_area)
896900
image_width, image_height = img.size
897901

898902
multiple_of = self.vae_scale_factor * 2

src/diffusers/pipelines/flux2/pipeline_flux2_klein.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ def __call__(
632632
callback_on_step_end_tensor_inputs: list[str] = ["latents"],
633633
max_sequence_length: int = 512,
634634
text_encoder_out_layers: tuple[int] = (9, 18, 27),
635+
max_area: int = 1024**2,
635636
):
636637
r"""
637638
Function invoked when calling the pipeline for generation.
@@ -700,6 +701,9 @@ def __call__(
700701
max_sequence_length (`int` defaults to 512): Maximum sequence length to use with the `prompt`.
701702
text_encoder_out_layers (`tuple[int]`):
702703
Layer indices to use in the `text_encoder` to derive the final prompt embeddings.
704+
max_area (`int`, defaults to `1024 ** 2`):
705+
The maximum area (in pixels) allowed for each condition image. Condition images whose area exceeds
706+
this value are downscaled to fit it while preserving their aspect ratio.
703707
704708
Examples:
705709
@@ -769,8 +773,8 @@ def __call__(
769773
condition_images = []
770774
for img in image:
771775
image_width, image_height = img.size
772-
if image_width * image_height > 1024 * 1024:
773-
img = self.image_processor._resize_to_target_area(img, 1024 * 1024)
776+
if image_width * image_height > max_area:
777+
img = self.image_processor._resize_to_target_area(img, max_area)
774778
image_width, image_height = img.size
775779

776780
multiple_of = self.vae_scale_factor * 2

src/diffusers/pipelines/flux2/pipeline_flux2_klein_kv.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ def __call__(
627627
callback_on_step_end_tensor_inputs: list[str] = ["latents"],
628628
max_sequence_length: int = 512,
629629
text_encoder_out_layers: tuple[int] = (9, 18, 27),
630+
max_area: int = 1024**2,
630631
):
631632
r"""
632633
Function invoked when calling the pipeline for generation.
@@ -668,6 +669,9 @@ def __call__(
668669
Maximum sequence length for the prompt.
669670
text_encoder_out_layers (`tuple[int]`):
670671
Layer indices for text encoder hidden state extraction.
672+
max_area (`int`, defaults to `1024 ** 2`):
673+
The maximum area (in pixels) allowed for each condition image. Condition images whose area exceeds
674+
this value are downscaled to fit it while preserving their aspect ratio.
671675
672676
Examples:
673677
@@ -720,8 +724,8 @@ def __call__(
720724
condition_images = []
721725
for img in image:
722726
image_width, image_height = img.size
723-
if image_width * image_height > 1024 * 1024:
724-
img = self.image_processor._resize_to_target_area(img, 1024 * 1024)
727+
if image_width * image_height > max_area:
728+
img = self.image_processor._resize_to_target_area(img, max_area)
725729
image_width, image_height = img.size
726730

727731
multiple_of = self.vae_scale_factor * 2

0 commit comments

Comments
 (0)