Skip to content

Conversation

@gushiqiao
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gushiqiao, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses several issues within the z-image components, primarily focusing on robust configuration handling and image dimension calculations. The changes ensure correct retrieval of configuration parameters like vae_scale_factor and streamline the process of setting target image shapes based on custom_shape or aspect_ratio settings. Additionally, it includes a minor refactor for better import management.

Highlights

  • Configuration Key Update: The configuration key for the number of transformer layers in ZImageTransformerWeights has been updated from num_layers to n_layers for consistency.
  • Corrected Configuration Access: Incorrect calls to config.get (missing parentheses) have been fixed to proper dictionary access config[...] for vae_scale_factor in z_image_runner.py.
  • Improved Image Shape Handling: The logic for determining target image shapes in set_target_shape and set_img_shapes has been refactored to robustly handle custom_shape (now parsed from a string) and aspect_ratio configurations, including raising a NotImplementedError for unhandled scenarios.
  • Simplified Latent Channel Calculation: The determination of num_channels_latents has been streamlined by removing task-specific conditional logic, now consistently using a default value if not specified in the configuration.
  • Code Organization: The import of torch.nn.functional has been moved to the top of scheduler.py, eliminating a redundant local import within a method for cleaner code.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gushiqiao gushiqiao merged commit 3ab49a1 into main Jan 6, 2026
2 checks passed
@gushiqiao gushiqiao deleted the gsq/z-image branch January 6, 2026 10:17
Copy link
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 introduces several bug fixes for the z-image functionality. The changes correct configuration key names, fix improper dictionary access, and refactor how image dimensions are determined. My review focuses on improving the robustness of the new configuration parsing logic and addressing code duplication. I've suggested adding error handling for parsing custom_shape and looking up aspect_ratio to prevent crashes from invalid configurations. I also recommend refactoring duplicated logic into a helper method to improve maintainability.

Comment on lines +243 to +250
if self.config.get("custom_shape", None) is not None:
parts = self.config["custom_shape"].split(",")
height = int(parts[0].strip())
width = int(parts[1].strip())
elif self.config.get("aspect_ratio", None) is not None:
width, height = ASPECT_RATIO_MAP[self.config["aspect_ratio"]]
else:
width, height = self.config.get("aspect_ratios", ASPECT_RATIO_MAP)[self.config["aspect_ratio"]]
raise NotImplementedError
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The logic for determining image dimensions from the configuration is not robust. It can crash with an unhandled IndexError, ValueError, or KeyError if custom_shape has an invalid format or aspect_ratio is not a valid key. This can lead to unexpected application failures. It's better to add explicit validation and error handling. Additionally, NotImplementedError should be replaced with ValueError for a missing configuration, as this is an issue with input data, not an unimplemented feature.

Suggested change
if self.config.get("custom_shape", None) is not None:
parts = self.config["custom_shape"].split(",")
height = int(parts[0].strip())
width = int(parts[1].strip())
elif self.config.get("aspect_ratio", None) is not None:
width, height = ASPECT_RATIO_MAP[self.config["aspect_ratio"]]
else:
width, height = self.config.get("aspect_ratios", ASPECT_RATIO_MAP)[self.config["aspect_ratio"]]
raise NotImplementedError
if self.config.get("custom_shape") is not None:
try:
height_str, width_str = self.config["custom_shape"].split(",")
height = int(height_str.strip())
width = int(width_str.strip())
except ValueError:
raise ValueError(f"Invalid custom_shape format: {self.config.get('custom_shape')}. Expected 'height,width'.")
elif self.config.get("aspect_ratio") is not None:
aspect_ratio = self.config["aspect_ratio"]
try:
width, height = ASPECT_RATIO_MAP[aspect_ratio]
except KeyError:
raise ValueError(f"Invalid aspect_ratio: {aspect_ratio}. Supported values are {list(ASPECT_RATIO_MAP.keys())}")
else:
raise ValueError("Either 'custom_shape' or 'aspect_ratio' must be provided in the config.")

Comment on lines +267 to +274
if self.config.get("custom_shape", None) is not None:
parts = self.config["custom_shape"].split(",")
height = int(parts[0].strip())
width = int(parts[1].strip())
elif self.config.get("aspect_ratio", None) is not None:
width, height = ASPECT_RATIO_MAP[self.config["aspect_ratio"]]
else:
width, height = self.config.get("aspect_ratios", ASPECT_RATIO_MAP)[self.config["aspect_ratio"]]
vae_scale_factor = self.config.get["vae_scale_factor"]
raise NotImplementedError
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This block of code for determining height and width is nearly identical to the one in the set_target_shape method (lines 243-250). This code duplication makes the code harder to maintain, as any changes or bug fixes would need to be applied in both places.

To improve maintainability, this logic should be extracted into a private helper method. For example:

def _get_dimensions_from_config(self):
    if self.config.get("custom_shape") is not None:
        try:
            height_str, width_str = self.config["custom_shape"].split(",")
            height = int(height_str.strip())
            width = int(width_str.strip())
        except ValueError:
            raise ValueError(f"Invalid custom_shape format: {self.config.get('custom_shape')}. Expected 'height,width'.")
        return height, width
    elif self.config.get("aspect_ratio") is not None:
        aspect_ratio = self.config["aspect_ratio"]
        try:
            width, height = ASPECT_RATIO_MAP[aspect_ratio]
        except KeyError:
            raise ValueError(f"Invalid aspect_ratio: {aspect_ratio}. Supported values are {list(ASPECT_RATIO_MAP.keys())}")
        return width, height
    else:
        raise ValueError("Either 'custom_shape' or 'aspect_ratio' must be provided in the config.")

# Then call it in both set_target_shape and set_img_shapes
# height, width = self._get_dimensions_from_config()

This would also be a good place to apply the robustness improvements suggested for set_target_shape.

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.

3 participants