使用 Karpenter 自动扩缩功能创建和配置 HyperPod 集群 - 亚马逊 SageMaker AI
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Karpenter 自动扩缩功能创建和配置 HyperPod 集群

在以下步骤中,您将创建一个启用持续配置的 SageMaker HyperPod 集群,并将其配置为使用基于 Karpenter 的自动扩展。

创建集 HyperPod 群
  1. 加载您的环境配置并从 CloudFormation堆栈中提取值。

    source .env SUBNET1=$(cfn-output $VPC_STACK_NAME PrivateSubnet1) SUBNET2=$(cfn-output $VPC_STACK_NAME PrivateSubnet2) SUBNET3=$(cfn-output $VPC_STACK_NAME PrivateSubnet3) SECURITY_GROUP=$(cfn-output $VPC_STACK_NAME NoIngressSecurityGroup) EKS_CLUSTER_ARN=$(cfn-output $EKS_STACK_NAME ClusterArn) EXECUTION_ROLE=$(cfn-output $SAGEMAKER_STACK_NAME ExecutionRole) SERVICE_ROLE=$(cfn-output $SAGEMAKER_STACK_NAME ServiceRole) BUCKET_NAME=$(cfn-output $SAGEMAKER_STACK_NAME Bucket) HP_CLUSTER_NAME="hyperpod-eks-test-$(date +%s)" EKS_CLUSTER_NAME=$(cfn-output $EKS_STACK_NAME ClusterName) HP_CLUSTER_ROLE=$(cfn-output $SAGEMAKER_STACK_NAME ClusterRole)
  2. 将节点初始化脚本上传到 Amazon S3 存储桶。

    aws s3 cp lifecyclescripts/on_create_noop.sh s3://$BUCKET_NAME
  3. 使用环境变量创建集群配置文件。

    cat > cluster_config.json << EOF { "ClusterName": "$HP_CLUSTER_NAME", "InstanceGroups": [ { "InstanceCount": 1, "InstanceGroupName": "system", "InstanceType": "ml.c5.xlarge", "LifeCycleConfig": { "SourceS3Uri": "s3://$BUCKET_NAME", "OnCreate": "on_create_noop.sh" }, "ExecutionRole": "$EXECUTION_ROLE" }, { "InstanceCount": 0, "InstanceGroupName": "auto-c5-az1", "InstanceType": "ml.c5.xlarge", "LifeCycleConfig": { "SourceS3Uri": "s3://$BUCKET_NAME", "OnCreate": "on_create_noop.sh" }, "ExecutionRole": "$EXECUTION_ROLE" }, { "InstanceCount": 0, "InstanceGroupName": "auto-c5-4xaz2", "InstanceType": "ml.c5.4xlarge", "LifeCycleConfig": { "SourceS3Uri": "s3://$BUCKET_NAME", "OnCreate": "on_create_noop.sh" }, "ExecutionRole": "$EXECUTION_ROLE", "OverrideVpcConfig": { "SecurityGroupIds": [ "$SECURITY_GROUP" ], "Subnets": [ "$SUBNET2" ] } }, { "InstanceCount": 0, "InstanceGroupName": "auto-g5-az3", "InstanceType": "ml.g5.xlarge", "LifeCycleConfig": { "SourceS3Uri": "s3://$BUCKET_NAME", "OnCreate": "on_create_noop.sh" }, "ExecutionRole": "$EXECUTION_ROLE", "OverrideVpcConfig": { "SecurityGroupIds": [ "$SECURITY_GROUP" ], "Subnets": [ "$SUBNET3" ] } } ], "VpcConfig": { "SecurityGroupIds": [ "$SECURITY_GROUP" ], "Subnets": [ "$SUBNET1" ] }, "Orchestrator": { "Eks": { "ClusterArn": "$EKS_CLUSTER_ARN" } }, "ClusterRole": "$HP_CLUSTER_ROLE", "AutoScaling": { "Mode": "Enable", "AutoScalerType": "Karpenter" }, "NodeProvisioningMode": "Continuous" } EOF
  4. 运行以下命令来创建您的 HyperPod 集群。

    aws sagemaker create-cluster --cli-input-json file://./cluster_config.json
  5. 集群创建过程大约需要 20 分钟。监控集群状态,直到两者都 ClusterStatus 显示, AutoScaling.Status 都显示出来 InService。

  6. 保存集群 ARN 以供后续操作使用。

    HP_CLUSTER_ARN=$(aws sagemaker describe-cluster --cluster-name $HP_CLUSTER_NAME \ --output text --query ClusterArn)
启用 Karpenter 自动扩缩
  1. 运行以下命令,在任意具有持续节点预调配模式的预先存在的集群上,启用基于 Karpenter 的自动扩缩。

    aws sagemaker update-cluster \ --cluster-name $HP_CLUSTER_NAME \ --auto-scaling Mode=Enable,AutoScalerType=Karpenter \ --cluster-role $HP_CLUSTER_ROLE
  2. 确认已成功启用 Karpenter:

    aws sagemaker describe-cluster --cluster-name $HP_CLUSTER_NAME --query 'AutoScaling'
  3. 预期输出:

    { "Mode": "Enable", "AutoScalerType": "Karpenter", "Status": "InService" }

等待显示StatusInService后再继续配置 NodeClass 和 NodePool。