Skip to content

Conversation

hnyls2002
Copy link
Collaborator

from sgl_kernel import (
File "/usr/local/lib/python3.10/dist-packages/sgl_kernel/__init__.py", line 13, in <module>
from sgl_kernel import common_ops
ImportError: /usr/local/lib/python3.10/dist-packages/sgl_kernel/common_ops.abi3.so: undefined symbol: cuGreenCtxDestroy

This will fix the above issue.

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.

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 an ImportError.
  • 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

  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 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.

Comment on lines +17 to +20
if torch.version.cuda < "12.4":
raise RuntimeError(
"Green Contexts feature requires CUDA Toolkit 12.4 or newer."
)
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 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.

Suggested change
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}"
)

Comment on lines +105 to +106
"Green Contexts feature requires CUDA Toolkit 12.4 or newer. Current CUDA version: " +
std::to_string(CUDA_VERSION));
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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 hnyls2002 self-assigned this Aug 2, 2025
@zhyncs zhyncs merged commit 603f5ce into main Aug 2, 2025
50 of 55 checks passed
@zhyncs zhyncs deleted the fix-green-context branch August 2, 2025 22:23
htiennv pushed a commit to htiennv/sglang that referenced this pull request Aug 5, 2025
@ghost
Copy link

ghost commented Aug 9, 2025

@hnyls2002 @zhyncs This does not fix the problem. cuGreenCtxDestroy is a driver level API. For example, the problem still occurs with CUDA 12.8 but an older driver (e.g. 525).

See this insightful comment from @seven-mile #8432 (comment) for more information.

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.

2 participants