Repository navigation
Description
Context
Gym historically starts or joins a Ray cluster from the CLI orchestrator and connects every server process and Uvicorn worker, including stateless servers that never call Ray. This adds per-process runtime state, memory, background work, and cluster connections that scale with num_workers. It is especially relevant when Gym is co-located with large-scale RL training and host-memory headroom is limited.
External components loaded from PyPI installations through --search-dir, NEMO_GYM_EXTRA_ROOTS, private forks, or separate environment repositories may rely on the current implicit initialization. The migration therefore needs a compatibility window.
Migration path
- Add an implementation-level
ray_enabled: ClassVar[bool | None]declaration. - During the compatibility phase, treat
Noneas enabled and emit an actionable warning. - Mark every shipped server explicitly
TrueorFalse. - Stop non-Ray server processes and Uvicorn workers from importing or connecting to Ray.
- Migrate workloads to better-fitting execution boundaries where possible.
- After downstream servers have had time to migrate, interpret
Noneas disabled so Ray becomes opt-in. - Use lightweight pre-spawn dependency metadata to avoid starting the orchestrator's Ray cluster when no configured server requires it.
- Reassess whether Ray should remain a required core dependency or become optional.
Status (2026-11-19)
Steps 1–8 of the migration path are done on main:
- Servers declare
ray_enabled, and every shipped server declares it explicitly (feat(server): allow servers to opt out of Ray #3622, chore(server): declare Ray usage for built-in servers #3728, chore(server): declare Ray usage for environment servers and GPQA-Diamond #4244). gymstarts or joins Ray only when a configured server declaresray_enabled = True(feat(cli): start Ray only when a configured server may use it #4245).- Gym runs without Ray installed, and servers that use Ray request the
nemo-gym[ray]extra (feat(core): run Gym without Ray installed #4300, chore(server): request the ray extra from servers that use Ray #4301). ray_enableddefaults toFalse. Servers that do not declare Ray are launched withRAY_ENABLE_AUTO_CONNECT=0, so they cannot start or join a cluster implicitly (feat(core): servers run without Ray unless they declare ray_enabled = True #4307, chore(server): drop redundant ray_enabled = False declarations #4470).- Ray is an optional dependency;
pip install nemo-gymno longer installs it (build(deps): make Ray an optional dependency #4350). The evaluation driver installs the extra when a checkout declares it (fix(orchestration): always install the ray extra in the eval driver #4815, fix(orchestration): the driver install asks uv only for extras the checkout declares #5626). code_genruns submissions in sandboxes instead of Ray tasks (refactor(code-gen): replace legacy Ray execution with sandboxes #4958).local_vllm_modelandgenrm_modelserve an external vLLM endpoint without Ray through newexternal_app.pyentrypoints, which declareray_enabled = False(feat(local_vllm_model): serve external vLLM endpoints without Ray #6039, feat(genrm_model): serve external GenRM vLLM pools without Ray #6056). Theirapp.pyentrypoints still use Ray, because they launch vLLM on Ray. Training frameworks pick up the new entrypoints by selecting them once their Gym pin includes these PRs.
Related fix: with num_workers > 1, each Uvicorn worker built its server twice before #5681. The extra build ran before the worker's health check started, so a slow build could get the worker killed and restarted.
Docs: #6065 fixed the pages that still said Gym always installs and starts Ray. The Architecture page now explains why Gym runs separate servers and how a server moves heavy work off its own processes: sandboxes first, then model servers, then Ray. The Ray guide is its own page, Scale CPU-Heavy Work with Ray, with an upgrade note for 0.7.0 users. AGENTS.md and the add-benchmark skill tell coding agents to declare ray_enabled = True, request nemo-gym[ray], and use the Sandbox API for isolated execution.
Measurements
Each comparison runs current main against main with the old behavior restored: Ray started for every run, every server process and Uvicorn worker connected, and Ray installed in every server environment. Everything else is identical. Numbers are medians of three interleaved runs.
Evaluation, MMLU-Pro and IFEval with 100 tasks each against a hosted OpenAI-compatible endpoint, default server settings:
- Time until all servers are ready: 12.9 s with Ray, 6.3 s without. Almost all of the difference is starting the Ray cluster.
- Memory once running (PSS): 2.8 GB with Ray, 1.1 GB without. Ray's own 31 background processes hold about 1.5 GB for the whole run.
- Gym processes connected to Ray: all with the old behavior, none today. Scores are unchanged.
- Each server environment is about 200 MB smaller without Ray (816 MB against 616 MB for a simple server).
Training, a production-scale RL configuration with 35 environments and 112 Gym servers, including a policy model server with 16 Uvicorn workers. This is a CPU-only simulation of how NeMo RL's single-controller path starts Gym inside a Ray actor on an existing cluster, using the Gym version NeMo RL currently pins plus the external_app.py entrypoints above:
- Gym processes connected to the training job's Ray cluster: 132 with the old behavior, 1 with these changes (
code_gen, which still used Ray at that Gym version). - Memory on Gym's node: 23.5 GB with the old behavior, 18.5 GB with these changes.
- Time until Gym is ready: 58 s against 49 s. Individual runs varied by about 10 s because 112 servers start at once on one machine.
An earlier single-server measurement on macOS found the same pattern: about 4 s of added startup and 28 extra processes.
Servers that still depend on Ray
Each server has a follow-up issue that records how it uses Ray and the proposed replacement. Each box is checked once the server no longer declares ray_enabled = True on main, or documents why it keeps Ray. On main (2026-11-18), 16 server implementations declare ray_enabled = True.
Candidates for the Sandbox API
These primarily use Ray to distribute harness execution, code execution, compilation, tests, or other disposable task environments. The Sandbox API provides a clearer lifecycle and stronger isolation; provider-side pooling and concurrency controls can replace the outer Ray task layer.
Resources servers:
-
resources_servers/code_fim(Migrate code_fim off Ray #6428) -
resources_servers/evalplus(Migrate evalplus off Ray #6429) -
resources_servers/spider2_lite(Migrate spider2_lite off Ray #6430) -
resources_servers/swerl_gen(Migrate swerl_gen off Ray #6431)
Agent servers:
-
responses_api_agents/anyterminal_agent(Migrate anyterminal_agent off Ray #6434) -
responses_api_agents/harbor_agent(Migrate harbor_agent off Ray #6435) -
responses_api_agents/harbor_agent_general(Migrate harbor_agent_general off Ray #6436) -
responses_api_agents/mini_swe_agent(Migrate mini_swe_agent off Ray #6437) -
responses_api_agents/mini_swe_agent_2(Migrate mini_swe_agent_2 off Ray #6438) -
responses_api_agents/osworld_agent(Migrate osworld_agent off Ray #6439) -
responses_api_agents/swe_agents(Migrate swe_agents off Ray #6440)
Some of these already use sandbox-backed execution internally. The remaining work is to determine whether Ray is still needed around that sandbox lifecycle or whether async Gym orchestration and provider capacity controls are sufficient.
Candidates for persistent endpoints
These use Ray to keep heavyweight models resident, place them on GPUs, and route repeated scoring or inference calls. They are better candidates for independently deployed persistent services with stable HTTP APIs, batching, readiness, and model-version metadata.
-
resources_servers/longmt_eval(Migrate longmt_eval off Ray #6432): COMET/LASER/Ersatz scoring actors -
resources_servers/wmt_translation(Migrate wmt_translation off Ray #6433): persistent COMET scoring actors -
responses_api_models/local_vllm_model(Migrate local_vllm_model off Ray #6441):app.pylaunches vLLM with Ray actors and placement groups. The external-endpoint case runs without Ray throughexternal_app.py(feat(local_vllm_model): serve external vLLM endpoints without Ray #6039). -
responses_api_models/genrm_model(Migrate genrm_model off Ray #6442): builds onlocal_vllm_model, with the same split (feat(genrm_model): serve external GenRM vLLM pools without Ray #6056).
Not yet categorized
-
resources_servers/legal_agent_bench(Migrate legal_agent_bench off Ray #6443)
No longer use Ray
-
resources_servers/code_gen: runs submissions in sandboxes (refactor(code-gen): replace legacy Ray execution with sandboxes #4958). -
responses_api_agents/stirrup_agent: no longer declares Ray.
Cases where Ray may remain appropriate
Ray can remain an explicit dependency for trusted cluster-local workloads that genuinely need long-lived mutable actors, placement groups or custom resources, shared-object transfer, gang scheduling, or low-latency distributed coordination. Each remaining use should document why a sandbox, bounded local concurrency, or persistent endpoint is insufficient.
Acceptance criteria
- All shipped server implementations explicitly declare whether they use Ray. Since
ray_enableddefaults toFalse, only servers that use Ray declare it, andtests/unit_tests/test_ray_opt_out.pychecks that a server declaresray_enabled = Trueexactly when it uses Ray. - External undeclared servers retain compatibility temporarily and receive a migration warning. The compatibility window ran from feat(server): allow servers to opt out of Ray #3622 until feat(core): servers run without Ray unless they declare ray_enabled = True #4307 made undeclared servers run without Ray.
- Non-Ray servers and Uvicorn workers create no Ray client connections. They launch with
RAY_ENABLE_AUTO_CONNECT=0; the measurements above show no Gym process connected to Ray. - The listed migration candidates are evaluated and tracked through focused follow-up work.
code_genmoved to sandboxes, andlocal_vllm_modelandgenrm_modelserve external endpoints without Ray (feat(local_vllm_model): serve external vLLM endpoints without Ray #6039, feat(genrm_model): serve external GenRM vLLM pools without Ray #6056). Each unchecked server above has its own follow-up issue. fix(spider2_lite): run SQL in a thread with a SQLite progress-handler timeout, not Ray #6392 (open) movesspider2_liteoff Ray. - Documentation covers PyPI, forks, and external component roots. The Scale CPU-Heavy Work with Ray page explains when Ray starts, how a server opts in, and how it requests the
nemo-gym[ray]extra, and docs: explain why Gym runs separate servers and when it uses Ray #6065 fixed the pages that still described the old behavior. Coverage of forks and external component roots has not been checked. - Ray becomes opt-in after the announced compatibility window.
- The orchestrator does not start Ray when no configured server requires it.
- Remaining Ray users document the concrete distributed-systems requirement Ray satisfies. None of the 16 servers that declare Ray documents this yet.
Related work
- Memory profiling: feat(telemetry): report host and per-server memory usage #3584
- Server-level Ray declarations and opt-out: #3622
- Ray server environments on every Ray node, for multi-node clusters with node-local environments (open): fix(server-runtime): set up Ray server venvs on every Ray node #6336
Sub-issues
Collapse Sub-issuesSub-issues
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDev WIP
Activity
feat(server): allow servers to opt out of Ray (NVIDIA-NeMo#3622)
chore(server): declare Ray usage for built-in servers (NVIDIA-NeMo#3728)
chore(server): declare Ray usage for environment servers and GPQA-Dia…
feat(cli): start Ray only when a configured server may use it
feat(cli): start Ray only when a configured server may use it
feat(cli): start Ray only when a configured server may use it
feat(cli): start Ray only when a configured server may use it (NVIDIA…
chore(server): request the ray extra from servers that use Ray
feat(core): servers run without Ray unless they declare ray_enabled =…
feat(core): servers run without Ray unless they declare ray_enabled =…
19 remaining items