在 Azure 上启动 Ray 集群#

本指南详细介绍了在 Azure 上启动 Ray 集群所需的步骤。

有两种方法可以启动 Azure Ray 集群。

  • 通过 Ray 集群启动器启动。

  • 使用 Azure 门户部署集群。

注意

Azure 集成由社区维护。如果在遇到任何问题,请在 Github 上联系集成维护者:gramhagen, eisber, ijrsvt。

使用 Ray 集群启动器#

安装 Ray 集群启动器#

Ray 集群启动器是 ray CLI 的一部分。使用 CLI 可以通过 ray upray downray attach 等命令启动、停止和连接到正在运行的 Ray 集群。您可以使用 pip 安装支持集群启动器的 Ray CLI。有关更详细的说明,请参阅Ray 安装文档

# install ray
pip install -U ray[default]

安装和配置 Azure CLI#

接下来,安装 Azure CLI (pip install -U azure-cli azure-identity) 并使用 az login 登录。

# Install azure cli.
pip install azure-cli azure-identity

# Login to azure. This will redirect you to your web browser.
az login

使用 Ray 集群启动器启动 Ray#

提供的集群配置文件将创建一个小型集群,其中包含一个 Standard DS2v3 按需头节点,该节点配置为自动扩缩容至最多两个 Standard DS2v3 现成实例工作节点。

请注意,您需要在这些模板中填写 Azure 的 resource_grouplocation。您还需要设置要使用的订阅。您可以通过命令行使用 az account set -s <subscription_id> 完成此操作,或者在集群配置文件中填写 subscription_id

在您的本地机器上运行以下命令进行测试

# Download the example-full.yaml
wget https://raw.githubusercontent.com/ray-project/ray/master/python/ray/autoscaler/azure/example-full.yaml

# Update the example-full.yaml to update resource_group, location, and subscription_id.
# vi example-full.yaml

# Create or update the cluster. When the command finishes, it will print
# out the command that can be used to SSH into the cluster head node.
ray up example-full.yaml

# Get a remote screen on the head node.
ray attach example-full.yaml
# Try running a Ray program.

# Tear down the cluster.
ray down example-full.yaml

恭喜,您已在 Azure 上启动了一个 Ray 集群!

使用 Azure 门户#

或者,您也可以直接使用 Azure 门户部署集群。请注意,自动扩缩容是使用 Azure VM Scale Sets 完成的,而不是通过 Ray 自动扩缩容器。这将为头节点和由 Azure Virtual Machine Scale Sets 管理的可自动扩缩容集群部署 Azure 数据科学虚拟机 (DSVM)。头节点方便地同时暴露 SSH 和 JupyterLab。

模板成功部署后,部署输出页面将提供连接的 ssh 命令以及头节点上 JupyterHub 的链接(用户名/密码按照模板输入指定)。在 Jupyter notebook 中(使用模板输入中指定的 conda 环境,默认为 py38_tensorflow)使用以下代码连接到 Ray 集群。

import ray; ray.init()

在底层,执行 azure-init.sh 脚本并执行以下操作

  1. 激活 DSVM 上可用的某个 conda 环境

  2. 安装 Ray 和任何其他用户指定的依赖项

  3. 设置一个 systemd 任务 (/lib/systemd/system/ray.service) 以头节点或工作节点模式启动 Ray