[MAX] Add shift_terminal support for Qwen-Image#7
Conversation
Summary of ChangesHello, 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 enhances 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. Changelog
Activity
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.
Code Review
This pull request adds support for shift_terminal to the FlowMatchEulerDiscreteScheduler to allow for stretching of sigma values. However, it introduces a critical vulnerability: the lack of proper validation for the shift_terminal value can lead to a division by zero, causing an application crash (Denial of Service). A specific issue identified is a potential ZeroDivisionError if shift_terminal is exactly 1.0.
| one_minus_z = 1.0 - sigmas | ||
| scale_factor = one_minus_z[-1] / (1.0 - self.shift_terminal) | ||
| sigmas = (1.0 - (one_minus_z / scale_factor)).astype( | ||
| np.float32 | ||
| ) |
There was a problem hiding this comment.
The code performs a division by (1.0 - self.shift_terminal) on line 157. If self.shift_terminal is 1.0, this will cause a ZeroDivisionError, leading to an application crash (Denial of Service). This is a critical vulnerability as scheduler parameters are often exposed to users. It is recommended to add validation in the __init__ method to ensure shift_terminal is within a safe range, such as (0, 1). Additionally, consider handling this edge case explicitly by checking for self.shift_terminal being close to 1.0 using np.isclose and setting sigmas to 1.0 in that scenario.
| one_minus_z = 1.0 - sigmas | |
| scale_factor = one_minus_z[-1] / (1.0 - self.shift_terminal) | |
| sigmas = (1.0 - (one_minus_z / scale_factor)).astype( | |
| np.float32 | |
| ) | |
| if np.isclose(self.shift_terminal, 1.0): | |
| sigmas = np.ones(sigmas.shape, dtype=np.float32) | |
| else: | |
| one_minus_z = 1.0 - sigmas | |
| scale_factor = one_minus_z[-1] / (1.0 - self.shift_terminal) | |
| sigmas = (1.0 - (one_minus_z / scale_factor)).astype(np.float32) |
Summary
shift_terminalsupport toFlowMatchEulerDiscreteSchedulershift_terminalis unsetTesting
./bazelw run format./bazelw run lintChecklist