Skip to content

Fix profiling tools#10977

Closed
Qiaolin-Yu wants to merge 3 commits intosgl-project:mainfrom
Qiaolin-Yu:fix
Closed

Fix profiling tools#10977
Qiaolin-Yu wants to merge 3 commits intosgl-project:mainfrom
Qiaolin-Yu:fix

Conversation

@Qiaolin-Yu
Copy link
Copy Markdown
Collaborator

@Qiaolin-Yu Qiaolin-Yu commented Sep 27, 2025

Motivation

Before this pr,

image

This issue is introduced in 777eb53.

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Qiaolin-Yu, 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 addresses a regression in the profiling tools by adjusting how profiling stages are represented in log messages. Specifically, it reverts a change that incorrectly used stage.name and instead utilizes stage.__str__() to ensure accurate and consistent logging of profiling stages, thereby fixing the profiling output and providing clearer diagnostic information.

Highlights

  • Profiling Stage Naming: Corrected the method used to obtain the string representation of a profiling stage from stage.name to stage.__str__().
  • Logging Consistency: Ensured consistent and correct logging of profiling stages in both start_profile and stop_profile methods within the scheduler profiler.
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
Copy Markdown
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 fixes a crash in the profiling tools by changing how the stage parameter is converted to a string. The change from stage.name to stage.__str__() prevents an AttributeError when an unexpected type (like a boolean) is passed. My review focuses on making this fix more robust and idiomatic. I've suggested using isinstance(stage, ForwardMode) to explicitly check the type of the stage parameter. This prevents confusing logs and filenames when an incorrect type is passed, and makes the code more resilient to such errors. I've also recommended using the built-in str() function instead of the dunder __str__ method, which is standard Python practice.

self, stage: Optional[ForwardMode] = None
) -> ProfileReqOutput | None:
stage_str = f" for {stage.name}" if stage else ""
stage_str = f" for {stage.__str__()}" if stage else ""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While using __str__ fixes the crash when a boolean is passed, it's more of a workaround that leads to confusing log messages like "Profiling starts for True...". A more robust solution would be to explicitly check if stage is an instance of ForwardMode. This handles the incorrect type gracefully by producing an empty string, leading to cleaner logs, while still using the desired string representation for valid ForwardMode objects.

Also, it's more idiomatic to use str(stage) instead of the dunder method stage.__str__().

Suggested change
stage_str = f" for {stage.__str__()}" if stage else ""
stage_str = f" for {str(stage)}" if isinstance(stage, ForwardMode) else ""

Path(self.torch_profiler_output_dir).mkdir(parents=True, exist_ok=True)

stage_suffix = f"-{stage.name}" if stage else ""
stage_suffix = f"-{stage.__str__()}" if stage else ""
Copy link
Copy Markdown
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 the start_profile method, it's good to apply the same robust type checking here. This ensures that if this function is ever called with an unexpected type for stage, it will handle it gracefully. Using isinstance makes the code more resilient.

It's also more idiomatic to use str(stage) over stage.__str__().

Suggested change
stage_suffix = f"-{stage.__str__()}" if stage else ""
stage_suffix = f"-{str(stage)}" if isinstance(stage, ForwardMode) else ""

@JustinTong0323
Copy link
Copy Markdown
Collaborator

@hnyls2002 We shall merge this PR directly

@Qiaolin-Yu Qiaolin-Yu requested a review from mickqian September 27, 2025 05:54
Comment thread python/sglang/srt/managers/scheduler_profiler_mixin.py
Comment thread python/sglang/srt/managers/scheduler_profiler_mixin.py
Comment thread python/sglang/srt/managers/scheduler_profiler_mixin.py
Comment thread python/sglang/srt/managers/scheduler_profiler_mixin.py Outdated
Copy link
Copy Markdown
Contributor

@Muqi1029 Muqi1029 left a comment

Choose a reason for hiding this comment

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

remove meaningless True param in the start_profile, and then make start_profile concise

Comment thread python/sglang/srt/managers/scheduler_profiler_mixin.py Outdated
Comment thread python/sglang/srt/managers/scheduler_profiler_mixin.py Outdated
Comment thread python/sglang/srt/managers/scheduler_profiler_mixin.py Outdated
Comment thread python/sglang/srt/managers/scheduler_profiler_mixin.py Outdated
Comment thread python/sglang/srt/managers/scheduler_profiler_mixin.py Outdated
Comment thread python/sglang/srt/managers/scheduler_profiler_mixin.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants