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 October 14, 2025 02:42
@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 enhances the testing infrastructure for diffusers examples by adding dedicated test files for ControlNet, DreamBooth, Text-to-Image, Textual Inversion, and Unconditional Image Generation. It also refines the checkpointing mechanism in training scripts by adopting the safetensors format and save_pretrained() method for UNet models, alongside minor documentation updates to improve user experience.

Highlights

  • New Test Suites: Introduced comprehensive test files for various diffusers examples, including ControlNet, DreamBooth (and its LoRA variants), Text-to-Image (and its LoRA variants), Textual Inversion, and Unconditional Image Generation. These tests cover basic functionality, checkpointing, and specific features like text encoder training and latent caching.
  • Checkpoint Handling Improvement: Updated existing training scripts across ControlNet, DreamBooth, Text-to-Image, and Textual Inversion examples to standardize checkpoint loading and saving. The changes involve migrating from the .ckpt format to the more secure and efficient .safetensors format and utilizing unet.save_pretrained() for saving UNet models.
  • Documentation Path Corrections: Minor adjustments were made to README.md files in cogvideox_factory, cogview, and dreambooth examples to correct cd commands and installation tips, ensuring accurate setup instructions.
  • Test Utility Introduction: A new utility file, test_examples_utils.py, was added to provide common functionalities for running and asserting example tests, promoting consistency and reusability across the new test suites.
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 a comprehensive test suite for various diffusers examples, enhancing the project's robustness. It also refactors the checkpointing mechanism in several training scripts to consistently use the .safetensors format and the save_pretrained method, which is a good improvement for model serialization. My review identifies a few critical issues in the new test files and one of the updated training scripts that need to be addressed.

Comment on lines 278 to 279
with ms.load_checkpoint(state_dict_file, format="safetensors") as f:
metadata = f.metadata() or {}
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The usage of ms.load_checkpoint as a context manager is incorrect, as it returns a dictionary and does not support the with statement. To read metadata from a .safetensors file, safetensors.safe_open should be used. You will need to add from safetensors import safe_open to the file imports.

Suggested change
with ms.load_checkpoint(state_dict_file, format="safetensors") as f:
metadata = f.metadata() or {}
from safetensors import safe_open
with safe_open(state_dict_file, framework="np") as f:
metadata = f.metadata() or {}

# TODO: load optimizer & grad scaler etc. like accelerator.load_state
input_model_file = os.path.join(args.output_dir, path, "pytorch_model.ckpt")
input_model_file = os.path.join(args.output_dir, path, "unet/diffusion_pytorch_model.safetensors")
ms.load_param_into_net(unet, ms.load_checkpoint(input_model_file), strict_load=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The ms.load_checkpoint function is being called to load a .safetensors file, but the format argument is missing. Without format="safetensors", MindSpore will try to load it as a standard checkpoint file, which will fail.

Suggested change
ms.load_param_into_net(unet, ms.load_checkpoint(input_model_file), strict_load=True)
ms.load_param_into_net(unet, ms.load_checkpoint(input_model_file, format="safetensors"), strict_load=True)



class ControlNetSD35(ExamplesTests):
def test_controlnet_sd3(self):
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 test method test_controlnet_sd3 in class ControlNetSD35 has a duplicated name with the test method in class ControlNetSD3. Test method names within a test class and its inherited test cases should be unique. This will cause one of the tests to be skipped by the test runner. Please rename it to reflect the test case, for example, test_controlnet_sd35.

Suggested change
def test_controlnet_sd3(self):
def test_controlnet_sd35(self):

@Cui-yshoho Cui-yshoho force-pushed the test_diffusers_example branch 12 times, most recently from 3b81766 to ada9cd1 Compare October 15, 2025 03:19
@Cui-yshoho Cui-yshoho force-pushed the test_diffusers_example branch 2 times, most recently from fb61a3d to 58c81ef Compare October 16, 2025 07:38
@Cui-yshoho Cui-yshoho force-pushed the test_diffusers_example branch from 58c81ef to e8afa2a Compare October 16, 2025 07:50
@Cui-yshoho Cui-yshoho force-pushed the test_diffusers_example branch 4 times, most recently from 845cf22 to 18234b8 Compare October 17, 2025 07:22
@Cui-yshoho Cui-yshoho force-pushed the test_diffusers_example branch from 18234b8 to 494debb Compare October 17, 2025 08:43
@zhanghuiyao zhanghuiyao added this pull request to the merge queue Oct 17, 2025
Merged via the queue into mindspore-lab:master with commit 753bc9d Oct 17, 2025
3 checks passed
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.

5 participants