> This page is for version Main (default).
> For other versions, use one of these documentation indexes:
> - Main (default): https://docs.nvidia.com/nemo/gym/main/llms.txt
> - 0.7.0: https://docs.nvidia.com/nemo/gym/v0.7.0/llms.txt
> - 0.6.0: https://docs.nvidia.com/nemo/gym/v0.6.0/llms.txt
> - 0.5.1: https://docs.nvidia.com/nemo/gym/v0.5.1/llms.txt
> - 0.5.0: https://docs.nvidia.com/nemo/gym/v0.5.0/llms.txt
> - 0.4.0: https://docs.nvidia.com/nemo/gym/v0.4.0/llms.txt
> - 0.3.0: https://docs.nvidia.com/nemo/gym/v0.3.0/llms.txt
> - 0.2.1: https://docs.nvidia.com/nemo/gym/v0.2.1/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/gym/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/gym/_mcp/server.

# nemo_gym.server_runtime.ray_support

Ray support for Gym servers: detecting Ray, starting or joining a cluster, and shutting down a cluster Gym started.

## Module Contents

### Functions

| Name                                                                                    | Description                                                                         |
| --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| [`_connect_server_to_ray`](#nemo_gym-server_runtime-ray_support-_connect_server_to_ray) | Join the run's Ray cluster if this server declares that it uses Ray.                |
| [`_declared_ray_enabled`](#nemo_gym-server_runtime-ray_support-_declared_ray_enabled)   | The literal `ray_enabled` assigned in a class body, or None when there is none.     |
| [`_get_ray`](#nemo_gym-server_runtime-ray_support-_get_ray)                             | Import Ray only for processes configured to use it.                                 |
| [`entrypoint_ray_enabled`](#nemo_gym-server_runtime-ray_support-entrypoint_ray_enabled) | The `ray_enabled` declaration of the server an entrypoint starts, read from source. |
| [`initialize_ray`](#nemo_gym-server_runtime-ray_support-initialize_ray)                 | Initialize ray cluster in a process.                                                |
| [`maybe_ray_cluster_exit`](#nemo_gym-server_runtime-ray_support-maybe_ray_cluster_exit) | -                                                                                   |
| [`ray_is_installed`](#nemo_gym-server_runtime-ray_support-ray_is_installed)             | Whether Ray can be imported in this process, checked without importing it.          |

### Data

[`_NEMO_GYM_STARTED_RAY_CLUSTER`](#nemo_gym-server_runtime-ray_support-_NEMO_GYM_STARTED_RAY_CLUSTER)

### API

```python
nemo_gym.server_runtime.ray_support._connect_server_to_ray(
    server_class: type,
    global_config_dict: omegaconf.DictConfig
) -> None
```

Join the run's Ray cluster if this server declares that it uses Ray.

```python
nemo_gym.server_runtime.ray_support._declared_ray_enabled(
    class_node: ast.ClassDef
) -> bool | None
```

The literal `ray_enabled` assigned in a class body, or None when there is none.

```python
nemo_gym.server_runtime.ray_support._get_ray()
```

Import Ray only for processes configured to use it.

```python
nemo_gym.server_runtime.ray_support.entrypoint_ray_enabled(
    entrypoint_fpath: pathlib.Path
) -> bool | None
```

The `ray_enabled` declaration of the server an entrypoint starts, read from source.

The supervisor must decide whether to start Ray before any server exists; see `entrypoint_class_flag` for
what the source alone can settle.

```python
nemo_gym.server_runtime.ray_support.initialize_ray() -> None
```

Initialize ray cluster in a process.
We store the Ray address in the global config dict so that child processes can connect to it.
This avoids the need to start a new Ray cluster in each child process.
Note: This function will modify the global config dict - update `ray_head_node_address`

```python
nemo_gym.server_runtime.ray_support.maybe_ray_cluster_exit()
```

```python
nemo_gym.server_runtime.ray_support.ray_is_installed() -> bool
```

Whether Ray can be imported in this process, checked without importing it.

```python
nemo_gym.server_runtime.ray_support._NEMO_GYM_STARTED_RAY_CLUSTER: bool = False
```