Skip to content

Conversation

@Cui-yshoho
Copy link
Contributor

What does this PR do?

Fixes # (issue)

Adds # (feature)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline?
  • Did you make sure to update the documentation with your changes? E.g. record bug fixes or new features in What's New. Here are the
    documentation guidelines
  • Did you build and run the code without any errors?
  • Did you report the running environment (NPU type/MS version) and performance in the doc? (better record it for data loading, model inference, or training tasks)
  • Did you write any new necessary tests?

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

@Cui-yshoho Cui-yshoho requested a review from vigo999 as a code owner November 28, 2025 02:39
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 AutoencoderMixin class. This new mixin consolidates shared functionalities like enabling and disabling tiling and slicing, which were previously duplicated across numerous autoencoder implementations. By having various autoencoder models inherit from this mixin, the codebase becomes more modular, easier to maintain, and less prone to inconsistencies. Additionally, some specific autoencoder models received minor updates to their type hints and internal logic for better compatibility and functionality.

Highlights

  • Code Refactoring: Introduced a new AutoencoderMixin class to centralize common methods for enabling/disabling tiling and slicing across various autoencoder models, significantly reducing code duplication.
  • Mixin Integration: Updated 17 different autoencoder classes, including AsymmetricAutoencoderKL, AutoencoderDC, AutoencoderKL, and others, to inherit from the new AutoencoderMixin.
  • Method Consolidation: Removed redundant enable_tiling, disable_tiling, enable_slicing, and disable_slicing methods from individual autoencoder implementations, as these are now provided by the AutoencoderMixin.
  • Type Hint and Logic Updates: Applied minor fixes and improvements to specific autoencoder models, such as updating type hints from torch.Tensor to ms.Tensor in AutoencoderKLHunyuanVideo and AutoencoderKLMochi, and refining tiling/patching logic in AutoencoderKLWan.
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.

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 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):
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
class AsymmetricAutoencoderKL(ModelMixin, AutoencoderMixin, ConfigMixin):
class AsymmetricAutoencoderKL(ModelMixin, ConfigMixin):



class AutoencoderKLTemporalDecoder(ModelMixin, ConfigMixin):
class AutoencoderKLTemporalDecoder(ModelMixin, AutoencoderMixin, ConfigMixin):
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
class AutoencoderKLTemporalDecoder(ModelMixin, AutoencoderMixin, ConfigMixin):
class AutoencoderKLTemporalDecoder(ModelMixin, ConfigMixin):

Comment on lines +883 to +888
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
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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

Comment on lines +899 to +904
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
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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):
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
class VQModel(ModelMixin, AutoencoderMixin, ConfigMixin):
class VQModel(ModelMixin, ConfigMixin):

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.

1 participant