Skip to content

Conversation

@wtomin
Copy link
Collaborator

@wtomin wtomin commented Oct 16, 2025

What does this PR do?

Adds # (feature)

  1. Add throughputs (tokens/s) printing in MmaDA inference script;
  2. Add performance table in the readme file of MmaDA.
  3. For some reason unknown, the changes in mindone/trainers/zero.py introduced by [FEATURE] Support Qwen2.5VL training #1214 caused a parameter shape error in Zero2 training of MmaDA. Falled back to the previous code snippet.

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.

@SamitHuang @zhtmike @vigo999

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @wtomin, 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 primarily focuses on enhancing the MmaDA example by integrating performance metrics and updating documentation. It introduces throughput logging in inference scripts and comprehensive performance tables in the README, offering users clearer benchmarks. Additionally, it addresses a critical bug in the mindone/trainers/zero.py module, reverting a problematic change to ensure stable Zero2 training for MmaDA.

Highlights

  • Performance Metrics Integration: Throughput (tokens/s) logging has been added to the MmaDA inference scripts (generate.py, inference_mmu.py, inference_t2i.py) to provide clearer performance insights.
  • README Performance Tables: The examples/mmada/README.md file now includes detailed performance tables for MmaDA inference (text generation, multimodal generation, text-to-image generation) and finetuning, tested on Ascend Atlas 800T A2 machines with MindSpore 2.6.0 and 2.7.0.
  • Zero2 Training Fix: A previous change in mindone/trainers/zero.py that caused a parameter shape error during Zero2 training of MmaDA has been reverted, specifically by introducing conditional logic for PYNATIVE_MODE in get_optimizer_param_tuples.
  • Dependency Updates: The examples/mmada/README.md has been updated with the latest recommended versions for MindSpore, Ascend Driver, Firmware, and CANN toolkit/kernel.
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 adds performance metrics to the MMaDA example, including throughput calculations in inference scripts and performance tables in the README. It also includes a fix for Zero2 training in PyNative mode.

My review focuses on the correctness of the new performance calculations. I've found a few issues where the duration measurement for throughput is inaccurate because it includes post-processing time, and in one case, the formula for calculating tokens per second seems incorrect. I've provided suggestions to fix these issues to ensure the reported performance metrics are accurate. The documentation updates and the fix in zero.py look good.

Comment on lines 170 to +171
print(f"Inference time: {time() - infer_start:.3f}s")
print(f"Throughput: {out.shape[1] / (time() - infer_start):.3f} token/s")
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 duration time() - infer_start is calculated twice, which can lead to slight inaccuracies in both the reported inference time and throughput. The second call to time() will result in a slightly longer duration, making the throughput appear lower than it is. It's better to calculate the duration once and reuse it for both print statements.

Suggested change
print(f"Inference time: {time() - infer_start:.3f}s")
print(f"Throughput: {out.shape[1] / (time() - infer_start):.3f} token/s")
duration = time() - infer_start
print(f"Inference time: {duration:.3f}s")
print(f"Throughput: {out.shape[1] / duration:.3f} token/s")

Comment on lines 159 to +163
output_ids = model.mmu_generate(input_ids, max_new_tokens=1024, steps=512, block_length=1024)
text = uni_prompting.text_tokenizer.batch_decode(
output_ids[:, input_ids.shape[1] :], skip_special_tokens=True
)
throughputs.append(output_ids.shape[1] / (time() - infer_start))
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 duration for throughput calculation is measured after the batch_decode operation. This includes post-processing time and will lead to an inaccurate (lower) throughput value for the model generation. The duration should be measured immediately after the model.mmu_generate call.

Suggested change
output_ids = model.mmu_generate(input_ids, max_new_tokens=1024, steps=512, block_length=1024)
text = uni_prompting.text_tokenizer.batch_decode(
output_ids[:, input_ids.shape[1] :], skip_special_tokens=True
)
throughputs.append(output_ids.shape[1] / (time() - infer_start))
output_ids = model.mmu_generate(input_ids, max_new_tokens=1024, steps=512, block_length=1024)
infer_duration = time() - infer_start
text = uni_prompting.text_tokenizer.batch_decode(
output_ids[:, input_ids.shape[1] :], skip_special_tokens=True
)
throughputs.append(output_ids.shape[1] / infer_duration)

if isinstance(getattr(self.optimizer, attr), ms.ParameterTuple):
if attr in ["_parameters", "parameters"]:
if ms.get_context("mode") == ms.PYNATIVE_MODE:
for name in self.optimizer._params_list:
Copy link
Collaborator

Choose a reason for hiding this comment

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

somehow in MS2.7, self.optimizer._params_list is a empty list in ZeRO3, better to test if zero3 works

@vigo999 vigo999 added this pull request to the merge queue Oct 18, 2025
Merged via the queue into mindspore-lab:master with commit 36d1e6a Oct 18, 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.

4 participants