Repository navigation
[core] Not overriding accelerator id env vars when num_accelerators is 0 or not set - #54928
Conversation
There was a problem hiding this comment.
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 refines how Ray manages accelerator visibility environment variables (such as CUDA_VISIBLE_DEVICES). The primary goal is to prevent unintended modifications to these variables when no accelerators are requested and to ensure that any necessary modifications are properly reset after a task completes. This improves the predictability and isolation of task execution, especially in environments with diverse hardware configurations.
Highlights
- Granular Control for Accelerator Visibility: The
set_visible_accelerator_idsfunction has been enhanced to prevent overriding accelerator environment variables (likeCUDA_VISIBLE_DEVICES) if no accelerator IDs are assigned for a given resource (e.g., whennum_gpus=0). This avoids unnecessary modifications to the environment. - Environment Variable Restoration: A new mechanism is introduced to capture the original state of accelerator-related environment variables before they are modified. After a non-actor task completes, these variables are now explicitly reset to their original values, ensuring a clean environment for subsequent tasks and preventing unintended side effects.
- Actor Task Exception: The new environment variable management and restoration logic is intentionally skipped for actor tasks. This allows actors to maintain their own accelerator visibility configurations without interference from Ray's automatic environment variable cleanup.
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.
Code Review
This pull request addresses an issue where CUDA_VISIBLE_DEVICES was being overridden even when num_gpus was not set. The changes correctly skip this override and also introduce a mechanism to reset any modified accelerator-related environment variables after a task completes. Overall, this is a solid improvement to resource management for accelerators.
|
@Qiaolin-Yu , we will need to do some testing for vLLM before rolling this out. Let me know when the PR is ready. |
I think the functionality is basically ready, you can try it 👀. |
|
@Qiaolin-Yu , a PR for slime may use this feature. Let me know when the PR is ready. |
@guapisolo After offline discussion, we believe that a temporary solution is to add an additional environment variable to control this logic. So it will not be a break change. |
Got it. Thanks! |
…s 0 or not set (ray-project#54928) Signed-off-by: Andrew Grosser <[email protected]>
…ng (#55791) Before this pr: ``` python /ray-workspace/temp.py 2025-08-18 18:26:21,621 INFO worker.py:1943 -- Started a local Ray instance. View the dashboard at http://127.0.0.1:8265 2025-08-18 18:26:53,873 WARNING worker.py:1991 -- Tip: In future versions of Ray, Ray will no longer override accelerator visible devices env var if num_gpus=0 or num_gpus=None (default). To enable this behavior and turn off this error message, set RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0 ``` After this pr: ``` 2025-08-20 19:08:41,923 INFO worker.py:1939 -- Started a local Ray instance. View the dashboard at http://127.0.0.1:8265 /sgl-workspace/ray/python/ray/_private/worker.py:1987: FutureWarning: Tip: In future versions of Ray, Ray will no longer override accelerator visible devices env var if num_gpus=0 or num_gpus=None (default). To enable this behavior and turn off this error message, set RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0 warnings.warn( ``` #54928
…s 0 or not set (ray-project#54928) Signed-off-by: jugalshah291 <[email protected]>
…ng (ray-project#55791) Before this pr: ``` python /ray-workspace/temp.py 2025-08-18 18:26:21,621 INFO worker.py:1943 -- Started a local Ray instance. View the dashboard at http://127.0.0.1:8265 2025-08-18 18:26:53,873 WARNING worker.py:1991 -- Tip: In future versions of Ray, Ray will no longer override accelerator visible devices env var if num_gpus=0 or num_gpus=None (default). To enable this behavior and turn off this error message, set RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0 ``` After this pr: ``` 2025-08-20 19:08:41,923 INFO worker.py:1939 -- Started a local Ray instance. View the dashboard at http://127.0.0.1:8265 /sgl-workspace/ray/python/ray/_private/worker.py:1987: FutureWarning: Tip: In future versions of Ray, Ray will no longer override accelerator visible devices env var if num_gpus=0 or num_gpus=None (default). To enable this behavior and turn off this error message, set RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0 warnings.warn( ``` ray-project#54928 Signed-off-by: jugalshah291 <[email protected]>
…s 0 or not set (#54928) Signed-off-by: Douglas Strodtman <[email protected]>
…ng (ray-project#55791) Before this pr: ``` python /ray-workspace/temp.py 2025-08-18 18:26:21,621 INFO worker.py:1943 -- Started a local Ray instance. View the dashboard at http://127.0.0.1:8265 2025-08-18 18:26:53,873 WARNING worker.py:1991 -- Tip: In future versions of Ray, Ray will no longer override accelerator visible devices env var if num_gpus=0 or num_gpus=None (default). To enable this behavior and turn off this error message, set RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0 ``` After this pr: ``` 2025-08-20 19:08:41,923 INFO worker.py:1939 -- Started a local Ray instance. View the dashboard at http://127.0.0.1:8265 /sgl-workspace/ray/python/ray/_private/worker.py:1987: FutureWarning: Tip: In future versions of Ray, Ray will no longer override accelerator visible devices env var if num_gpus=0 or num_gpus=None (default). To enable this behavior and turn off this error message, set RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0 warnings.warn( ``` ray-project#54928 Signed-off-by: Douglas Strodtman <[email protected]>
…ng (ray-project#55791) Before this pr: ``` python /ray-workspace/temp.py 2025-08-18 18:26:21,621 INFO worker.py:1943 -- Started a local Ray instance. View the dashboard at http://127.0.0.1:8265 2025-08-18 18:26:53,873 WARNING worker.py:1991 -- Tip: In future versions of Ray, Ray will no longer override accelerator visible devices env var if num_gpus=0 or num_gpus=None (default). To enable this behavior and turn off this error message, set RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0 ``` After this pr: ``` 2025-08-20 19:08:41,923 INFO worker.py:1939 -- Started a local Ray instance. View the dashboard at http://127.0.0.1:8265 /sgl-workspace/ray/python/ray/_private/worker.py:1987: FutureWarning: Tip: In future versions of Ray, Ray will no longer override accelerator visible devices env var if num_gpus=0 or num_gpus=None (default). To enable this behavior and turn off this error message, set RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0 warnings.warn( ``` ray-project#54928
#62492) Following up on #54928 where we originally introduced a feature flag to give users the option to not set CUDA_VISIBLE_DEVICES when num_gpus=0 or None. We also output an error informing users that the default behavior will be changed in a future ray version. Since it's been around 8 months since we introduced this feature flag and the error is a bit distracting, we're now setting this as the default behavior meaning we will no longer override CUDA_VISIBLE_DEVICES when num_gpus = 0 or None. --------- Signed-off-by: Joshua Lee <[email protected]> Co-authored-by: Edward Oakes <[email protected]>
ray-project#62492) Following up on ray-project#54928 where we originally introduced a feature flag to give users the option to not set CUDA_VISIBLE_DEVICES when num_gpus=0 or None. We also output an error informing users that the default behavior will be changed in a future ray version. Since it's been around 8 months since we introduced this feature flag and the error is a bit distracting, we're now setting this as the default behavior meaning we will no longer override CUDA_VISIBLE_DEVICES when num_gpus = 0 or None. --------- Signed-off-by: Joshua Lee <[email protected]> Co-authored-by: Edward Oakes <[email protected]> Signed-off-by: doanxem99 <[email protected]>
ray-project#62492) Following up on ray-project#54928 where we originally introduced a feature flag to give users the option to not set CUDA_VISIBLE_DEVICES when num_gpus=0 or None. We also output an error informing users that the default behavior will be changed in a future ray version. Since it's been around 8 months since we introduced this feature flag and the error is a bit distracting, we're now setting this as the default behavior meaning we will no longer override CUDA_VISIBLE_DEVICES when num_gpus = 0 or None. --------- Signed-off-by: Joshua Lee <[email protected]> Co-authored-by: Edward Oakes <[email protected]>
ray-project#62492) Following up on ray-project#54928 where we originally introduced a feature flag to give users the option to not set CUDA_VISIBLE_DEVICES when num_gpus=0 or None. We also output an error informing users that the default behavior will be changed in a future ray version. Since it's been around 8 months since we introduced this feature flag and the error is a bit distracting, we're now setting this as the default behavior meaning we will no longer override CUDA_VISIBLE_DEVICES when num_gpus = 0 or None. --------- Signed-off-by: Joshua Lee <[email protected]> Co-authored-by: Edward Oakes <[email protected]>
Why are these changes needed?
This PR aims to avoid overriding the accelerator ids environment variables when the number of accelerators is zero. For example, when this environment variable is set, if a user sets
num_gpus=0in theray.init()call, the environment variableCUDA_VISIBLE_DEVICESwill not be set to an empty string.Note that this logic is controlled by a new env var
RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO. We makeRAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=1by default to avoid a breaking change. To enable the new behavior, it needs to setRAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0.With this PR,
ray.init()will output the following message.Related issue number
Close #54868
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/under thecorresponding
.rstfile.