ModalRayCluster
from modal_training_gym.common.ray_cluster import ModalRayClusterStarts 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
Section titled “client”clientRay 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
Section titled “discover_cluster”discover_cluster(n_nodes: int) -> NoneDiscover this container’s Ray cluster state.
Parameters
n_nodes int
Number of containers in the cluster.
forward_dashboard
Section titled “forward_dashboard”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
Section titled “head_extra_start_args”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) -> NoneDiscover the cluster and start Ray.
start_ray
Section titled “start_ray”start_ray(*, init_retries: int = 30, worker_wait_retries: int = 60) -> NoneStart 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
Section titled “submit_and_tail”submit_and_tail(entrypoint: str, *, runtime_env: dict | None = None, max_retries: int = 35) -> ModalRayJobResultSubmit a Ray job and stream its logs.
Returns
The final Ray job status.
wait_forever
Section titled “wait_forever”wait_forever(poll_seconds: float = 10) -> NoneKeep a worker container alive until the head terminates the cluster.
worker_extra_start_args
Section titled “worker_extra_start_args”worker_extra_start_args() -> list[str]Additional arguments for ray start on worker ranks.