

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

# 推論管道的故障診斷
<a name="inference-pipeline-troubleshoot"></a>

若要進行推論管道問題的故障診斷，請使用 CloudWatch 日誌和錯誤訊息。如果您在包含 Amazon SageMaker AI 內建演算法的管道中使用自訂 Docker 映像檔，可能也會遇到許可問題。若要授予必要許可，請建立 Amazon Elastic Container Registry (Amazon ECR) 政策。

**Topics**
+ [推論管道 Amazon ECR 許可的疑難排解](#inference-pipeline-troubleshoot-permissions)
+ [使用 CloudWatch 日誌進行 SageMaker AI 推論管道的疑難排解](#inference-pipeline-troubleshoot-logs)
+ [使用錯誤訊息進行推論管道的故障診斷](#inference-pipeline-troubleshoot-errors)

## 推論管道 Amazon ECR 許可的疑難排解
<a name="inference-pipeline-troubleshoot-permissions"></a>

您在包含 [SageMaker AI 內建演算法](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-algo-docker-registry-paths.html)的管道中使用自訂 Docker 映像檔時，您需要 [Amazon ECR 政策](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html)。此政策可讓您的 Amazon ECR 儲存庫授與 SageMaker AI 提取映像的許可。此政策必須新增下列許可：

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "allowSageMakerToPull",
            "Effect": "Allow",
            "Principal": {
                "Service": "sagemaker.amazonaws.com"
            },
            "Action": [
                "ecr:GetDownloadUrlForLayer",
                "ecr:BatchGetImage",
                "ecr:BatchCheckLayerAvailability"
            ],
            "Resource": "*"
        }
    ]
}
```

------

## 使用 CloudWatch 日誌進行 SageMaker AI 推論管道的疑難排解
<a name="inference-pipeline-troubleshoot-logs"></a>

對於將推論管道部署到 Amazon CloudWatch 的端點，SageMaker AI 會在每個容器的以下路徑發佈端點的容器日誌。

```
/aws/sagemaker/Endpoints/{EndpointName}/{Variant}/{InstanceId}/{ContainerHostname}
```

例如，此端點的日誌會發佈到以下日誌群組和串流：

```
EndpointName: MyInferencePipelinesEndpoint
Variant: MyInferencePipelinesVariant
InstanceId: i-0179208609ff7e488
ContainerHostname: MyContainerName1 and MyContainerName2
```

```
logGroup: /aws/sagemaker/Endpoints/MyInferencePipelinesEndpoint
logStream: MyInferencePipelinesVariant/i-0179208609ff7e488/MyContainerName1
logStream: MyInferencePipelinesVariant/i-0179208609ff7e488/MyContainerName2
```

*日誌串流*是一系列共用相同來源的日誌事件。每個單獨日誌串流是由 CloudWatch 中的單獨日誌來源所組成。*日誌群組*是共用相同保留、監控和存取控制設定的日誌串流群組。

**查看日誌群組和串流**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽頁面中，選擇 **Logs (日誌)**。

1. 在 **Log Groups (日誌群組)** 中，依 **MyInferencePipelinesEndpoint** 篩選：  
![針對推論管道端點篩選的 CloudWatch 日誌群組。](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/pipeline-log-group-filter.png)

1. 若要查看日誌串流，請在 CloudWatch **日誌群組** 頁面選擇 **MyInferencePipelinesEndpoint**，然後選擇**搜尋日誌群組**。  
![推論管道的 CloudWatch 日誌串流。](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/pipeline-log-streams-2.png)

如需 SageMaker AI 發佈的日誌清單，請參閱[推論管道日誌和指標](inference-pipeline-logs-metrics.md)。

## 使用錯誤訊息進行推論管道的故障診斷
<a name="inference-pipeline-troubleshoot-errors"></a>

推論管道錯誤訊息指出哪些容器故障。

如果 SageMaker AI 調用端點時發生錯誤，服務會傳回 `ModelError` (錯誤碼 424)，指出哪個容器故障。如果請求承載 (來自前一個容器的回應) 超過 5 MB 的限制，SageMaker AI 會提供詳細的錯誤訊息，例如：

收到來自 MyContainerName1 的回應，狀態碼為 200。不過，從 MyContainerName1 到 MyContainerName2 的請求承載為 6000000 位元組，已超過最大限制 5 MB。

``

SageMaker AI 建立端點時，如果容器的 ping 運作狀態檢查失敗，則會傳回 `ClientError`，並指出上一次運作狀態檢查時未通過 ping 檢查的所有容器。