

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

# Amazon SageMaker Debugger 參考
<a name="debugger-reference"></a>

在下列主題中，尋找有關使用 Amazon SageMaker Debugger 的詳細資訊和參考。

**Topics**
+ [Amazon SageMaker Debugger API](#debugger-apis)
+ [Debugger 規則的 Docker 映像檔](#debugger-docker-images-rules)
+ [Amazon SageMaker Debugger 例外狀況](#debugger-exceptions)
+ [Amazon SageMaker Debugger 支援的分散式訓練](#debugger-considerations)

## Amazon SageMaker Debugger API
<a name="debugger-apis"></a>

Amazon SageMaker Debugger 在很多位置都有 API 作業，用於實作模型訓練的監控和分析。

Amazon SageMaker Debugger 也提供開放原始碼 [`sagemaker-debugger` Python SDK](https://github.com/awslabs/sagemaker-debugger/tree/master/smdebug)，可用來設定內建規則、定義自訂規則以及註冊勾點，從訓練任務收集輸出張量資料。

[Amazon SageMaker AI Python SDK](https://sagemaker.readthedocs.io/en/stable/) 是一套以機器學習實驗為主的高階軟體開發套件。此軟體開發套件可用於部署以 `SMDebug` Python 程式庫定義的內建或自訂規則，以使用 SageMaker AI 估算器監控和分析這些張量。

Debugger 在 Amazon SageMaker API 中新增操作和類型，可讓平台在訓練模型時使用 Debugger，以及管理輸入和輸出的組態。
+ [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html) 和 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateTrainingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateTrainingJob.html) 使用下列 Debugger API 設定張量集合、規則、規則映像和分析選項：
  + [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CollectionConfiguration.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CollectionConfiguration.html)
  + [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugHookConfig.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugHookConfig.html)
  + [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugRuleConfiguration.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugRuleConfiguration.html)
  + [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_TensorBoardOutputConfig.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_TensorBoardOutputConfig.html)
  + [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerConfig.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerConfig.html)
  + [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerRuleConfiguration.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerRuleConfiguration.html)
+ [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeTrainingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeTrainingJob.html) 提供完整訓練任務描述，包含下列 Debugger 組態和規則評估狀態：
  + [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugHookConfig.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugHookConfig.html)
  + [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugRuleConfiguration.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugRuleConfiguration.html)
  + [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugRuleEvaluationStatus.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugRuleEvaluationStatus.html)
  + [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerConfig.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerConfig.html)
  + [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerRuleConfiguration.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerRuleConfiguration.html)
  + [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerRuleEvaluationStatus.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerRuleEvaluationStatus.html)

規則組態 API 作業會在分析模型訓練時使用 SageMaker Processing 功能。如需 SageMaker Processing 的詳細資訊，請參閱[使用 SageMaker Processing 的資料轉換工作負載](processing-job.md)。

## Debugger 規則的 Docker 映像檔
<a name="debugger-docker-images-rules"></a>

Amazon SageMaker AI 為規則提供兩組 Docker 映像：一組用於評估 SageMaker AI 提供的規則 (內建規則)，另一組用於評估 Python 來源檔案中提供的自訂規則。

如果您使用 [Amazon SageMaker Python SDK](https://sagemaker.readthedocs.io/en/stable)，您可以僅使用 SageMaker AI 高階偵錯器 API 作業搭配 SageMaker AI 估算器 API 作業，無需手動擷取偵錯器 Docker 映像並設定 `ConfigureTrainingJob` API。

如果您未使用 SageMaker Python SDK，則必須為偵錯器規則擷取相關的預先建置容器基礎映像。Amazon SageMaker Debugger 為內建和自訂規則提供預先建置的 Docker 映像，而該映像儲存在 Amazon Elastic Container Registry (Amazon ECR) 中。若要從 Amazon ECR 儲存庫提取映像 (或將映像推送到某儲存庫)，請使用 `CreateTrainingJob` API 使用該映像的全名登錄 URL。SageMaker AI 為偵錯器規則容器映像登錄位址使用下列 URL 模式。

```
<account_id>.dkr.ecr.<Region>.amazonaws.com/<ECR repository name>:<tag>
```

如需每個 AWS 區域中的帳戶 ID、Amazon ECR 儲存庫名稱和標籤值，請參閱下列主題。

**Topics**
+ [內建規則評估工具的 Amazon SageMaker Debugger 映像 URL](#debuger-built-in-registry-ids)
+ [自訂規則評估工具的 Amazon SageMaker Debugger 映像 URL](#debuger-custom-rule-registry-ids)

### 內建規則評估工具的 Amazon SageMaker Debugger 映像 URL
<a name="debuger-built-in-registry-ids"></a>

對於為 Amazon SageMaker Debugger 提供內建規則的映像，請對映像的登錄 URL 元件使用以下的值。如需帳戶 ID，請參閱下表。

**ECR 儲存庫名稱**：sagemaker-debugger-rules 

**標籤**：latest 

**完整的登錄 URL 範例**：

`904829902805.dkr.ecr.ap-south-1.amazonaws.com/sagemaker-debugger-rules:latest`

依 AWS 區域分類的內建規則容器映像的帳戶 IDs 


| 區域 | account\_id | 
| --- | --- | 
| af-south-1 | 314341159256 | 
| ap-east-1 | 199566480951 | 
| ap-northeast-1 | 430734990657  | 
| ap-northeast-2 | 578805364391 | 
| ap-south-1 | 904829902805 | 
| ap-southeast-1 | 972752614525 | 
| ap-southeast-2 | 184798709955 | 
| ca-central-1 | 519511493484 | 
| cn-north-1 | 618459771430 | 
| cn-northwest-1 | 658757709296 | 
| eu-central-1 | 482524230118 | 
| eu-north-1 | 314864569078 | 
| eu-south-1 | 563282790590 | 
| eu-west-1 | 929884845733 | 
| eu-west-2 | 250201462417 | 
| eu-west-3 | 447278800020 | 
| me-south-1 | 986000313247 | 
| sa-east-1 | 818342061345 | 
| us-east-1 | 503895931360 | 
| us-east-2 | 915447279597 | 
| us-west-1 | 685455198987 | 
| us-west-2 | 895741380848 | 
| us-gov-west-1 | 515509971035 | 

### 自訂規則評估工具的 Amazon SageMaker Debugger 映像 URL
<a name="debuger-custom-rule-registry-ids"></a>

對於為 Amazon SageMaker Debugger 提供自訂規則評估工具的映像，請對映像的登錄 URL 元件使用以下的值。如需帳戶 ID，請參閱下表。

**ECR 儲存庫名稱**：sagemaker-debugger-rule-evaluator 

**標籤**：latest 

**完整的登錄 URL 範例**：

`552407032007.dkr.ecr.ap-south-1.amazonaws.com/sagemaker-debugger-rule-evaluator:latest`

依 AWS 區域自訂規則容器映像的帳戶 IDs 


| 區域 | account\_id | 
| --- | --- | 
| af-south-1 | 515950693465 | 
| ap-east-1 | 645844755771 | 
| ap-northeast-1 | 670969264625  | 
| ap-northeast-2 | 326368420253 | 
| ap-south-1 | 552407032007 | 
| ap-southeast-1 | 631532610101 | 
| ap-southeast-2 | 445670767460 | 
| ca-central-1 | 105842248657 | 
| cn-north-1 | 617202126805 | 
| cn-northwest-1 | 658559488188 | 
| eu-central-1 | 691764027602 | 
| eu-north-1 | 091235270104 | 
| eu-south-1 | 335033873580 | 
| eu-west-1 | 606966180310 | 
| eu-west-2 | 074613877050 | 
| eu-west-3 | 224335253976 | 
| me-south-1 | 050406412588 | 
| sa-east-1 | 466516958431 | 
| us-east-1 | 864354269164 | 
| us-east-2 | 840043622174 | 
| us-west-1 | 952348334681 | 
| us-west-2 | 759209512951 | 
| us-gov-west-1 | 515361955729 | 

## Amazon SageMaker Debugger 例外狀況
<a name="debugger-exceptions"></a>

Amazon SageMaker Debugger 的設計指出不一定每個步驟都有執行規則所需的張量。因此會引發一些例外狀況，這讓您能夠掌控張量遺失時所發生的情況。這些例外狀況都收錄於 [smdebug.exceptions 模組](https://github.com/awslabs/sagemaker-debugger/blob/master/smdebug/exceptions.py)中。您可以如下所示匯入例外狀況：

```
from smdebug.exceptions import *
```

以下是可用的例外狀況：
+ `TensorUnavailableForStep`——步驟沒有所要求的張量。這可能意味著勾點完全沒有儲存此步驟，或者，此步驟可能儲存一些張量，但其中沒有所要求的張量。請注意，當您看到此例外狀況時，這意味著此步驟未來永遠不會有此張量。如果張量已儲存步驟的減量，則會通知您可以查詢減量。
+ `TensorUnavailable`——此張量未儲存，或尚未以 `smdebug` API 儲存。這意味著 `smdebug` 中的任何步驟從來沒有看過這個張量。
+ `StepUnavailable`——未儲存步驟，Debugger 沒有來自步驟的資料。
+ `StepNotYetAvailable`——`smdebug` 尚未看到步驟。如果訓練仍繼續進行，則未來可能會提供。Debugger 變為可用時，會自動載入新資料。
+ `NoMoreData`——在訓練結束時引發。看到這一項就知道已沒有更多步驟和張量要儲存。
+ `IndexReaderException`——索引讀取器無效。
+ `InvalidWorker` — 調用的工作者無效。
+ `RuleEvaluationConditionMet`——在步驟上評估規則，結果是符合條件。
+ `InsufficientInformationForRuleInvocation` — 提供的資訊不足，無法調用規則。

## Amazon SageMaker Debugger 支援的分散式訓練
<a name="debugger-considerations"></a>

下列清單顯示在具有深度學習架構和各種分散式訓練選項的訓練任務上使用 Debugger 的有效性範圍和考量事項。
+ **Horovod**

  使用 Debugger 進行 Horovod 訓練任務的有效性範圍    
[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/debugger-reference.html)
+ **SageMaker AI 分散式資料平行**

  使用 Debugger 與 SageMaker AI 分散式資料平行進行訓練任務的有效性範圍    
[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/debugger-reference.html)

  \* Debugger 不支援 TensorFlow 2.x 的架構分析。

  \*\* SageMaker AI 分散式資料平行不支援具有 Keras 實作的 TensorFlow 2.x。
+ **SageMaker AI 分散式模型平行**——Debugger 不支援 SageMaker AI 分散式模型平行訓練。
+ **具有 SageMaker AI 檢查點的分散式訓練**——啟用分散式訓練選項和 SageMaker AI 檢查點時，Debugger 不可用於訓練任務。您可能會看到類似以下的錯誤：

  ```
  SMDebug Does Not Currently Support Distributed Training Jobs With Checkpointing Enabled
  ```

  若要使用 Debugger 進行具有分散式訓練選項的訓練任務，您需要停用 SageMaker AI 檢查點，並將手動檢查點功能新增至訓練指令碼。有關 Debugger 搭配分散式訓練選項和檢查點使用的詳細資訊，請參閱[將 SageMaker AI 分散式資料平行與 Amazon SageMaker Debugger 和檢查點搭配使用](distributed-troubleshooting-data-parallel.md#distributed-ts-data-parallel-debugger)和[儲存檢查點](distributed-troubleshooting-model-parallel.md#distributed-ts-model-parallel-checkpoints)。
+ **參數伺服器**——Debugger不支援以參數伺服器為基礎的分散式訓練。
+ 沒有可用的分析分散式訓練架構作業，例如 SageMaker AI 分散式資料平行的 `AllReduced` 作業和 [Horovod 作業](https://horovod.readthedocs.io/en/stable/timeline_include.html)。