

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

# 使用 Amazon SageMaker 訓練模型
<a name="how-it-works-training"></a>

Amazon SageMaker 訓練是由 SageMaker 提供的全受管機器學習 (ML) 服務，可協助您有效地大規模訓練各種 ML 模型。SageMaker AI 任務的核心是 ML 工作負載的容器化和管理 AWS 運算資源的能力。SageMaker Training 平台負責處理與設定和管理 ML 訓練工作負載基礎架構相關的繁重工作。透過 SageMaker Training，您可以專注於開發、訓練和微調模型。此頁介紹在 SageMaker 上訓練模型的三種建議方法，後面還有您可以考慮的其他選項。

**提示**  
如需進一步了解如何為生成式 AI 訓練基礎模型，請參閱[在 Amazon SageMaker Studio 中使用 SageMaker JumpStart 基礎模型](https://docs.aws.amazon.com/sagemaker/latest/dg/jumpstart-foundation-models-use-studio-updated.html)。

## 在 Amazon SageMaker 訓練中選擇功能
<a name="choose-a-feature-of-sagemaker-training"></a>

在 SageMaker AI 中訓練 ML 模型有三個主要使用案例。本節說明這些使用案例，以及針對每個使用案例的建議 SageMaker AI 功能。

無論您要訓練複雜的深度學習模型或實作較小型的機器學習演算法，SageMaker 訓練都能提供簡化且符合成本效益的解決方案，以符合您的使用案例需求。

### 使用案例
<a name="choose-use-cases-sagemaker-training"></a>

以下是在 SageMaker AI 中訓練 ML 模型的主要使用案例。
+ **使用案例 1**：在低程式碼或無程式碼環境中開發機器學習模型。
+ **使用案例 2**：使用程式碼來開發更具彈性和控制度的機器學習模型。
+ **使用案例 3**：以最大彈性和控制度大規模地開發機器學習模型。

### 推薦功能
<a name="choose-recommended-features-of-sagemaker-training"></a>

下表說明訓練 ML 模型的三個常見案例，以及開始使用 SageMaker 訓練的相應選項。


| 描述項 | 使用案例 1 | 使用案例 2 | 使用案例 3 | 
| --- | --- | --- | --- | 
| SageMaker AI 功能 | [使用 Amazon SageMaker Canvas 建置模型](https://docs.aws.amazon.com/sagemaker/latest/dg/canvas-build-model.html)。 | 使用其中一個 [SageMaker AI 內建 ML 演算法](https://docs.aws.amazon.com/sagemaker/latest/dg/algos.html)訓練模型，例如 [XGBoost](https://docs.aws.amazon.com/sagemaker/latest/dg/xgboost.html#xgboost-modes) 或 [任務特定的 SageMaker JumpStart 模型](https://docs.aws.amazon.com/sagemaker/latest/dg/jumpstart-models.html)，並搭配使用 SageMaker Python SDK。 | 利用 SageMaker AI 中的[指令碼模式](https://sagemaker-examples.readthedocs.io/en/latest/sagemaker-script-mode/sagemaker-script-mode.html)或[自訂容器](https://docs.aws.amazon.com/sagemaker/latest/dg/docker-containers-adapt-your-own.html)，以最大的彈性大規模訓練模型。 | 
| Description | 使用您的資料。SageMaker AI 能協助您管理建置 ML 模型和設定訓練基礎架構和資源。 |  使用您的資料並選擇 SageMaker AI 提供的內建 ML 演算法。使用 SageMaker Python SDK 來設定模型超參數、輸出指標和基本基礎架構設定。SageMaker 訓練平台可協助您佈建訓練基礎架構和資源。  |  開發您自有的 ML 程式碼，並將其作為 (一組) 指令碼用於 SageMaker AI。若要進一步了解，請參閱 [SageMaker 分散式運算最佳實務](https://docs.aws.amazon.com/sagemaker/latest/dg/distributed-training-options.html#distributed-training-options-2)。此外，您可以[使用自己的 Docker 容器](https://docs.aws.amazon.com/sagemaker/latest/dg/adapt-training-container.html#byoc-training-step2)。SageMaker 訓練平台會根據您的自訂設定，協助您大規模地佈建訓練基礎架構和資源。  | 
| 最佳化 |  低/無程式碼和 UI 驅動的模型開發，搭配訓練資料集的快速實驗。當您[建置自訂模型](canvas-build-model.md)時，演算法會根據您的資料自動選取。如需演算法選擇等進階自訂選項，請參閱[進階模型建置組態](canvas-advanced-settings.md)。  |  針對超參數、基礎架構設定，透過高階自訂訓練 ML 模型，以直接使用 ML 架構和進入點指令碼來提高靈活性。透過 [Amazon SageMaker Python SDK](https://sagemaker.readthedocs.io/en/stable)，使用內建演算法、預先訓練的模型和 JumpStart 模型來開發 ML 模型。如需詳細資訊，請參閱[使用 JumpStart 類別進行低程式碼部署](https://sagemaker.readthedocs.io/en/stable/overview.html#low-code-deployment-with-the-jumpstartmodel-class)。  |  ML 大規模訓練工作負載，需要多個執行個體和最大的彈性。請參閱 [SageMaker 分散式運算最佳實務](distributed-training-options.md)。SageMaker AI 使用 Docker 映像來託管所有模型的訓練和服務。您可以使用任何 SageMaker AI 或外部演算法，並[使用 Docker 容器來建置模型](docker-containers.md)。  | 
| 考量事項 |  自訂 Amazon SageMaker Canvas 提供的模型所需的最小彈性。  |  相較於低階 SageMaker Training API，SageMaker Python SDK 提供更簡化的介面和較少組態選項。  |  需要基礎設施 AWS 和分散式訓練選項的知識。另請參閱 [使用 SageMaker 工具組](https://docs.aws.amazon.com/sagemaker/latest/dg/amazon-sagemaker-toolkits.html)[建立自有訓練容器](https://docs.aws.amazon.com/sagemaker/latest/dg/your-algorithms-training-algo.html)。  | 
| 建議的環境 | 使用 [Amazon SageMaker Canvas](https://docs.aws.amazon.com/sagemaker/latest/dg/canvas-getting-started.html#canvas-prerequisites)。若要了解如何設定，請參閱[SageMaker Canvas 使用入門](https://docs.aws.amazon.com/sagemaker/latest/dg/canvas-getting-started.html)。 | 在 [Amazon SageMaker Studio](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-updated-launch.html) 中使用 [SageMaker AI JupyterLab](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-updated-jl.html)。若要了解如何設定，請參閱[啟動 Amazon SageMaker Studio](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-updated-launch.html)。 | 在 [Amazon SageMaker Studio](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-updated-launch.html) 中使用 [SageMaker JupyterLab](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-updated-jl.html)。若要了解如何設定，請參閱[啟動 Amazon SageMaker Studio](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-updated-launch.html)。 | 

## 其他選項
<a name="choose-additional-options-for-sagemaker-training"></a>

SageMaker AI 提供下列額外選項來訓練 ML 模型。

**提供訓練功能的 SageMaker AI 功能**
+ **[SageMaker JumpStart](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-jumpstart.html)**：SageMaker JumpStart 提供對 SageMaker AI 公開可用模型中樞的存取權，該中樞包含最新公開和專屬的基礎模型 (FM)。您可以在 Amazon SageMaker Studio 中微調、評估和部署這些模型。SageMaker JumpStart 會簡化您生成式 AI 使用案例利用基礎模型的程序，可讓您建立私有模型中樞來使用基礎模型，同時強制控管防護機制，並確保貴組織只能存取核准的模型。若要開始使用 SageMaker JumpStart，請參閱 [SageMaker JumpStart 基礎模型](https://docs.aws.amazon.com/sagemaker/latest/dg/jumpstart-foundation-models.html)。
+ **[SageMaker HyperPod](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-hyperpod.html)**：SageMaker HyperPod 是一種持久性叢集服務，適用於需要彈性叢集來處理大量機器學習 (ML) 工作負載和開發最新基礎模型 (FM) 的使用案例。它透過移除在建置和維護採用 AWS Trainium 或 NVIDIA A100 和 H100 圖形處理器 (GPUs) 等數千個加速器的大規模運算叢集時所涉及的無差異繁重提升，加速此類模型的開發。您可以使用工作負載管理工具軟體，例如 HyperPod 上的 Slurm。

**SageMaker 訓練的更多功能**
+ **[超參數調校](https://docs.aws.amazon.com/sagemaker/latest/dg/automatic-model-tuning.html)**：此 SageMaker AI 功能有助於為模型定義一組超參數，並在資料集上啟動多個訓練任務。根據超參數值，模型訓練效能可能有所不同。此功能可在您設定的超參數搜尋範圍內，提供最佳效能的超參數集。
+ **[分散式訓練](https://docs.aws.amazon.com/sagemaker/latest/dg/distributed-training.html)**：使用 PyTorch、NVIDIA CUDA 和其他 PyTorch 架構來建置的預先訓練或微調 FM。若要有效利用 GPU 執行個體，請使用 SageMaker AI 分散式訓練程式庫，該程式庫提供集體通訊操作和多種模型平行化技術，例如針對 AWS 基礎架構最佳化的專家平行處理和共用資料平行處理。
+ **可觀測性功能**：使用 SageMaker 訓練的分析和偵錯功能，深入了解模型訓練工作負載、模型效能和資源使用率。若要進一步了解，請參閱[偵錯並改善模型效能](https://docs.aws.amazon.com/sagemaker/latest/dg/train-debug-and-improve-model-performance.html)和[剖析和最佳化運算效能](https://docs.aws.amazon.com/sagemaker/latest/dg/train-profile-computational-performance.html)。
+ **節省成本且有效的執行個體選項**：若要最佳化訓練執行個體佈建的運算成本和效率，請使用[異質叢集](https://docs.aws.amazon.com/sagemaker/latest/dg/train-heterogeneous-cluster.html)、[受管 Spot 執行個體](https://docs.aws.amazon.com/sagemaker/latest/dg/model-managed-spot-training.html)或[受管暖集區](https://docs.aws.amazon.com/sagemaker/latest/dg/train-warm-pools.html)。