Skip to content

Conversation

@iforgetmyname
Copy link
Collaborator

Motivation

_custom_ops.py introduced three kinds of customized allreduce implementation:

  • CUDA based custom allreduce (on CUDA GPUs and AMD GPUs)
  • ROCm based quick allreduce (AMD GPUs only)
  • MSCCL++ based mscclpp allreduce (currently CUDA GPUs only)

However, due to the coarse-grained implementation, this file and any related imports often cause import errors or give useless but annoying warning messages on un-supported platforms. This pr is intended to help clearify and unify the definition logics, preventing duplicated condition checks.

Modifications

  • Gathers custom_ar check flag into _custom_ops.py to reduce try-catches
  • Separates custom_allreduce, quick_allreduce and mscclpp allreduce definition blocks
  • Adds lru_cache to is_x()

Accuracy Tests

Benchmarking and Profiling

Checklist

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @iforgetmyname, 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 custom allreduce implementations within the system. The primary goal is to enhance code clarity, maintainability, and robustness by centralizing platform-specific checks and separating the logic for different allreduce mechanisms. This prevents platform-specific import issues and warnings, leading to a cleaner and more efficient initialization process for distributed operations. Additionally, common utility functions are optimized for performance through caching.

Highlights

  • Refactored Custom Allreduce Logic: The _custom_ops.py file has been refactored to centralize platform availability checks and separate the definition blocks for CUDA custom allreduce, ROCm quick allreduce, and MSCCL++ allreduce. This change aims to prevent import errors and unnecessary warning messages on unsupported platforms.
  • Centralized Availability Flags: New boolean flags (IS_CUSTOM_AR_AVAILABLE, IS_QUICK_AR_AVAILABLE, IS_MSCCLPP_AR_AVAILABLE) have been introduced in _custom_ops.py to consolidate the logic for checking the availability of different allreduce implementations, reducing redundant try-catch blocks across the codebase.
  • Performance Optimization for Utility Functions: The @lru_cache(maxsize=1) decorator has been added to various is_x() utility functions (e.g., is_cuda, is_hip, is_hpu) in sglang/srt/utils/common.py to cache their results, improving performance by avoiding repeated computations for these checks.
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 refactors the logic for custom all-reduce operations by centralizing the availability checks into _custom_ops.py. This is a great improvement for code clarity and maintainability, as it removes duplicated checks and try-except blocks from multiple files. The addition of lru_cache to the platform-checking functions is also a nice optimization.

However, I've found a critical issue in the logic for determining the availability of the custom all-reduce feature, which would prevent it from being enabled on any platform. My review includes a specific comment with a suggested fix for this issue.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@iforgetmyname
Copy link
Collaborator Author

/tag-and-rerun-ci

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.

3 participants