-
Notifications
You must be signed in to change notification settings - Fork 134
fix z-image bugs #714
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
fix z-image bugs #714
Conversation
Summary of ChangesHello @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 Highlights
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this 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.
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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.") |
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
No description provided.