-
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ | |
|
|
||
| from nemo_curator.backends.base import NodeInfo, WorkerMetadata | ||
| from nemo_curator.backends.xenna import XennaExecutor | ||
| from nemo_curator.core.client import RayClient | ||
| from nemo_curator.core.client import SlurmRayClient | ||
| from nemo_curator.pipeline import Pipeline | ||
| from nemo_curator.stages.base import ProcessingStage | ||
| from nemo_curator.stages.resources import Resources | ||
|
|
@@ -217,7 +217,7 @@ def process(self, task: SampleTask) -> SampleTask: | |
| def main() -> None: | ||
| """Main function to run the pipeline.""" | ||
| # Create pipeline | ||
| ray_client = RayClient() | ||
| ray_client = SlurmRayClient() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is what we want, the quickstart should be generic to a single node run. Reading through the issue it looks like the main ask is either a way to verify that Ray has been initialized, or a clearer error message if the cluster is not ready. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in I reverted the quickstart back to Local validation: |
||
| ray_client.start() | ||
| pipeline = Pipeline(name="sentiment_analysis", description="Analyze sentiment of sample sentences") | ||
|
|
||
|
|
||
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.