Repository navigation
feat(cli): start Ray only when a configured server may use it - #4245
Merged
Merged
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Contributor
ananthsub
force-pushed
the
ananthsub/orchestrator-skip-ray
branch
from
October 8, 2026 18:02
ff74916 to
b67e8e2
Compare
hemildesai
previously approved these changes
Oct 8, 2026
ananthsub
force-pushed
the
ananthsub/orchestrator-skip-ray
branch
from
October 8, 2026 18:15
b67e8e2 to
b755c37
Compare
The orchestrator called initialize_ray() unconditionally, so every `gym env start` and end-to-end rollout collection started a local Ray cluster (or joined the configured one), even when every configured server declares ray_enabled = False and never connects to it. Before spawning servers, read each entrypoint's source and find the classes it calls run_webserver() on. Ray is skipped only when every such class literally declares ray_enabled = False. Undeclared, inherited, imported, or unreadable declarations count as using Ray, which matches the runtime default for undeclared servers. The config walk moves into _configured_servers() so the Ray decision and the launch loop share one server list. Part of #3669. Signed-off-by: Ananth Subramaniam <[email protected]>
Signed-off-by: Ananth Subramaniam <[email protected]>
ananthsub
force-pushed
the
ananthsub/orchestrator-skip-ray
branch
from
October 8, 2026 18:35
b755c37 to
403a4a7
Compare
Contributor
Author
|
/ok to test 403a4a7 |
hemildesai
approved these changes
Oct 8, 2026
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/37827662047 |
ehosseiniasl
pushed a commit
to ehosseiniasl/Gym
that referenced
this pull request
Oct 9, 2026
## What changed Gym now works when Ray isn't installed. Ray stays a core dependency in this PR; a follow-up moves it into the new `ray` extra. - **Importing Gym:** `global_config.py` no longer raises at import when Ray is missing. The parent Ray version is `None`, and `gym --version` reports Ray as `not installed`. - **Pinning Ray in server venvs:** the parent's exact Ray version is now passed to every server venv install as a uv constraint (`-c <(printf ...)`), stored under a new `head_server_constraints` config key, instead of as a `ray[default]==<version>` requirement in `head_server_deps`. - Where a server installs Ray, it still gets exactly the parent's version. - The pin no longer forces Ray into venvs whose servers don't depend on it, which matters once Ray leaves the core dependencies. - When the parent has no Ray, there's no constraint. - **Servers that leave `ray_enabled` undeclared:** - They join Ray only when Ray is importable in their venv and the run has a cluster address to join. - Otherwise they run without Ray and log a warning saying so. - Previously, such a server with no address called `ray.init()` and started a private cluster, in every process and Uvicorn worker. - **A Gym-launched server that needs Ray but finds no cluster address** now raises an error naming the class, instead of starting a private cluster. This can only happen when the supervisor decided no server needs Ray, for example because Ray isn't installed where `gym` runs. - **Supervisor decision:** - Servers that declare `ray_enabled = True` always need Ray. - Servers whose declaration can't be read from source (undeclared, inherited, imported) count only when Ray is installed where `gym` runs. - If a server declares `True` and Ray isn't installed there, `gym env start` stops before launching anything, with a one-line error naming the servers and the install command. - `entrypoint_may_use_ray()` becomes `entrypoint_ray_enabled()`, which returns `True`, `False`, or `None` for "can't tell". - **New `ray` extra:** `nemo-gym[ray]` (also included in `all`) duplicates the core Ray and `jinja2` requirements for now. Error messages can point to it, and server manifests can request it before Ray leaves the core dependencies. The `uv.lock` change is metadata only; no package versions moved. - **Docs:** the FAQ's Ray section and the system design page describe when Ray starts, how undeclared servers behave, and the `ray` extra. The FAQ also still described the pre-NVIDIA-NeMo#4245 behavior. ## Why This is the second step of making Ray optional (NVIDIA-NeMo#3669). Before the core dependency can move into an extra, every path that assumed Ray was installed has to cope without it: - the import-time version lookup; - the per-venv pin that installed Ray everywhere; - `gym --version`; - undeclared servers starting private clusters. ## Validation - `pytest tests/unit_tests/test_global_config.py tests/unit_tests/test_cli_setup_command.py tests/unit_tests/test_ray_opt_out.py tests/unit_tests/test_cli.py tests/unit_tests/test_server_utils.py tests/unit_tests/test_cli_main.py tests/unit_tests/test_cli_endpoint_readiness.py tests/unit_tests/h2_ping_sidecar` - **Full `tests/unit_tests/` run:** the same set of tests fails on this branch and on its base commit. All of them come from optional extras missing in the local venv (`sandbox`, `wandb`, `mlflow`). - **New and updated tests:** - the config parses without Ray, and the Ray pin is a constraint rather than a requirement; - install commands carry the constraint on every path, including both installs on the PyPI `pyproject.toml` path; - undeclared servers join only when Ray is importable and a cluster is configured, and otherwise run without Ray and warn; - a Gym-launched Ray server without a cluster fails, while a standalone one may still start its own; - the supervisor decision across declarations and Ray availability, including the early failure; - `gym --version` with Ray missing; - the source declaration reader returns `None` for undeclared, inherited, imported, unreadable and mixed entrypoints. - **Real `uv` check, offline against hand-built wheels:** a constraint passed through process substitution didn't install the constrained package when nothing requested it. A conflicting constraint made the install fail as unsatisfiable. - `fern check` passes. - `pre-commit run` scoped to the changed files. ## Rollout evidence **Smoke run without Ray.** I made a venv with this branch installed and then ran `uv pip uninstall ray`. - `import nemo_gym.global_config, nemo_gym.server_utils, nemo_gym.cli.env` succeeded, with `ray_version = None`. - `gym --version --json` reported `"ray": "not installed"`. - `gym env start` with `example_single_tool_call` and `openai_model` reached `All 4 / 4 servers ready`: the resources server, the simple agent, the legacy agent environment server and the model server. No Ray processes were started. - The same venv with the `code_gen` config, which declares `ray_enabled = True`, exited before building any venv: ``` Error: These servers use Ray, but Ray isn't installed where `gym` runs: code_gen. Install with: pip install nemo-gym[ray] ``` No model requests were sent. This changes dependency handling and whether Ray starts, not prompts, trajectories, verification or rewards. ## Compatibility - **Installs with Ray (everyone today):** servers that declare `ray_enabled` behave exactly as before. Server venvs still get the parent's exact Ray version. - **Undeclared servers started outside Gym with no `ray_head_node_address`:** they no longer start a private Ray cluster at startup. If such a server calls Ray anyway, Ray initializes lazily on first use. - **Undeclared servers launched by Gym:** unchanged when Ray is installed where `gym` runs, because Gym starts Ray for them and they join it. - **`head_server_deps` no longer contains Ray.** The Ray pin lives in the new reserved `head_server_constraints` key. Signed-off-by: Ananth Subramaniam <[email protected]>
7 tasks done
8 of 26 tasks
This branch was previously deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changed
RunHelper.start()now starts or joins Ray only when a configured server may use it. PreviouslyRunHelper._startcalledinitialize_ray()unconditionally. That started a local Ray cluster, or connected toray_head_node_address, even when every configured server declaredray_enabled = False.This applies to every path that launches servers through
RunHelper:gym env start, including dry runs (++dry_run=true)gym eval runwithout--no-serveRunHelperthemselvesHow it works:
entrypoint_may_use_ray()innemo_gym/server_utils.pyreads each server entrypoint's source without importing it, because each server runs in its own venv. It finds the classes the entrypoint callsrun_webserver()on and reads theirray_enableddeclarations.ray_enabled = False._configured_servers(), so the Ray decision and the launch loop use the same server list.Why
A local Ray cluster costs host memory, an object store in
/dev/shm, background processes, and several seconds of startup. Starting one here took about 9 seconds. Configs whose servers all opted out of Ray in #3622, #3728 and #4244 still paid that cost on every launch. That hurts most in memory-limited containers and in image builds that use a dry run to prebuild server venvs, which then had to stop the leftover cluster withray stop.The check itself takes about 2 ms per server. Across all built-in entrypoints the median is 1.8 ms and the slowest is 40 ms.
This is step 7 of #3669.
Guidance
For server authors: declare
ray_enabledon the class your entrypoint callsrun_webserver()on, even when a parent class already declares it. The check reads only that class's own source, so an inheritedFalsestill starts Ray. To see why Ray started for a config, look for the log line naming the servers that may use it.For programs that embed Gym:
RunHelper.start(), a config whose servers all declareray_enabled = Falsenow runs without any Ray cluster.RunHelper.start(), for example inside a Ray actor, nothing changes.initialize_ray()already returned immediately in that case, and Gym never started a cluster of its own. Servers that use Ray still join the cluster named byray_head_node_address, and servers that declareray_enabled = Falsedon't connect, as since feat(server): allow servers to opt out of Ray #3622.For image builds: a dry run of a config whose servers all declare
ray_enabled = Falseno longer starts Ray, so a followingray stopis unnecessary. It's harmless to keep as a guard for configs that include servers that use Ray.Validation
pytest tests/unit_tests/test_cli.py tests/unit_tests/test_server_utils.py tests/unit_tests/test_ray_opt_out.py tests/unit_tests/test_cli_endpoint_readiness.py tests/unit_tests/h2_ping_sidecar, rerun after rebasing onto the HTTP/2 ping sidecar change (feat(sidecar): optionally run an HTTP/2 PING proxy fromgym env startfor endpoints with idle timeouts #4079).RunHelpertest that Ray is skipped forFalseand started forTrueor undeclared. The skip case fails on the previous code.pre-commit runscoped to the changed files.Rollout evidence
Smoke run:
gym env statusreported all four servers healthy: the resources server, the simple agent, the legacy agent environment server and the OpenAI model server.rayletorgcs_serverprocesses appeared.No model requests were sent. This change only decides whether Ray starts, so it can't affect prompts, trajectories, verification or rewards.
Compatibility
ray_enabled = False: Gym doesn't start a local Ray cluster. Ifray_head_node_addressis set, thegymprocess no longer connects to it, since none of the servers use Ray. A process that already initialized Ray before callingRunHelperis unaffected.ray_enabled = Falsefrom another module: still starts Ray until it declares the value on its own class.