Skip to content

[fix]:flux2 i2i auto target shape#985

Merged
llmc-reviewer merged 1 commit intomainfrom
fix/flux2_i2i
Apr 2, 2026
Merged

[fix]:flux2 i2i auto target shape#985
llmc-reviewer merged 1 commit intomainfrom
fix/flux2_i2i

Conversation

@helloyongyang
Copy link
Copy Markdown
Contributor

No description provided.

@llmc-reviewer llmc-reviewer merged commit 43687e3 into main Apr 2, 2026
2 checks passed
@llmc-reviewer llmc-reviewer deleted the fix/flux2_i2i branch April 2, 2026 09:30
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the target shape assignment logic in the Flux2Klein runner, moving the i2i task shape initialization to the input encoder. However, the changes introduce a NameError in set_target_shape by using multiple_of before its definition. Additionally, the target_shape is not correctly updated when a custom shape is provided, and useful logging was removed.

Comment on lines 256 to 269
task = self.config.get("task", "t2i")
if task == "i2i" and hasattr(self.input_info, "auto_width"):
width = self.input_info.auto_width
height = self.input_info.auto_height
else:
if task == "i2i": # for i2i task, the target shape is already set in _run_input_encoder_local_i2i
height, width = self.input_info.target_shape
else: # for t2i task, calculate the target shape based on the resolution
custom_shape = self.get_custom_shape()
if custom_shape is not None:
width, height = custom_shape
else:
calculated_width, calculated_height, _ = calculate_dimensions(self.resolution * self.resolution, 16 / 9)
width = calculated_width // multiple_of * multiple_of
height = calculated_height // multiple_of * multiple_of

self.input_info.auto_width = width
self.input_info.auto_height = height

self.input_info.target_shape = (height, width)
logger.info(f"Flux2Klein Image Runner set target shape: {width}x{height}")
self.input_info.target_shape = (height, width)

multiple_of = self.config.get("vae_scale_factor", 8) * 2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The set_target_shape method contains a critical bug and a logic error:

  1. NameError: multiple_of is used on lines 265 and 266 before it is defined on line 269. This will cause a crash during execution for the t2i task.
  2. Logic Error: self.input_info.target_shape is only updated inside the else block (line 267). If a custom_shape is provided (line 261), the target_shape attribute in input_info is never updated, which will lead to incorrect behavior in subsequent pipeline stages that rely on this value.
  3. Missing Logging: The useful log message indicating the final target shape was removed.

I recommend moving the multiple_of definition to the top and ensuring target_shape is always assigned for the t2i task.

Suggested change
task = self.config.get("task", "t2i")
if task == "i2i" and hasattr(self.input_info, "auto_width"):
width = self.input_info.auto_width
height = self.input_info.auto_height
else:
if task == "i2i": # for i2i task, the target shape is already set in _run_input_encoder_local_i2i
height, width = self.input_info.target_shape
else: # for t2i task, calculate the target shape based on the resolution
custom_shape = self.get_custom_shape()
if custom_shape is not None:
width, height = custom_shape
else:
calculated_width, calculated_height, _ = calculate_dimensions(self.resolution * self.resolution, 16 / 9)
width = calculated_width // multiple_of * multiple_of
height = calculated_height // multiple_of * multiple_of
self.input_info.auto_width = width
self.input_info.auto_height = height
self.input_info.target_shape = (height, width)
logger.info(f"Flux2Klein Image Runner set target shape: {width}x{height}")
self.input_info.target_shape = (height, width)
multiple_of = self.config.get("vae_scale_factor", 8) * 2
multiple_of = self.config.get("vae_scale_factor", 8) * 2
task = self.config.get("task", "t2i")
if task == "i2i": # for i2i task, the target shape is already set in _run_input_encoder_local_i2i
height, width = self.input_info.target_shape
else: # for t2i task, calculate the target shape based on the resolution
custom_shape = self.get_custom_shape()
if custom_shape is not None:
width, height = custom_shape
else:
calculated_width, calculated_height, _ = calculate_dimensions(self.resolution * self.resolution, 16 / 9)
width = calculated_width // multiple_of * multiple_of
height = calculated_height // multiple_of * multiple_of
self.input_info.target_shape = (height, width)
logger.info(f"Flux2Klein Image Runner set target shape: {width}x{height}")

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.

2 participants