-
Notifications
You must be signed in to change notification settings - Fork 89
(core/diffusers): AutoencoderMixin to abstract common methods #1444
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
base: master
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @Cui-yshoho, 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 significantly refactors the autoencoder architecture by introducing an Highlights
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 an AutoencoderMixin to abstract common methods like enable_tiling, disable_tiling, enable_slicing, and disable_slicing. This is a great refactoring that improves code reuse and maintainability across various autoencoder models.
My review includes suggestions to improve the consistency of the new mixin and to correct its application to a few models that do not seem to support the abstracted functionality.
|
|
||
|
|
||
| class AsymmetricAutoencoderKL(ModelMixin, ConfigMixin): | ||
| class AsymmetricAutoencoderKL(ModelMixin, AutoencoderMixin, ConfigMixin): |
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 AsymmetricAutoencoderKL class does not seem to implement tiling or slicing logic, and with the removal of self.use_slicing and self.use_tiling attributes, calling enable_tiling() or enable_slicing() will raise a NotImplementedError. This is misleading. It would be better to not inherit from AutoencoderMixin.
The corresponding import on line 27 should also be updated to remove AutoencoderMixin.
| class AsymmetricAutoencoderKL(ModelMixin, AutoencoderMixin, ConfigMixin): | |
| class AsymmetricAutoencoderKL(ModelMixin, ConfigMixin): |
|
|
||
|
|
||
| class AutoencoderKLTemporalDecoder(ModelMixin, ConfigMixin): | ||
| class AutoencoderKLTemporalDecoder(ModelMixin, AutoencoderMixin, ConfigMixin): |
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 AutoencoderKLTemporalDecoder class does not implement tiling or slicing functionality, nor does it define the use_tiling or use_slicing attributes. To avoid confusion and potential runtime errors, it's best to remove the AutoencoderMixin from its base classes. The import on line 29 should be updated accordingly.
| class AutoencoderKLTemporalDecoder(ModelMixin, AutoencoderMixin, ConfigMixin): | |
| class AutoencoderKLTemporalDecoder(ModelMixin, ConfigMixin): |
| def disable_tiling(self): | ||
| r""" | ||
| Disable tiled VAE decoding. If `enable_tiling` was previously enabled, this method will go back to computing | ||
| decoding in one step. | ||
| """ | ||
| self.use_tiling = False |
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.
For consistency with enable_tiling, the disable_tiling method should also check if the use_tiling attribute exists before trying to modify it. This will prevent silent errors if called on a model that doesn't support tiling.
| def disable_tiling(self): | |
| r""" | |
| Disable tiled VAE decoding. If `enable_tiling` was previously enabled, this method will go back to computing | |
| decoding in one step. | |
| """ | |
| self.use_tiling = False | |
| def disable_tiling(self): | |
| r""" | |
| Disable tiled VAE decoding. If `enable_tiling` was previously enabled, this method will go back to computing | |
| decoding in one step. | |
| """ | |
| if not hasattr(self, "use_tiling"): | |
| raise NotImplementedError(f"Tiling doesn't seem to be implemented for {self.__class__.__name__}.") | |
| self.use_tiling = False |
| def disable_slicing(self): | ||
| r""" | ||
| Disable sliced VAE decoding. If `enable_slicing` was previously enabled, this method will go back to computing | ||
| decoding in one step. | ||
| """ | ||
| self.use_slicing = False |
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.
Similar to disable_tiling, disable_slicing should check for the use_slicing attribute to ensure consistency with enable_slicing and provide clearer error messages for unsupported models.
| def disable_slicing(self): | |
| r""" | |
| Disable sliced VAE decoding. If `enable_slicing` was previously enabled, this method will go back to computing | |
| decoding in one step. | |
| """ | |
| self.use_slicing = False | |
| def disable_slicing(self): | |
| r""" | |
| Disable sliced VAE decoding. If `enable_slicing` was previously enabled, this method will go back to computing | |
| decoding in one step. | |
| """ | |
| if not hasattr(self, "use_slicing"): | |
| raise NotImplementedError(f"Slicing doesn't seem to be implemented for {self.__class__.__name__}.") | |
| self.use_slicing = False |
|
|
||
|
|
||
| class VQModel(ModelMixin, ConfigMixin): | ||
| class VQModel(ModelMixin, AutoencoderMixin, ConfigMixin): |
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 VQModel does not appear to support tiling or slicing, as it lacks the necessary implementation and attributes (use_tiling, use_slicing). Inheriting from AutoencoderMixin is therefore not appropriate for this class. Please remove AutoencoderMixin from the inheritance list and the corresponding import on line 27.
| class VQModel(ModelMixin, AutoencoderMixin, ConfigMixin): | |
| class VQModel(ModelMixin, ConfigMixin): |
What does this PR do?
Fixes # (issue)
Adds # (feature)
Before submitting
What's New. Here are thedocumentation guidelines
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@xxx