-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[Bug] fix green context's incompatibility with cuda < 12.4
#8701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @hnyls2002, 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 bug where the sgl_kernel
library, specifically its green context feature, was incompatible with CUDA versions older than 12.4. This incompatibility led to an ImportError
due to an undefined symbol when sgl_kernel
was imported. My changes introduce checks and conditional compilation to ensure that the green context feature is only enabled for compatible CUDA versions (12.4 or newer) and provides clear error messages for users running older CUDA toolkits, preventing the import failure.
Highlights
- CUDA Version Compatibility: I've implemented checks and conditional compilation to prevent
sgl_kernel
's green context feature from being used with CUDA versions older than 12.4, which was causing anImportError
. - Improved Error Handling: I've added explicit runtime errors in the Python layer and compile-time checks in the C++ layer to inform users if their CUDA version does not meet the minimum requirement for green contexts.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
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 issue 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 or fill out our survey to provide feedback.
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
-
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. ↩
There was a problem hiding this 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 correctly adds conditional compilation to support CUDA versions older than 12.4, preventing build failures. My review identifies a critical issue with the Python-level CUDA version check which uses string comparison, and a medium-severity issue in the C++ error message where the CUDA version format could be more user-friendly. I've provided suggestions to fix both.
if torch.version.cuda < "12.4": | ||
raise RuntimeError( | ||
"Green Contexts feature requires CUDA Toolkit 12.4 or newer." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string-based comparison for the CUDA version is incorrect and can lead to bugs. For example, a lexicographical comparison would consider "12.10"
to be less than "12.4"
, which would incorrectly prevent the code from running on CUDA 12.10.
A more robust method is to parse the version string into its components and perform a numerical comparison, for instance by converting it to a tuple of integers.
Additionally, the error message can be improved to be more specific, clarifying that it is the CUDA version that PyTorch was compiled with that is being checked.
if torch.version.cuda < "12.4": | |
raise RuntimeError( | |
"Green Contexts feature requires CUDA Toolkit 12.4 or newer." | |
) | |
if tuple(map(int, torch.version.cuda.split('.'))) < (12, 4): | |
raise RuntimeError( | |
"Green Contexts feature requires PyTorch to be compiled with CUDA Toolkit 12.4 or newer. " | |
+ f"Current PyTorch CUDA version: {torch.version.cuda}" | |
) |
"Green Contexts feature requires CUDA Toolkit 12.4 or newer. Current CUDA version: " + | ||
std::to_string(CUDA_VERSION)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CUDA_VERSION
macro expands to an integer (e.g., 12040
for 12.4), which is not very human-readable in an error message. To improve user experience, it would be better to format this into a major.minor
string.
"Green Contexts feature requires CUDA Toolkit 12.4 or newer. Current CUDA version: " +
(std::to_string(CUDA_VERSION / 1000) + "." + std::to_string((CUDA_VERSION % 1000) / 10)));
@hnyls2002 @zhyncs This does not fix the problem. See this insightful comment from @seven-mile #8432 (comment) for more information. |
This will fix the above issue.