

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

# 故障診斷 Inference Recommender 錯誤
<a name="inference-recommender-troubleshooting"></a>

本節包含如何了解並防止常見錯誤、其所產生錯誤訊息的資訊，以及如何解決這些錯誤的指導方針。

## 如何故障診斷
<a name="inference-recommender-troubleshooting-how-to"></a>

您可以透過執行以下步驟嘗試解決錯誤：
+ 檢查您是否已涵蓋使用 Inference Recommender 的所有先決條件。請參閱 [Inference Recommender 先決條件](https://docs.aws.amazon.com/sagemaker/latest/dg/inference-recommender-prerequisites.html)。
+ 檢查您是否能夠將模型從模型註冊表部署到端點，並且可毫無錯誤地處理您的承載。請參閱[從註冊表部署模型](https://docs.aws.amazon.com/sagemaker/latest/dg/model-registry-deploy.html)。
+ 當您開始執行 Inference Recommender 任務時，您應該會看到在主控台中建立的端點，而且也可以檢閱 CloudWatch 記錄。

## 常見錯誤
<a name="inference-recommender-troubleshooting-common"></a>

請參閱下表，了解常見的 Inference Recommender 錯誤及其解決方案。


| 錯誤 | 解決方案 | 
| --- | --- | 
|  在模型套件版本 1 中指定 `Domain`。`Domain` 是任務的必要參數。  |  確保您提供機器學習 (ML) 網域或者在未知的情況下提供 `OTHER`。  | 
|  無法假設提供的角色 ARN 並發生 `AWSSecurityTokenServiceException` 錯誤。  |  請確定提供的執行角色具有先決條件中指定的必要許可。  | 
|  在模型套件版本 1 中指定 `Framework`。`Framework` 是任務的必要參數。  |  確保您提供機器學習 (ML) 架構或者在未知的情況下提供 `OTHER`。  | 
|  上一階段結束時的使用者為 0，而目前階段的初始使用者為 1。  |  此處的使用者指的是用來傳送請求的虛擬使用者或執行緒。每個階段都以 A 使用者開始，並以 B 使用者結束，以便 B > A. 在循序階段 x\$11 和 x\$12 之間，我們會要求 abs(x\$12.A - x\$11.B) <= 3 且 >= 0。  | 
|  總流量持續時間 (跨階段) 不應超過任務持續時間。  |  所有階段的總持續時間不能超過任務持續時間。  | 
|  不允許高載執行個體類型 ml.t2.medium。  |  Inference Recommender 不支援 t2 執行個體系列上的負載測試，因為高載執行個體無法提供一致的效能。  | 
|  呼叫 CreateEndpoint 操作時使用 ResourceLimitExceeded  |  您已超過 SageMaker AI 資源限制。例如，如果帳戶已達到端點配額，Inference Recommender 可能無法佈建端點以進行基準測試。如需 SageMaker AI 限制和配額的參考資訊，請參閱 [Amazon SageMaker AI 端點與配額](https://docs.aws.amazon.com/general/latest/gr/sagemaker.html)。  | 
|  呼叫 InvokeEndpoint 操作時出現 ModelError  |  模型錯誤可能是由於下列原因所發生： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/inference-recommender-troubleshooting.html)  | 
|  呼叫 InvokeEndpoint 操作時出現 PayloadError  |  承載錯誤可能是由於下列原因所發生： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/inference-recommender-troubleshooting.html)  | 

## 檢查 CloudWatch
<a name="inference-recommender-troubleshooting-check-cw"></a>

當您開始執行 Inference Recommender 任務時，您應該會看到主控台正在建立端點。選取其中一個端點並檢視 CloudWatch 日誌，以監控是否有任何 4xx/5xx 錯誤。如果您有成功的 Inference Recommender 任務，您將能夠看到端點名稱作為結果的一部分。即使您的 Inference Recommender 任務失敗，您仍然可以按照以下步驟檢查已刪除端點的 CloudWatch 日誌：

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

1. 從右上角的**區域**下拉式清單中，選取您在其中建立 Inference Recommender 任務的區域。

1. 在 CloudWatch 導覽窗格中，選擇**日誌**，然後選擇**日誌群組**。

1. 搜尋名為 `/aws/sagemaker/Endpoints/sm-epc-*` 的日誌群組。根據您最近的 Inference Recommender 任務選取日誌群組。

您也可以檢查 Inference Recommender CloudWatch 日誌，對任務進行故障診斷。在 `/aws/sagemaker/InferenceRecommendationsJobs` CloudWatch 日誌群組中發佈的 Inference Recommender 日誌，可提供 `<jobName>/execution` 日誌串流中任務進度的高階檢視。您可以在 `<jobName>/Endpoint/<endpointName>` 日誌串流中找到有關正在測試的每個端點組態之詳情。

**Inference Recommender 日誌串流概觀**
+ `<jobName>/execution` 包含整體任務資訊，例如針對基準測試排程的端點組態、編譯任務略過原因，以及驗證失敗原因。
+ `<jobName>/Endpoint/<endpointName>` 包含資源建立進度、測試組態、載入測試停止原因和資源清理狀態等資訊。
+ `<jobName>/CompilationJob/<compilationJobName>` 包含 Inference Recommender 所建立之編譯任務的相關資訊，例如編譯任務組態和編譯任務狀態。

**建立 Inference Recommender 錯誤訊息的警示**

Inference Recommender 會針對故障診斷時可能有幫助的錯誤輸出日誌陳述式。借助CloudWatch 日誌群組，您可在要傳送至 CloudWatch 的此份日誌資料中尋找詞彙和模式。然後，您可以根據日誌群組指標篩選條件建立 CloudWatch 警示。如需詳情，請參閱[根據日誌群組指標篩選條件建立 CloudWatch 警示](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Create_alarm_log_group_metric_filter.html)。

## 檢查基準
<a name="inference-recommender-troubleshooting-check-benchmarks"></a>

當您開始執行 Inference Recommender 任務時，Inference Recommender 會建立數個基準測試，以評估模型在不同執行個體類型上的效能。您可以使用 [ListInferenceRecommendationsJobSteps](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ListInferenceRecommendationsJobSteps.html) API 來檢視所有基準測試的詳細資料。如果您有一個失敗的基準測試，您可以看到失敗原因作為結果的一部分。

若要使用 [ListInferenceRecommendationsJobSteps](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ListInferenceRecommendationsJobSteps.html) API，請提供下列值：
+ 對於 `JobName`，提供 Inference Recommender 任務的名稱。
+ 對於 `StepType`，使用 `BENCHMARK` 傳回有關任務基準測試的詳細資訊。
+ 對於 `Status`，使用 `FAILED` 僅傳回失敗基準測試的詳細資訊。如需其他狀態類型的清單，請參閱 [ListInferenceRecommendationsJobSteps](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ListInferenceRecommendationsJobSteps.html) API 中的 `Status` 欄位。

```
# Create a low-level SageMaker service client.
import boto3
aws_region = '<region>'
sagemaker_client = boto3.client('sagemaker', region_name=aws_region) 

# Provide the job name for the SageMaker Inference Recommender job
job_name = '<job-name>'

# Filter for benchmarks
step_type = 'BENCHMARK' 

# Filter for benchmarks that have a FAILED status
status = 'FAILED'

response = sagemaker_client.list_inference_recommendations_job_steps(
    JobName = job_name,
    StepType = step_type,
    Status = status
)
```

您可以列印回應物件以檢視結果。前面的程式碼範例將回應儲存在一個名為 `response` 的變數：

```
print(response)
```