

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 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 串流。[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) 中的範例 LifecycleScripts 會將其 `stdout` 和 `stderr` 重新導向至此位置。如果您使用自訂指令碼，請將日誌寫入 `/var/log/provision/provisioning.log` 位置，讓它們可在 CloudWatch 中使用。

**生命週期指令碼日誌標記**

生命週期指令碼的 CloudWatch 日誌包含特定的標記，可協助您追蹤執行進度並識別問題：


|  |  | 
| --- |--- |
| Marker | Description | 
| 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 API
<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` 區段。

### 使用 SageMaker AI 的 AWS CLI 標記命令
<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
```