

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

# SageMaker HyperPod 集群管理
<a name="sagemaker-hyperpod-cluster-management-slurm"></a>

以下主题讨论了日志记录和管理 SageMaker HyperPod 集群。

## 记录 SageMaker HyperPod 事件
<a name="sagemaker-hyperpod-cluster-management-slurm-logging-hyperpod-events"></a>

来自的所有事件和日志 SageMaker HyperPod 都以日志组名称保存到 Amazon CloudWatch `/aws/sagemaker/Clusters/[ClusterName]/[ClusterID]`。每次调用 `CreateCluster` API 都会创建一个新的日志组。以下列表包含每个日志组收集的所有可用日志流。


|  |  | 
| --- |--- |
| 日志组名称 | 日志流名称 | 
| /aws/sagemaker/Clusters/[ClusterName]/[ClusterID] | LifecycleConfig/[instance-group-name]/[instance-id] | 

## SageMaker HyperPod 在实例级别进行日志记录
<a name="sagemaker-hyperpod-cluster-management-slurm-logging-at-instance-level"></a>

您可以访问在集群实例配置 CloudWatch 期间发布到的 LifecycleScript 日志。创建的集群中的每个实例都会生成单独的日志流，以 `LifecycleConfig/[instance-group-name]/[instance-id]` 格式区分。

写入的所有日志都将`/var/log/provision/provisioning.log`上传到前面的 CloudWatch 流中。 LifecycleScripts 在[https://github.com/aws-samples/awsome-distributed-training/tree/main/1.architectures/5.sagemaker-hyperpod/LifecycleScripts/base-config](https://github.com/aws-samples/awsome-distributed-training/tree/main/1.architectures/5.sagemaker-hyperpod/LifecycleScripts/base-config)将他们`stdout`和重定向`stderr`到此位置时示例。如果您使用的是自定义脚本，请将日志写入可用的`/var/log/provision/provisioning.log`位置 CloudWatch。

**生命周期脚本日志标记**

CloudWatch 生命周期脚本的日志包含特定的标记，可帮助您跟踪执行进度并识别问题：


|  |  | 
| --- |--- |
| Marker | 描述 | 
| START | Indicates the beginning of lifecycle script logs for the instance | 
| [SageMaker] Lifecycle scripts were provided, with S3 uri: {{[s3://bucket-name/]}} and entrypoint script: {{[script-name.sh]}} | Indicates the S3 location and entrypoint script that will be used | 
| [SageMaker] Downloading lifecycle scripts | Indicates scripts are being downloaded from the specified S3 location | 
| [SageMaker] Lifecycle scripts have been downloaded | Indicates scripts have been successfully downloaded from S3 | 
| [SageMaker] The lifecycle scripts succeeded | Indicates successful completion of all lifecycle scripts | 
| [SageMaker] The lifecycle scripts failed | Indicates failed execution of lifecycle scripts | 

这些标记可帮助您快速确定问题在生命周期脚本执行过程中的哪个位置出现。排除故障时，请查看日志条目以确定进程在何处停止或失败。

**生命周期脚本失败消息**

如果生命周期脚本存在但在执行过程中失败，您将收到一条包含 CloudWatch 日志组名称和日志流名称的错误消息。如果多个实例出现生命周期脚本故障，则错误消息将仅显示一个失败的实例，但日志组应包含所有实例的流。

您可以通过运行 [DescribeCluster](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeCluster.html)API 或在 SageMaker 控制台中查看集群详细信息页面来查看错误消息。控制台中提供了 “**查看生命周期脚本日志**” 按钮，可直接导航到 CloudWatch 日志流。错误消息采用以下格式：

```
Instance {{[instance-id]}} failed to provision with the following error: "Lifecycle scripts did not run successfully. To view lifecycle script logs,
visit log group ‘/aws/sagemaker/Clusters/{{[cluster-name]}}/{{[cluster-id]}}' and log stream ‘LifecycleConfig/{{[instance-group-name]}}/{{[instance-id]}}’.
If you cannot find corresponding lifecycle script logs in CloudWatch, please make sure you follow one of the options here:
https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-hyperpod-faq-slurm.html#hyperpod-faqs-q1.” Note that multiple instances may be impacted.
```

## 标注资源
<a name="sagemaker-hyperpod-cluster-management-slurm-tagging"></a>

AWS 标签系统有助于管理、识别、组织、搜索和筛选资源。 SageMaker HyperPod 支持标记，因此您可以将群集作为 AWS 资源进行管理。在创建集群或编辑现有集群期间，您可以为集群添加或编辑标签。要了解有关标记的更多一般信息，请参阅[标记 AWS 资源](https://docs.aws.amazon.com/tag-editor/latest/userguide/tagging.html)。

### 使用 SageMaker HyperPod 控制台 UI
<a name="sagemaker-hyperpod-cluster-management-slurm-tagging-in-console"></a>

在[创建新集群](sagemaker-hyperpod-operate-slurm-console-ui.md#sagemaker-hyperpod-operate-slurm-console-ui-create-cluster)和[编辑集群](sagemaker-hyperpod-operate-slurm-console-ui.md#sagemaker-hyperpod-operate-slurm-console-ui-edit-clusters)时，您可以添加、删除或编辑标签。

### 使用 SageMaker HyperPod APIs
<a name="sagemaker-hyperpod-cluster-management-slurm-tagging-in-api-request"></a>

当您以 JSON 格式编写[CreateCluster](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateCluster.html)或 [UpdateCluster](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateCluster.html)API 请求文件时，请编辑该`Tags`部分。

### 使用适用于 AI 的 AWS CLI SageMaker 标记命令
<a name="sagemaker-hyperpod-cluster-management-slurm-tagging-using-cli"></a>

**要标记一个集群**

按如下方式使用 [https://docs.aws.amazon.com/cli/latest/reference/sagemaker/add-tags.html](https://docs.aws.amazon.com/cli/latest/reference/sagemaker/add-tags.html)。

```
aws sagemaker add-tags --resource-arn {{cluster_ARN}} --tags Key={{string}},Value={{string}}
```

**要取消标记一个集群**

按如下方式使用 [https://docs.aws.amazon.com/cli/latest/reference/sagemaker/delete-tags.html](https://docs.aws.amazon.com/cli/latest/reference/sagemaker/delete-tags.html)。

```
aws sagemaker delete-tags --resource-arn {{cluster_ARN}} --tag-keys {{"tag_key"}}
```

**列出资源的标签**

按如下方式使用 [https://docs.aws.amazon.com/cli/latest/reference/sagemaker/list-tags.html](https://docs.aws.amazon.com/cli/latest/reference/sagemaker/list-tags.html)。

```
aws sagemaker list-tags --resource-arn {{cluster_ARN}}
```