Compute Configs
Cluster compute configs specify the resources your cluster will use. Cluster compute configs are optional, since Anyscale has defaults for all the values that the compute template can specify. Nevertheless, sometimes it's useful to specify some of the configs to override the default the values.
You might be familiar with Ray's cluster.yaml
, which specifies a large number of configs in a single file. Cluster compute configs are subset of this file.
Definition
The following is a fully specified example of compute config:
- AWS (EC2)
- GCP (GCE)
cloud: my-cloud # You may specify `cloud_id` instead
allowed_azs:
- us-west-2a
head_node_type:
name: head_node_type
instance_type: m5.8xlarge
worker_node_types:
- name: cpu_worker
instance_type: m5.8xlarge
min_workers: 2
max_workers: 10
use_spot: true
fallback_to_ondemand: true
- name: gpu_worker
instance_type: g4dn.4xlarge
min_workers: 2
max_workers: 10
aws:
BlockDeviceMappings:
- DeviceName: "/dev/sda1"
Ebs:
VolumeSize: 50
DeleteOnTermination: true
IamInstanceProfile:
Arn: arn:aws:iam:etc
NetworkInterfaces:
- SubnetId: subnet-etc
Groups:
- sg-etc
AssociatePublicIpAddress: true
TagSpecifications:
- ResourceType: instance
Tags:
- Key: my-key
Value: my-value
cloud: my-cloud # You may specify `cloud_id` instead
region: us-west1
allowed_azs:
- us-west1-b
head_node_type:
name: head_node
instance_type: n2-standard-32
worker_node_types:
- name: cpu_worker
instance_type: n2-standard-32
min_workers: 1
max_workers: 10
use_spot: true
fallback_to_ondemand: true
- name: gpu_worker
instance_type: n1-standard-16-nvidia-t4-16gb-1
min_workers: 1
max_workers: 10
gcp_advanced_configurations_json:
instance_properties:
disks:
- boot: true
auto_delete: true
initialize_params:
disk_size_gb: 200
service_accounts:
- email: email-etc
scopes:
- https://www.googleapis.com/auth/cloud-platform
network_interfaces:
- subnetwork: subnetUrl-etc
access_configs:
- type: ONE_TO_ONE_NAT
labels:
my-key: my-value
Note that you can specify the following in your cluster compute configs:
- A cloud, which defaults to your default cloud (set by an organization owner for the entire organization). On the SDK, this can only be specified as
cloud_id
. On the CLI, you may specifycloud
(the cloud name) instead. The SDK example below show how to resolve acloud
into acloud_id
. - A head node type, which defaults to
m5.8xlarge
on AWS orn2-standard-32
on GCP. - A list of worker node types, which by default includes:
- A CPU node type, which defaults to
m5.8xlarge
on AWS orn2-standard-32
on GCP. - A GPU node type, which defaults to
g4dn.4xlarge
on AWS orn1-standard-16-nvidia-t4-16gb-1
on GCP.
- A CPU node type, which defaults to
- AWS-specific configs, which are supported properties that will be passed directly to AWS when starting the instances.
When specifying instance types, you may specify any instance type supported by Anyscale as detailed on this page. In addition to the instance type, node types allow you to specify:
- The node type name, which is used in logs.
- Spot instance usage, which defaults to
false
. - Fallback to On Demand (requires Spot instance usage to be set to
true
), which defaults tofalse
. - A minimum and maximum number of workers.
- Instance specific cloud configurations, including Capacity Reservation IDs.
Global max_workers
is excluded from the compute config. It is no longer supported in Anyscale Ray 2.7+.
The advanced AWS-specific configuration (aws
block) is passed directly to the EC2 API when creating instances. You can use this to configure special parameters for your instances such as EBS disk size, security groups, and the subnet it resides in. We support the fields listed in the example, and the settings are applied to all instances launched for your cluster.
Please use caution when setting advanced AWS-specific configuration. Incorrect settings may cause your cluster to fail. The content of these fields is not validated before being passed to AWS.
Creating a compute config
You can use your cluster configs definition to create a compute config using the CLI, the Python SDK and the HTTP API:
- CLI
- Python SDK
anyscale compute-config create my_compute_configs.yaml --name my-cluster-compute
import yaml
from anyscale.sdk.anyscale_client.models import CreateClusterCompute
from anyscale import AnyscaleSDK
sdk = AnyscaleSDK()
with open('my_compute_configs.yaml') as f:
compute_configs = yaml.safe_load(f)
# If your config file contains `cloud`, use this to get the `cloud_id`
if "cloud" in compute_configs:
compute_configs["cloud_id"] = sdk.search_clouds(
{"name": {"equals": compute_configs["cloud"]}}
).results[0].id
del compute_configs["cloud"]
config=sdk.create_cluster_compute(CreateClusterCompute(
name="my-cluster-compute",
config=compute_configs
))
For more information, you can check the full reference of the CLI, Python SDK and the HTTP API.
You can also create a cluster compute in the Web UI by navigating to "Configurations > Compute configs > Create a new config" to create a cluster compute config. You can also create one on the fly when you create a new cluster.
FAQ
Capacity Reservations
Some instance types might be challenging to secure from cloud providers due to high demand or limited availability. Anyscale Clusters can utilize capacity reservations to ensure that you are able to launch the node types that you need for your workloads. To manage the capacity reservation configuration for a specific worker node type, you need to modify the Advanced Instance Configuration for that node. This can be done through the Web UI or through a compute config definition file.
- AWS (EC2)
- GCP (GCE)
To manage it from the Web UI, expand a Worker Node, then expand "Resources and instance config (advanced)", then click on the "Instance config" tab. You'll want to provide the following JSON, replacing the reservation ID with your own:
{
"CapacityReservationSpecification": {
"CapacityReservationTarget": {
"CapacityReservationId": "cr-0123456789abcdefg"
}
}
}
To manage capacity reservation from the Anyscale CLI or SDK, the following YAML example can be used:
cloud: my-cloud # You may specify `cloud_id` instead
allowed_azs:
- us-west-2a
head_node_type:
name: head_node_type
instance_type: m5.8xlarge
worker_node_types:
- name: accelerated_worker
instance_type: p4d.24xlarge
min_workers: 1
max_workers: 1
aws_advanced_configurations_json:
CapacityReservationSpecification:
CapacityReservationTarget:
CapacityReservationId: cr-0123456789abcdefg # Change to your reservation ID.
To manage it from the Web UI, expand a Worker Node, then expand "Resources and instance config (advanced)", then click on the "Instance config" tab. You'll want to provide the following JSON, replacing reservation-01
with your own reservation name:
{
"instanceProperties": {
"reservationAffinity": {
"consumeReservationType": "SPECIFIC_RESERVATION",
"key": "compute.googleapis.com/reservation-name",
"values": [
"reservation-01"
]
}
}
}
To manage capacity reservation from the Anyscale CLI or SDK, the following YAML example can be used:
cloud: my-cloud # You may specify `cloud_id` instead
region: us-west1
allowed_azs:
- us-west1-b
head_node_type:
name: head_node
instance_type: n2-standard-32
worker_node_types:
- name: accelerated_worker
instance_type: a2-ultragpu-1g
min_workers: 1
max_workers: 1
gcp_advanced_configurations_json:
instanceProperties:
reservationAffinity:
consumeReservationType: SPECIFIC_RESERVATION
key: compute.googleapis.com/reservation-name
values: [reservation-01] # This is the reservation name
Google Cloud also allows you to use any open reservation in a Google Project. Please see the Google documentation for how to use these.