基于 Ray 的分布式训练

Ludwig 对 Ray 提供强大的支持,Ray 是一个分布式计算框架,可以轻松地将运行在本地机器上的代码扩展到跨机器集群并行执行。

让我们启动一个 Ray 集群,这样我们就可以并行地尝试分布式训练和超参数调优。请确保您有权访问 AWS EC2 节点提供程序。

首先安装 Ray 集群启动器

pip install ray

接下来,让我们为 Ray 集群创建一个名为 cluster.yaml 的配置文件

cluster.yaml
cluster_name: ludwig-ray-gpu-latest

min_workers: 4
max_workers: 4

docker:
    image: "ludwigai/ludwig-ray-gpu:latest"
    container_name: "ray_container"

head_node:
    InstanceType: m5.2xlarge
    ImageId: latest_dlami

worker_nodes:
    InstanceType: g4dn.2xlarge
    ImageId: latest_dlami

最后,您可以使用以下命令启动集群

ray up cluster.yaml

为了运行分布式训练作业,请确保您的数据集存储在 S3 存储桶中,然后运行此命令

ray submit cluster.yaml ludwig train --config rotten_tomatoes.yaml --dataset s3://mybucket/rotten_tomatoes.csv

您也可以使用此命令运行分布式超参数优化作业

ray submit cluster.yaml ludwig hyperopt --config rotten_tomatoes.yaml --dataset s3://mybucket/rotten_tomatoes.csv

有关在 Ludwig 中使用 Ray 的更多信息,请参阅 Ray 配置指南