本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
开始 SageMaker HyperPod使用 Amazon CLI
使用中的Amazon CLI命令创建您的第一个 SageMaker HyperPod 集群 HyperPod。
使用 Slurm 创建你的第一个 SageMaker HyperPod 集群
以下教程演示了如何创建新 SageMaker HyperPod 集群并通过的Amazon CLI命令使用 Slurm 对其进行设置。 SageMaker HyperPod按照教程,您将创建一个包含三个 Slurm 节点的 HyperPod 集群,my-controller-groupmy-login-group、和。worker-group-1
-
首先,准备生命周期脚本并将其上传到 Amazon S3 存储桶。在创建集群期间,在每个实例组中 HyperPod 运行它们。使用以下命令将生命周期脚本上传到 Amazon S3。
aws s3 sync \ ~/local-dir-to-lifecycle-scripts/* \ s3://sagemaker-<unique-s3-bucket-name>/<lifecycle-script-directory>/src注意
S3 存储桶路径应以
sagemaker-前缀开头,因为 的 IAM 角色适用于 SageMaker HyperPod 与AmazonSageMakerClusterInstanceRolePolicy仅允许访问以特定前缀开头的 Amazon S3 存储桶。如果您是从头开始,请使用 Awsome 分布式训练 GitHub 存储库
中提供的示例生命周期脚本。以下子步骤说明了如何下载、修改和上传示例生命周期脚本到 Amazon S3 存储桶。 -
下载生命周期脚本示例到本地计算机的一个目录中。
git clone https://github.com/aws-samples/awsome-distributed-training/ -
进入目录
1.architectures/5.sagemaker_hyperpods/LifecycleScripts/base-config,可以找到一组生命周期脚本。 cd awsome-distributed-training/1.architectures/5.sagemaker_hyperpods/LifecycleScripts/base-config要了解生命周期脚本示例的更多信息,请参阅 使用生命周期脚本自定义 SageMaker HyperPod集群。
-
编写 Slurm 配置文件并保存为
provisioning_parameters.json。在文件中,指定基本的 Slurm 配置参数,以便将 Slurm 节点正确分配给集群实例组。 SageMaker HyperPod 在本教程中,请设置三个 Slurm 节点,分别命名为my-controller-group、my-login-group和worker-group-1,如以下示例配置provisioning_parameters.json所示。{ "version": "1.0.0", "workload_manager": "slurm", "controller_group": "my-controller-group", "login_group": "my-login-group", "worker_groups": [ { "instance_group_name": "worker-group-1", "partition_name": "partition-1" } ] } -
将脚本上传到
s3://sagemaker-。您可以使用 Amazon S3 管理控制台或运行以下 Amazon CLI Amazon S3 命令来完成此操作。<unique-s3-bucket-name>/<lifecycle-script-directory>/srcaws s3 sync \ ~/local-dir-to-lifecycle-scripts/* \ s3://sagemaker-<unique-s3-bucket-name>/<lifecycle-script-directory>/src
-
-
准备一个 JSON 格式的CreateCluster请求文件并另存为
create_cluster.json。以下请求模板与步骤 1.c 中provisioning_parameters.json中定义的 Slurm 节点配置一致。对于ExecutionRole,请提供在 使用 SageMaker HyperPod 的先决条件 中使用托管的AmazonSageMakerClusterInstanceRolePolicy创建的 IAM 角色的 ARN。{// Required: Specify the name of the cluster."ClusterName": "my-hyperpod-cluster",// Required: Configure instance groups to be launched in the cluster"InstanceGroups": [ {// Required: Specify the basic configurations to set up a controller node."InstanceGroupName": "my-controller-group", "InstanceType": "ml.c5.xlarge", "InstanceCount":1, "LifeCycleConfig": { "SourceS3Uri": "s3://sagemaker-<unique-s3-bucket-name>/<lifecycle-script-directory>/src", "OnCreate": "on_create.sh" }, "ExecutionRole": "${ROLE}",// Optional: Configure an additional storage per instance group."InstanceStorageConfigs": [ {// Attach an additional EBS volume to each instance within the instance group.// The default mount path for the additional EBS volume is /opt/sagemaker."EbsVolumeConfig":{// Specify an integer between 1 and 16384 in gigabytes (GB)."VolumeSizeInGB":<integer>} } ] }, { "InstanceGroupName": "my-login-group", "InstanceType": "ml.m5.4xlarge", "InstanceCount":1, "LifeCycleConfig": { "SourceS3Uri": "s3://sagemaker-<unique-s3-bucket-name>/<lifecycle-script-directory>/src", "OnCreate": "on_create.sh" }, "ExecutionRole": "${ROLE}" }, { "InstanceGroupName": "worker-group-1", "InstanceType": "ml.trn1.32xlarge", "InstanceCount":1, "LifeCycleConfig": { "SourceS3Uri": "s3://sagemaker-<unique-s3-bucket-name>/<lifecycle-script-directory>/src", "OnCreate": "on_create.sh" }, "ExecutionRole": "${ROLE}" } ] } -
运行以下命令创建集群。
aws sagemaker create-cluster --cli-input-jsonfile://complete/path/to/create_cluster.json这将返回已创建集群的 ARN。
如果因资源限制而出现错误,请确保将实例类型更改为账户中有足够配额的类型,或按照 SageMaker HyperPod 配额中的说明操作来请求额外配额。
-
运行
describe-cluster查看集群状态。aws sagemaker describe-cluster --cluster-namemy-hyperpod-cluster集群状态变为
InService后,进入下一步。 -
运行
list-cluster-nodes检查集群节点的详细信息。aws sagemaker list-cluster-nodes --cluster-namemy-hyperpod-cluster这将返回一个响应,
InstanceId是集群用户登录 (aws ssm) 所需的信息。有关登录集群节点和运行 ML 工作负载的更多信息,请参阅 SageMaker HyperPod 集群上的作业。
删除集群并清理资源
成功测试创建 SageMaker HyperPod 集群后,它会继续以该InService状态运行,直到您删除该集群。我们建议您在不使用按需 SageMaker AI 容量时删除任何使用按需 AI 容量创建的集群,以免产生基于按需定价的持续服务费。在本教程中,您创建了一个由两个实例组组成的集群。其中一个使用 C5 实例,因此请确保运行以下命令删除集群。
aws sagemaker delete-cluster --cluster-namemy-hyperpod-cluster
要从本教程使用的 Amazon S3 存储桶中清理生命周期脚本,请转到集群创建过程中使用的 Amazon S3 存储桶并完全删除文件。
如果您已测试在集群上运行任何模型训练工作负载,还要检查您是否上传了任何数据,或者您的任务是否已将任何项目保存到不同的 Amazon S3 存储桶或文件系统服务(例如 Amazon for Lustre 和 Amazon FSx Elastic File System)中。为防止产生费用,请删除存储或文件系统中的所有构件和数据。