

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

# Amazon SageMaker 调试器参考资料
<a name="debugger-reference"></a>

在以下主题中查找有关使用 Amazon SageMaker Debugger 的更多信息和参考资料。

**Topics**
+ [Amazon SageMaker 调试器 APIs](#debugger-apis)
+ [用于 Debugger 规则的 Docker 映像](#debugger-docker-images-rules)
+ [Amazon SageMaker 调试器异常](#debugger-exceptions)
+ [由 Amazon SageMaker 调试器支持的分布式训练](#debugger-considerations)

## Amazon SageMaker 调试器 APIs
<a name="debugger-apis"></a>

Amazon SageMaker Debugger 在多个位置都有用于监控和分析模型训练的 API 操作。

Amazon D SageMaker ebugger 还提供了开源 [`sagemaker-debugger`Python SDK](https://github.com/awslabs/sagemaker-debugger/tree/master/smdebug)，用于配置内置规则、定义自定义规则和注册挂钩以收集训练作业的输出张量数据。

[Amazon SageMaker AI Python S](https://sagemaker.readthedocs.io/en/stable/) DK 是一款专注于机器学习实验的高级软件开发工具包。SDK 可用于部署由 `SMDebug` Python 库定义的内置规则或自定义规则，以便使用 SageMaker AI 估计器监控和分析这些张量。

调试器已向 Amazon SageMaker API 添加了操作和类型，使平台能够在训练模型时使用调试器并管理输入和输出的配置。
+ [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 APIs 来配置张量集合、规则、规则图像和分析选项：
  + [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 处理功能。有关 SageMaker 处理的更多信息，请参阅[带 SageMaker 处理功能的数据转换工作负载](processing-job.md)。

## 用于 Debugger 规则的 Docker 映像
<a name="debugger-docker-images-rules"></a>

Amazon SageMaker AI 为规则提供了两组 Docker 镜像：一组用于评估 SageMaker AI 提供的规则（内置规则），另一组用于评估 Python 源文件中提供的自定义规则。

如果您使用 [Amaz SageMaker on Python SDK](https://sagemaker.readthedocs.io/en/stable)，则只需将 SageMaker AI 高级调试器 API 操作与 SageMaker AI Estimator API 操作一起使用，而不必手动检索调试器 Docker 镜像和配置 API。`ConfigureTrainingJob`

如果您不使用 SageMaker Python SDK，则必须为调试器规则检索相关的预构建容器基础镜像。Amazon D SageMaker ebugger 为内置规则和自定义规则提供预构建的 Docker 镜像，这些镜像存储在亚马逊弹性容器注册表 (Amazon ECR) Container Registry 中。要从 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 调试器图片 URIs](#debuger-built-in-registry-ids)
+ [URIs 适用于自定义规则评估者的 Amazon SageMaker 调试器图片](#debuger-custom-rule-registry-ids)

### 内置规则评估器的 Amazon SageMaker 调试器图片 URIs
<a name="debuger-built-in-registry-ids"></a>

使用以下值作为为 Amazon D SageMaker ebugger 提供内置规则的映像的注册表 URLs 组件。有关帐户 IDs，请参阅下表。

**ECR 存储库名称：** sagemaker-debugger-rules

**标签**：最新 

**完整注册表 URL 示例**：

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

按 AWS 区域划分 IDs 的内置规则容器镜像的账户


| Region | account\$1id | 
| --- | --- | 
| 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  | 

### URIs 适用于自定义规则评估者的 Amazon SageMaker 调试器图片
<a name="debuger-custom-rule-registry-ids"></a>

使用以下值作为为 Amazon D SageMaker ebugger 提供自定义规则评估器的图像的注册表 URL 的组成部分。有关帐户 IDs，请参阅下表。

**ECR 存储库名称：** sagemaker-debugger-rule-evaluator

**标签**：最新 

**完整注册表 URL 示例**：

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

按 AWS 区域划分 IDs 的自定义规则容器镜像账户


| Region | account\$1id | 
| --- | --- | 
| 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 调试器异常
<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 调试器支持的分布式训练
<a name="debugger-considerations"></a>

以下列表针对使用深度学习框架和各种分布式训练选项的训练作业，显示了 Debugger 的适用范围和注意事项。
+ **Horovod**

  对采用 Horovod 的训练作业的 Debugger 适用范围    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/debugger-reference.html)
+ **SageMaker AI 分布式数据 parallel**

  使用 Debugger 训练具有 SageMaker AI 分布式数据 parallel 的作业的有效范围    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/debugger-reference.html)

  \$1 调试器不支持 TensorFlow 2.x 的框架分析。

  \$1\$1 SageMaker 人工智能分布式数据 parallel 不支持采用 Keras 实现的 TensorFlow 2.x。
+ **SageMaker AI 分布式模型 paral** lel — Debugger 不支持 SageMaker AI 分布式模型并行训练。
+ **带有 SageMaker AI 检查点的分布式训**练 — 当同时启用分布式训练选项和 SageMaker AI 检查点时，调试器不可用于训练作业。您可能会看到如下所示的错误：

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

  要使用 Debugger 进行具有分布式训练选项的训练作业，您需要禁用 SageMaker AI 检查点功能，并在训练脚本中添加手动检查点功能。有关在带有检查点的分布式训练选项中使用 Debugger 的详细信息，请参阅[与 Amazon SageMaker 调试器和检查点并行使用 SageMaker 人工智能分布式数据](distributed-troubleshooting-data-parallel.md#distributed-ts-data-parallel-debugger)和[保存检查点](distributed-troubleshooting-model-parallel.md#distributed-ts-model-parallel-checkpoints)。
+ **参数服务器** – Debugger 不支持基于参数服务器的分布式训练。
+ 无法分析分布式训练框架的`AllReduced`操作，例如 SageMaker AI 分布式数据并行操作和 [Horovod 操作](https://horovod.readthedocs.io/en/stable/timeline_include.html)。