Skip to main content
Version: 1.1

Ray Launcher plugin

PyPI PyPI - License PyPI - Python Version PyPI - Downloads Example Example

The Ray Launcher plugin provides 2 launchers: ray_aws and ray. ray_aws launches jobs remotely on AWS and is built on top of ray autoscaler sdk. ray launches jobs on your local machine or existing ray cluster.


$ pip install hydra-ray-launcher --upgrade


Once installed, add hydra/launcher=ray_aws or hydra/launcher=ray to your command line. Alternatively, override hydra/launcher in your config:

defaults:  - override hydra/launcher: ray_aws

There are several standard approaches for configuring plugins. Check this page for more information.

ray_aws launcher#


ray_aws launcher is built on top of ray's autoscaler sdk. To get started, you need to config your AWS credentials. ray autoscaler sdk expects your AWS credentials have certain permissions for EC2 and IAM. Read this for more information.

ray autoscaler sdk expects a configuration for the EC2 cluster; we've schematized the configs in here

Discover ray_aws launcher's config
$ python hydra/launcher=ray_aws --cfg hydra -p hydra.launcher# @package hydra.launcher_target_: hydra_plugins.hydra_ray_launcher.ray_aws_launcher.RayAWSLauncherenv_setup:  pip_packages:    omegaconf: ${ray_pkg_version:omegaconf}    hydra_core: ${ray_pkg_version:hydra}    ray: ${ray_pkg_version:ray}    cloudpickle: ${ray_pkg_version:cloudpickle}    pickle5: 0.0.11    hydra_ray_launcher: 1.1.0.dev3  commands:  - conda create -n hydra_${python_version:micro} python=${python_version:micro} -y  - echo 'export PATH="$HOME/anaconda3/envs/hydra_${python_version:micro}/bin:$PATH"'    >> ~/.bashrcray:  init:    address: null  remote: {}  cluster:    cluster_name: default    min_workers: 0    max_workers: 1    initial_workers: 0    autoscaling_mode: default    target_utilization_fraction: 0.8    idle_timeout_minutes: 5    docker:      image: ''      container_name: ''      pull_before_run: true      run_options: []    provider:      type: aws      region: us-west-2      availability_zone: us-west-2a,us-west-2b      cache_stopped_nodes: false      key_pair:        key_name: hydra-${oc.env:USER,user}    auth:      ssh_user: ubuntu    head_node:      InstanceType: m5.large      ImageId: ami-008d8ed4bd7dc2485    worker_nodes:      InstanceType: m5.large      ImageId: ami-008d8ed4bd7dc2485    file_mounts: {}    initialization_commands: []    setup_commands: []    head_setup_commands: []    worker_setup_commands: []    head_start_ray_commands:    - ray stop    - ulimit -n 65536;ray start --head --port=6379 --object-manager-port=8076      --autoscaling-config=~/ray_bootstrap_config.yaml    worker_start_ray_commands:    - ray stop    - ulimit -n 65536; ray start --address=$RAY_HEAD_IP:6379 --object-manager-port=8076  run_env: autostop_cluster: truesync_up:  source_dir: null  target_dir: null  include: []  exclude: []sync_down:  source_dir: null  target_dir: null  include: []  exclude: []logging:  log_style: auto  color_mode: auto  verbosity: 0create_update_cluster:  no_restart: false  restart_only: false  no_config_cache: falseteardown_cluster:  workers_only: false  keep_min_workers: false


The following examples can be found here.

Simple app
$ python --multirun task=1,2,3[HYDRA] Ray Launcher is launching 3 jobs, [HYDRA]        #0 : task=1[HYDRA]        #1 : task=2[HYDRA]        #2 : task=3[HYDRA] Pickle for jobs: /var/folders/n_/9qzct77j68j6n9lh0lw3vjqcn96zxl/T/tmpqqg4v4i7/job_spec.pklCluster: default...INFO -- View the Ray dashboard at http://localhost:8265(pid=3374) [__main__][INFO] - Executing task 1(pid=3374) [__main__][INFO] - Executing task 2(pid=3374) [__main__][INFO] - Executing task 3...[HYDRA] Stopping cluster now. (stop_cluster=true)[HYDRA] Deleted the cluster (provider.cache_stopped_nodes=false)Destroying cluster. Confirm [y/N]: y [automatic, due to --yes]...No nodes remaining.
Upload & Download from remote cluster

If your application is dependent on multiple modules, you can configure hydra.launcher.sync_up to upload dependency modules to the remote cluster. You can also configure hydra.launcher.sync_down to download output from remote cluster if needed. This functionality is built on top of rsync, include and exclude is consistent with how it works in rsync.

$  python --multirun random_seed=1,2,3[HYDRA] Ray Launcher is launching 3 jobs, [HYDRA]        #0 : random_seed=1[HYDRA]        #1 : random_seed=2[HYDRA]        #2 : random_seed=3[HYDRA] Pickle for jobs: /var/folders/n_/9qzct77j68j6n9lh0lw3vjqcn96zxl/T/tmptdkye9of/job_spec.pklCluster: default...INFO -- View the Ray dashboard at http://localhost:8265(pid=1772) [__main__][INFO] - Start training...(pid=1772) [INFO] - Init my model(pid=1772) [INFO] - Created dir for checkpoints. dir=checkpoint(pid=1772) [__main__][INFO] - Start training...(pid=1772) [INFO] - Init my model(pid=1772) [INFO] - Created dir for checkpoints. dir=checkpoint(pid=1772) [__main__][INFO] - Start training...(pid=1772) [INFO] - Init my model(pid=1772) [INFO] - Created dir for checkpoints. dir=checkpointLoaded cached provider configuration...[HYDRA] Output: receiving file list ... done16-32-25/16-32-25/0/16-32-25/0/checkpoint/16-32-25/0/checkpoint/checkpoint_1.pt16-32-25/1/16-32-25/1/checkpoint/16-32-25/1/checkpoint/checkpoint_2.pt16-32-25/2/16-32-25/2/checkpoint/16-32-25/2/checkpoint/[HYDRA] Stopping cluster now. (stop_cluster=true)[HYDRA] Deleted the cluster (provider.cache_stopped_nodes=false)Destroying cluster. Confirm [y/N]: y [automatic, due to --yes]...No nodes remaining.
Manage Cluster LifeCycle#

You can manage the Ray EC2 cluster lifecycle by configuring the flags provided by the plugin:

  • Default setting (no need to specify on commandline): delete cluster after job finishes remotely:

  • Keep cluster running after jobs finishes remotely

  • Power off EC2 instances and control node termination using hydra.launcher.ray.cluster.provider.cache_stopped_nodes and hydra.launcher.teardown_cluster.workers_only

    falsefalseAll nodes are terminated
    falsetrueKeeps head node running and terminates only worker node
    truefalseKeeps both head node and worker node and stops both of them
    truetrueKeeps both head node and worker node and stops only worker node
  • Keep hydra.launcher.ray.cluster.min_workers worker nodes and delete the rest of the worker nodes


Additionally, you can configure how to create or update the cluster:

  • Default config: run setup commands, restart Ray and use the config cache if available

  • Skip restarting Ray services when updating the cluster config

  • Skip running setup commands and only restart Ray (cannot be used with hydra.launcher.create_update_cluster.no_restart)

  • Fully resolve all environment settings from the cloud provider again

Configure Ray Logging#

You can manage Ray specific logging by configuring the flags provided by the plugin:

  • Default config: use minimal verbosity and automatically detect whether to use pretty-print and color mode

  • Disable pretty-print

  • Disable color mode

  • Increase Ray logging verbosity


ray launcher#

ray launcher lets you launch application on your ray cluster or local machine. You can easily config how your jobs are executed by changing ray launcher's configuration here ~/hydra/plugins/hydra_ray_launcher/hydra_plugins/hydra_ray_launcher/conf/hydra/launcher/ray.yaml

The example application starts a new ray cluster.

$ python  --multirun hydra/launcher=ray[HYDRA] Ray Launcher is launching 1 jobs, sweep output dir: multirun/2020-11-10/15-16-28[HYDRA] Initializing ray with config: {}INFO -- View the Ray dashboard at[HYDRA]        #0 : (pid=97801) [__main__][INFO] - Executing task 1

You can run the example application on your existing ray cluster as well by overriding hydra.launcher.ray.init.address:

$ python  --multirun hydra/launcher=ray hydra.launcher.ray.init.address=localhost:6379'[HYDRA] Ray Launcher is launching 1 jobs, sweep output dir: multirun/2020-11-10/15-13-32[HYDRA] Initializing ray with config: {'num_cpus': None, 'num_gpus': None, 'address': 'localhost:6379'}INFO -- Connecting to existing Ray cluster at address:[HYDRA]        #0 : (pid=93358) [__main__][INFO] - Executing task 1

Configure ray.init() and ray.remote()#

Ray launcher is built on top of ray.init() and ray.remote(). You can configure ray by overriding hydra.launcher.ray.init and hydra.launcher.ray.remote. Check out an example config.