-
Notifications
You must be signed in to change notification settings - Fork 293
fix: make quickstart Ray startup Xenna-safe #2089
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
Closed
+120
−3
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| # Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| from nemo_curator.core import client as core_client | ||
| from nemo_curator.core import utils as core_utils | ||
|
|
||
| if TYPE_CHECKING: | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| def _mock_init_cluster_dependencies(monkeypatch: pytest.MonkeyPatch) -> list[list[str]]: | ||
| popen_calls: list[list[str]] = [] | ||
|
|
||
| class FakePopen: | ||
| def __init__(self, cmd: list[str], **_kwargs: object) -> None: | ||
| popen_calls.append(cmd) | ||
|
|
||
| monkeypatch.setattr(core_utils.ray.util, "register_serializer", lambda *_args, **_kwargs: None) | ||
| monkeypatch.setattr(core_utils, "get_free_port", lambda port, **_kwargs: port) | ||
| monkeypatch.setattr(core_utils.shutil, "which", lambda _cmd: None) | ||
| monkeypatch.setattr(core_utils.subprocess, "Popen", FakePopen) | ||
| return popen_calls | ||
|
|
||
|
|
||
| def test_init_cluster_sets_xenna_gpu_env_before_ray_start(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: | ||
| popen_calls = _mock_init_cluster_dependencies(monkeypatch) | ||
| monkeypatch.delenv("RAY_EXPERIMENTAL_NOSET_CUDA_VISIBLE_DEVICES", raising=False) | ||
|
|
||
| core_utils.init_cluster( | ||
| ray_port=6379, | ||
| ray_temp_dir=str(tmp_path), | ||
| ray_dashboard_port=8265, | ||
| ray_metrics_port=8080, | ||
| ray_client_server_port=10001, | ||
| ray_dashboard_host="127.0.0.1", | ||
| ) | ||
|
|
||
| assert popen_calls | ||
| assert "--head" in popen_calls[0] | ||
| assert "--block" in popen_calls[0] | ||
| assert core_utils.os.environ["RAY_EXPERIMENTAL_NOSET_CUDA_VISIBLE_DEVICES"] == "1" | ||
|
|
||
|
|
||
| def test_init_cluster_preserves_existing_xenna_gpu_env(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: | ||
| _mock_init_cluster_dependencies(monkeypatch) | ||
| monkeypatch.setenv("RAY_EXPERIMENTAL_NOSET_CUDA_VISIBLE_DEVICES", "0") | ||
|
|
||
| core_utils.init_cluster( | ||
| ray_port=6379, | ||
| ray_temp_dir=str(tmp_path), | ||
| ray_dashboard_port=8265, | ||
| ray_metrics_port=8080, | ||
| ray_client_server_port=10001, | ||
| ray_dashboard_host="127.0.0.1", | ||
| ) | ||
|
|
||
| assert core_utils.os.environ["RAY_EXPERIMENTAL_NOSET_CUDA_VISIBLE_DEVICES"] == "0" | ||
|
|
||
|
|
||
| def test_slurm_worker_sets_xenna_gpu_env_before_ray_start(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: | ||
| run_calls: list[list[str]] = [] | ||
|
|
||
| def fake_run(cmd: list[str], **_kwargs: object) -> object: | ||
| run_calls.append(cmd) | ||
| assert core_client.os.environ["RAY_EXPERIMENTAL_NOSET_CUDA_VISIBLE_DEVICES"] == "1" | ||
| return type("CompletedProcess", (), {"returncode": 0})() | ||
|
|
||
| monkeypatch.delenv("RAY_EXPERIMENTAL_NOSET_CUDA_VISIBLE_DEVICES", raising=False) | ||
| monkeypatch.setattr(core_client, "_find_ray_binary", lambda: "ray") | ||
| monkeypatch.setattr(core_client.subprocess, "run", fake_run) | ||
|
|
||
| client = core_client.SlurmRayClient(ray_port=6379, ray_temp_dir=str(tmp_path)) | ||
|
|
||
| assert client._run_as_worker("10.0.0.1") == 0 | ||
| assert run_calls | ||
| assert run_calls[0][:4] == ["ray", "start", "--address", "10.0.0.1:6379"] | ||
|
|
||
|
|
||
| def test_slurm_worker_preserves_existing_xenna_gpu_env(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: | ||
| monkeypatch.setenv("RAY_EXPERIMENTAL_NOSET_CUDA_VISIBLE_DEVICES", "0") | ||
| monkeypatch.setattr(core_client, "_find_ray_binary", lambda: "ray") | ||
| monkeypatch.setattr( | ||
| core_client.subprocess, | ||
| "run", | ||
| lambda *_args, **_kwargs: type("CompletedProcess", (), {"returncode": 0})(), | ||
| ) | ||
|
|
||
| client = core_client.SlurmRayClient(ray_port=6379, ray_temp_dir=str(tmp_path)) | ||
|
|
||
| assert client._run_as_worker("10.0.0.1") == 0 | ||
| assert core_client.os.environ["RAY_EXPERIMENTAL_NOSET_CUDA_VISIBLE_DEVICES"] == "0" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ray_dashboard_hostargumentinit_clusterhasray_dashboard_host: stras a required positional parameter (no default value), but both test invocations omit it entirely. This causes an immediateTypeError: init_cluster() missing 1 required positional argument: 'ray_dashboard_host', meaning neither test can pass even whenrayis installed. The same omission appears in the second test at line 62–69.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.
Thanks — addressed in
421e8c5. I added the missingray_dashboard_hostargument to bothinit_clustertest calls, and also covered/fixed the worker-node path by settingRAY_EXPERIMENTAL_NOSET_CUDA_VISIBLE_DEVICESbeforeSlurmRayClient._run_as_workerlaunchesray start.Validation:
uv run ruff check nemo_curator/core/client.py tests/core/test_ray_cluster_utils.py— passeduv run pytest tests/core/test_ray_cluster_utils.py— blocked locally because NeMo Curator raises on non-Linux hosts (darwin); attempting to spoof Linux then fails on Ray/psutil Linux native extension import on macOS.