Configuring your Cluster


Before you continue, be sure to have read Launching Cloud Clusters.

To launch a cluster, you must first create a cluster configuration file, which specifies some important details about the cluster.


At a minimum, we need to specify:

  • the name of your cluster,

  • the number of workers in the cluster

  • the cloud provider

  • any setup commands that should run on the node upon launch.

Here is an example cluster configuration file:

# A unique identifier for this cluster.
cluster_name: basic-ray

# The maximum number of workers nodes to launch in addition to the head
# node.
max_workers: 0 # this means zero workers

# Cloud-provider specific configuration.
   type: aws
   region: us-west-2
   availability_zone: us-west-2a

# How Ray will authenticate with newly launched nodes.
   ssh_user: ubuntu

  - pip install ray[all]
  # The following line demonstrate that you can specify arbitrary
  # startup scripts on the cluster.
  - touch /tmp/some_file.txt

Most of the example YAML file is optional. Here is a reference minimal YAML file, and you can find the defaults for optional fields in this YAML file.

In another example, the AWS example configuration file cluster config file will create a small cluster with an m5.large head node (on-demand) configured to autoscale up to two m5.large spot workers.

You are encouraged to copy the example YAML file and modify it to your needs. This may include adding additional setup commands to install libraries or sync local data files.

Setup Commands


After you have customized the nodes, create a new machine image (or docker container) and use that in the config file to reduce setup times.

The setup commands you use should ideally be idempotent (i.e., can be run multiple times without changing the result). This allows Ray to safely update nodes after they have been created.

You can usually make commands idempotent with small modifications, e.g. git clone foo can be rewritten as test -e foo || git clone foo which checks if the repo is already cloned first.

Docker Support

The cluster launcher is fully compatible with Docker images. To use Docker, provide a docker_image and container_name in the docker field of the YAML.

    container_name: "ray_container"
    image: "rayproject/ray-ml:latest-gpu"

We provide docker images on DockerHub. The rayproject/ray-ml:latest image is a quick way to get up and running .

When the cluster is launched, all of the Ray tasks will be executed completely inside of the container. For GPU support, Ray will automatically select the Nvidia docker runtime if available, and you just need to specify a docker image with the CUDA support (rayproject/ray-ml:latest-gpu and all of our -gpu images have this).

If Docker is not installed, add the following commands to initialization_commands to install it.

    - curl -fsSL -o
    - sudo sh
    - sudo usermod -aG docker $USER
    - sudo systemctl restart docker -f

Common cluster configurations

The example-full.yaml configuration is enough to get started with Ray, but for more compute intensive workloads you will want to change the instance types to e.g. use GPU or larger compute instance by editing the yaml file.

Here are a few common configurations (note that we use AWS in the examples, but these examples are generic):

GPU single node: use Ray on a single large GPU instance.

max_workers: 0
    InstanceType: p2.8xlarge

Mixed GPU and CPU nodes: for RL applications that require proportionally more CPU than GPU resources, you can use additional CPU workers with a GPU head node.

max_workers: 10
    InstanceType: p2.8xlarge
    InstanceType: m4.16xlarge

Autoscaling CPU cluster: use a small head node and have Ray auto-scale workers as needed. This can be a cost-efficient configuration for clusters with bursty workloads. You can also request spot workers for additional cost savings.

min_workers: 0
max_workers: 10
    InstanceType: m4.large
        MarketType: spot
    InstanceType: m4.16xlarge

Autoscaling GPU cluster: similar to the autoscaling CPU cluster, but with GPU worker nodes instead.

min_workers: 0  # NOTE: older Ray versions may need 1+ GPU workers (#2106)
max_workers: 10
    InstanceType: m4.large
        MarketType: spot
    InstanceType: p2.xlarge