Skip to main content

Migrate from Open Source Ray

When moving your Ray project to Anyscale, you do not need to change your Ray application code at all. There are a simple a couple of configurations to address when pivoting.

This guide assumes:

Concepts

  • In Anyscale, the monolithic cluster config has been split to two configurations, a cluster environment and a cluster compute configuration.
  • Anyscale will manage the cluster's lifecycle for you. It will launch clusters when needed and shut them down if they have not been used for a while. You can also manually modify the cluster using the web UI, Python SDK or HTTP API.

Migration steps

  1. Convert application dependencies:
  • If you require Debian packages, create a cluster environment.
  • If you require pip or Conda dependencies, you can create use the cluster environment to install them, or you can set up a runtime environment.
  • If you use Ray client to start an interactive session, the project directory will automatically upload to the cluster. This allows you to connect to the cluster and import any of your local modules. You can also specify a working directory using the working_dir parameter in a runtime environment. This lets you customize what files to sync to your cluster.
  1. Convert compute configs: If you need to customize your compute resources, you can create a cluster compute.

Connect to an Anyscale cluster

You can set the Ray address to an Anyscale URL, which will connect you to an Anyscale cluster, and also start one if it doesn't exist. You can check the interactive sessions section to know more about how to do this.

If you're trying to deploy your application in production, you can also check the production jobs and production services sections for more information.

Example

Before

deploy.py
import ray

@ray.remote
def do_work():
print("I'm doing some work")

ray.init(runtime_env={"pip": ["chess"]})

do_work.remote()
cluster.yaml
cluster_name: default
min_workers: 2
max_workers: 2
upscaling_speed: 1
idle_timeout_minutes: 5
provider:
type: aws
region: us-west-2
availability_zone: us-west-2a
auth:
ssh_user: ubuntu
head_node:
InstanceType: m4.16xlarge
ImageId: ami-0def3275
BlockDeviceMappings:
- DeviceName: "/dev/sda1"
Ebs:
VolumeSize: 50
worker_nodes:
InstanceType: m4.16xlarge
ImageId: ami-0def3275
BlockDeviceMappings:
- DeviceName: "/dev/sda1"
Ebs:
VolumeSize: 50
InstanceMarketOptions:
MarketType: spot
setup_commands:
- sudo apt-get update
- sudo apt-get install -y build-essential curl unzip
head_setup_commands: []
worker_setup_commands: []
head_start_ray_commands:
- ray stop
- ulimit -n 65536; ray start --head --port=6379 --autoscaling-config=~/ray_bootstrap_config.yaml
worker_start_ray_commands:
- ray stop
- ulimit -n 65536; ray start --address=$RAY_HEAD_IP:6379
ray start cluster.yaml # Returns some host and port for the cluster, e.g., ``123.45.67.89:10001``
export RAY_ADDRESS="123.45.67.89:10001"
python deploy.py

After

setup.py
from anyscale.sdk.anyscale_client.models import CreateClusterEnvironment
from anyscale.sdk.anyscale_client.models import CreateClusterCompute
from anyscale import AnyscaleSDK

sdk = AnyscaleSDK()

# Create cluster environment
cluster_environment_build = sdk.build_cluster_environment(
create_cluster_environment=CreateClusterEnvironment(
name="my-cluster-env",
config_json={
"base_image": "anyscale/ray-ml:1.4.0-py37",
"debian_packages": ["build-essential", "curl", "unzip"]
}
)
)

# Create cluster compute config
sdk.create_cluster_compute(CreateClusterCompute(
name="my-cluster-compute",
config={
"cloud_id": "cld_4F7k8814aZzGG8TNUGPKnc",
"allowed_azs": ["us-west-2a"],
"head_node_type": {
"name": "head_node_type",
"instance_type": "m4.16xlarge"
},
"worker_node_types": [{
"name": "worker_node_1",
"instance_type": "m4.16xlarge",
"min_workers": 2,
"max_workers": 2,
"use_spot": True

}],
"aws": {
"BlockDeviceMappings": [{
"DeviceName": "/dev/sda1",
"Ebs": {"VolumeSize": 50}
}]
}
}
))
export RAY_ADDRESS="anyscale://my-cluster?cluster_env=my-cluster-env:1&cluster_compute=my-cluster-compute"
python deploy.py # No code changes on `deploy.py`