Skip to content
Repo

ModalRayCluster

from modal_training_gym.common.ray_cluster import ModalRayCluster

Starts and coordinates a Ray cluster inside a Modal clustered function.

Attributes

n_nodes int

Total cluster node count.

rank int

This container's rank, where zero is the head.

head_addr str

IPv4 address of the head node.

node_ip str

IPv4 address of this container.

is_head bool

Whether this container is the head.

client

Ray JobSubmissionClient for the head node, or None before startup.

Raises

  • RuntimeError: Cluster discovery has not run or this container is not the head node.
discover_cluster(n_nodes: int) -> None

Discover this container’s Ray cluster state.

Parameters

n_nodes int

Number of containers in the cluster.

forward_dashboard()

Open a forwarding context for the Ray dashboard.

Returns

A context manager compatible with with and async with.

Raises

  • RuntimeError: This container is not the head node.
head_extra_start_args() -> list[str]

Additional arguments for ray start --head.

start(n_nodes: int, *, init_retries: int = 30, worker_wait_retries: int = 60) -> None

Discover the cluster and start Ray.

start_ray(*, init_retries: int = 30, worker_wait_retries: int = 60) -> None

Start the Ray head or worker.

Parameters

init_retries int

Maximum Ray head initialization attempts. Default: 30

worker_wait_retries int

Maximum attempts to wait for workers. Default: 60

Raises

  • RuntimeError: discover_cluster() has not been called.
submit_and_tail(entrypoint: str, *, runtime_env: dict | None = None, max_retries: int = 35) -> ModalRayJobResult

Submit a Ray job and stream its logs.

Returns

The final Ray job status.

wait_forever(poll_seconds: float = 10) -> None

Keep a worker container alive until the head terminates the cluster.

worker_extra_start_args() -> list[str]

Additional arguments for ray start on worker ranks.