

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

# 內建演算法的參數
<a name="common-info-all-im-models"></a>

下表會列出 Amazon SageMaker AI 所提供的每種演算法的參數。


| 演算法名稱 | 頻道名稱 | 訓練輸入模式 | 檔案類型 | 執行個體類別 | 可平行化 | 
| --- | --- | --- | --- | --- | --- | 
| AutoGluon - 自列表格 | 訓練和 (選擇性) 驗證 | 檔案 | CSV | GPU 或 CPU (限單一執行個體) | 否 | 
| BlazingText | 訓練 | 檔案或管道 | 文字檔 (一行一個句子，使用空格分隔權杖)  | GPU 或 CPU (限單一執行個體)  | 否 | 
| CatBoost | 訓練和 (選擇性) 驗證 | 檔案 | CSV | CPU (限單一執行個體) | 否 | 
| DeepAR 預測 | 訓練和 (選擇性) 測試 | 檔案 | JSON Lines 或 Parquet | CPU 或 GPU | 是 | 
| 分解機 | 訓練和 (選擇性) 測試 | 檔案或管道 | recordIO-protobuf | CPU (密集資料則 GPU) | 是 | 
| 影像分類 - MXNet | 訓練和驗證、(選擇性) train\$1lst、validation\$1lst 和模型 | 檔案或管道 | recordIO 或圖片檔 (.jpg 或 .png)  | GPU | 是 | 
| 影像分類 - TensorFlow | 訓練與驗證 | 檔案 | 影像檔案 (.jpg、.jpeg 或 .png)  | CPU 或 GPU | 是 (僅適用於單一執行個體上的多個 GPU) | 
| IP 深入分析 | 訓練和 (選擇性) 驗證 | 檔案 | CSV | CPU 或 GPU | 是 | 
| K 平均數 | 訓練和 (選擇性) 測試 | 檔案或管道 | recordIO-protobuf 或 CSV | CPU 或 GPUCommon (在一或多個執行個體上的單一 GPU 裝置) | 否 | 
| K-Nearest-Neighbors (k-NN) | 訓練和 (選擇性) 測試 | 檔案或管道 | recordIO-protobuf 或 CSV | CPU 或 GPU (在一或多個執行個體上的單一 GPU 裝置) | 是 | 
| LDA | 訓練和 (選擇性) 測試 | 檔案或管道 | recordIO-protobuf 或 CSV | CPU (限單一執行個體) | 否 | 
| LightGBM | 訓練和 (選擇性) 驗證 | 檔案 | CSV | CPU | 是 | 
| 線性學習程式 | 訓練和 (選擇性) 驗證、測試，或兩者兼具 | 檔案或管道 | recordIO-protobuf 或 CSV | CPU 或 GPU | 是 | 
| 神經主題模型 | 訓練和 (選擇性) 驗證、測試，或兩者兼具 | 檔案或管道 | recordIO-protobuf 或 CSV | CPU 或 GPU | 是 | 
| Object2Vec | 訓練和 (選擇性) 驗證、測試，或兩者兼具 | 檔案 | JSON 行  | GPU 或 CPU (限單一執行個體) | 否 | 
| 物件偵測 - MXNet | 訓練和驗證、(選擇性) train\$1annotation、validation\$1annotation 和模型 | 檔案或管道 | recordIO 或圖片檔 (.jpg 或 .png)  | GPU | 是 | 
| 物體偵測 - TensorFlow | 訓練與驗證 | 檔案 | 影像檔案 (.jpg、.jpeg 或 .png)  | GPU | 是 (僅適用於單一執行個體上的多個 GPU) | 
| PCA | 訓練和 (選擇性) 測試 | 檔案或管道 | recordIO-protobuf 或 CSV | CPU 或 GPU | 是 | 
| Random Cut Forest (隨機分割森林) | 訓練和 (選擇性) 測試 | 檔案或管道 | recordIO-protobuf 或 CSV | CPU | 是 | 
| 語義分段 | 訓練和驗證、train\$1annotation、validation\$1annotation 和 (選擇性) label\$1map 與模型 | 檔案或管道 | 影像檔 | GPU (限單一執行個體) | 否 | 
| Seq2Seq Modeling | 訓練、驗證、詞彙 | 檔案 | recordIO-protobuf | GPU (限單一執行個體) | 否 | 
| TabTransformer | 訓練和 (選擇性) 驗證 | 檔案 | CSV | GPU 或 CPU (限單一執行個體) | 否 | 
| 文字分類 - TensorFlow | 訓練與驗證 | 檔案 | CSV | CPU 或 GPU | 是 (僅適用於單一執行個體上的多個 GPU) | 
| XGBoost (0.90-1, 0.90-2, 1.0-1, 1.2-1, 1.2-21) | 訓練和 (選擇性) 驗證 | 檔案或管道 | CSV、LibSVM 或 Parquet | CPU (或適用於 1.2-1 的 GPU) | 是 | 

可以將*可平行化*的演算法部署在多個運算執行個體來進行分散式訓練。

下列主題提供資料格式、建議的 Amazon EC2 執行個體類型，以及 Amazon SageMaker AI 所提供之所有內建演算法通用的 CloudWatch 日誌等相關資訊。

**注意**  
若要查詢 SageMaker AI 管理之內建演算法的 Docker 映像檔 URI，請參閱 [Docker 登錄檔路徑和範例程式碼](https://docs.aws.amazon.com/sagemaker/latest/dg-ecr-paths/sagemaker-algo-docker-registry-paths)。

**Topics**
+ [用於訓練的一般資料格式](cdf-training.md)
+ [推論的一般資料格式](cdf-inference.md)
+ [內建演算法的執行個體類型](cmn-info-instance-types.md)
+ [內建演算法的日誌](common-info-all-sagemaker-models-logs.md)

# 用於訓練的一般資料格式
<a name="cdf-training"></a>

若要準備訓練，您可以使用各種 AWS 服務預先處理資料，包括 Amazon EMR AWS Glue、Amazon Redshift、Amazon Relational Database Service 和 Amazon Athena。預先處理完畢後，請將資料發佈到 Amazon S3 儲存貯體上。為了進行訓練，資料必須先經過一系列轉換和轉變的過程，例如：
+ 訓練資料序列化 (由您處理) 
+ 訓練資料還原序列化 (由演算法處理) 
+ 訓練模型序列化 (由演算法處理) 
+ 訓練模型還原序列化 (選擇性，由您處理) 

在演算法的訓練部分使用 Amazon SageMaker AI 時，請務必一次上傳所有資料。若該位置新增了更多資料，則需進行新的訓練呼叫，以建立全新的模型。

**Topics**
+ [內建演算法支援的內容類型](#cdf-common-content-types)
+ [使用樞紐分析模式](#cdf-pipe-mode)
+ [使用 CSV 格式](#cdf-csv-format)
+ [使用 RecordIO 格式](#cdf-recordio-format)
+ [訓練模型還原序列化](#td-deserialization)

## 內建演算法支援的內容類型
<a name="cdf-common-content-types"></a>

下表列出了一些常見支援的[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_Channel.html#SageMaker-Type-Channel-ContentType](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_Channel.html#SageMaker-Type-Channel-ContentType)值以及使用它們的算法：

內建演算法的類型


| ContentType | 演算法 | 
| --- | --- | 
| 應用程式/x - 影像 | 物件偵測演算法、語意分割 | 
| 應用程式/X - 錄音 |  物件偵測演算法  | 
| application/x-recordio-protobuf |  因式分解機, K 平均數, k-NN, Latent Dirichlet Allocation, 線性學習, NTM, PCA, RCF, Sequence-to-Sequence  | 
| application/jsonlines |  BlazingText, DeepAR  | 
| 影像/JPEG |  物件偵測演算法、語意分割  | 
| 圖片/png |  物件偵測演算法、語意分割  | 
| text/csv |  IP Insights, K 平均數, k-NN, Latent Dirichlet Allocation, 線性學習, NTM, PCA, RCF, XGBoost  | 
| 文字/libsvm |  XGBoost  | 

如需每個演算法使用的參數摘要，請參閱文件或此[資料表](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-algo-docker-registry-paths.html)以取得個別演算法的資訊。

## 使用樞紐分析模式
<a name="cdf-pipe-mode"></a>

在*管道模式下*，您的訓練任務會直接從 Amazon Simple Storage Service (Amazon S3) 串流資料。串流可以為訓練任務提供更快的啟動時間和更高的輸送量。這與*檔案模式*相反，Amazon S3 中的資料會存放在訓練執行個體磁碟區上。檔案模式則使用存放最終模型成品和完整訓練資料集的磁碟空間。透過以管道模式直接從 Amazon S3 串流資料，您可以減少訓練執行個體的 Amazon 彈性區塊存放區容量大小。管道模式僅需足夠磁碟空間來存放您的最終模型成品。請參閱 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_AlgorithmSpecification.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_AlgorithmSpecification.html)以取得訓練輸入模式的詳細資訊。

## 使用 CSV 格式
<a name="cdf-csv-format"></a>

許多 Amazon SageMaker AI 演算法能以 CSV 格式的資料支援訓練。若要使用 CSV 格式的資料進行訓練，請在輸入資料通道規格中指定**text/csv**為 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_Channel.html#SageMaker-Type-Channel-ContentType](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_Channel.html#SageMaker-Type-Channel-ContentType)。Amazon SageMaker AI 要求 CSV 檔案沒有標題記錄，且目標變數位於第一欄中。若要執行不具有目標的無監督學習演算法，請指定內容類型中標籤欄的數目。例如，在此案例中為 **'content\$1type=text/csv;label\$1size=0'**。有關詳細資訊，請參閱[現在，將管道模式與 CSV 資料集結合使用，以便更快地對 Amazon SageMaker AI 內建演算法進行訓練](https://aws.amazon.com/blogs/machine-learning/now-use-pipe-mode-with-csv-datasets-for-faster-training-on-amazon-sagemaker-built-in-algorithms/)。

## 使用 RecordIO 格式
<a name="cdf-recordio-format"></a>

在 protobuf recordIO 格式中，SageMaker AI 會將資料集的每項觀察都轉換為二進位表示法，成為一組 4 個位元組的浮點，再將其載入 protobuf 值欄位。如果您使用 Python 來準備資料，強烈建議您使用這些現有的轉換。不過，如果您使用其他語言，下列 protobuf 定義檔提供您用於將資料轉換為 SageMaker AI protobuf 格式的結構描述。

**注意**  
如需說明如何將常用 numPy 陣列轉換為 protobuf recordIO 格式的範例，請參閱*[入門指南：因式分解機搭配使用 MNIST](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/factorization_machines_mnist/factorization_machines_mnist.html)*。

```
syntax = "proto2";

 package aialgs.data;

 option java_package = "com.amazonaws.aialgorithms.proto";
 option java_outer_classname = "RecordProtos";

 // A sparse or dense rank-R tensor that stores data as doubles (float64).
 message Float32Tensor   {
     // Each value in the vector. If keys is empty, this is treated as a
     // dense vector.
     repeated float values = 1 [packed = true];

     // If key is not empty, the vector is treated as sparse, with
     // each key specifying the location of the value in the sparse vector.
     repeated uint64 keys = 2 [packed = true];

     // An optional shape that allows the vector to represent a matrix.
     // For example, if shape = [ 10, 20 ], floor(keys[i] / 20) gives the row,
     // and keys[i] % 20 gives the column.
     // This also supports n-dimensonal tensors.
     // Note: If the tensor is sparse, you must specify this value.
     repeated uint64 shape = 3 [packed = true];
 }

 // A sparse or dense rank-R tensor that stores data as doubles (float64).
 message Float64Tensor {
     // Each value in the vector. If keys is empty, this is treated as a
     // dense vector.
     repeated double values = 1 [packed = true];

     // If this is not empty, the vector is treated as sparse, with
     // each key specifying the location of the value in the sparse vector.
     repeated uint64 keys = 2 [packed = true];

     // An optional shape that allows the vector to represent a matrix.
     // For example, if shape = [ 10, 20 ], floor(keys[i] / 10) gives the row,
     // and keys[i] % 20 gives the column.
     // This also supports n-dimensonal tensors.
     // Note: If the tensor is sparse, you must specify this value.
     repeated uint64 shape = 3 [packed = true];
 }

 // A sparse or dense rank-R tensor that stores data as 32-bit ints (int32).
 message Int32Tensor {
     // Each value in the vector. If keys is empty, this is treated as a
     // dense vector.
     repeated int32 values = 1 [packed = true];

     // If this is not empty, the vector is treated as sparse with
     // each key specifying the location of the value in the sparse vector.
     repeated uint64 keys = 2 [packed = true];

     // An optional shape that allows the vector to represent a matrix.
     // For Exmple, if shape = [ 10, 20 ], floor(keys[i] / 10) gives the row,
     // and keys[i] % 20 gives the column.
     // This also supports n-dimensonal tensors.
     // Note: If the tensor is sparse, you must specify this value.
     repeated uint64 shape = 3 [packed = true];
 }

 // Support for storing binary data for parsing in other ways (such as JPEG/etc).
 // This is an example of another type of value and may not immediately be supported.
 message Bytes {
     repeated bytes value = 1;

     // If the content type of the data is known, stores it.
     // This allows for the possibility of using decoders for common formats
     // in the future.
     optional string content_type = 2;
 }

 message Value {
     oneof value {
         // The numbering assumes the possible use of:
         // - float16, float128
         // - int8, int16, int32
         Float32Tensor float32_tensor = 2;
         Float64Tensor float64_tensor = 3;
         Int32Tensor int32_tensor = 7;
         Bytes bytes = 9;
     }
 }

 message Record {
     // Map from the name of the feature to the value.
     //
     // For vectors and libsvm-like datasets,
     // a single feature with the name `values`
     // should be specified.
     map<string, Value> features = 1;

     // An optional set of labels for this record.
     // Similar to the features field above, the key used for
     // generic scalar / vector labels should be 'values'.
     map<string, Value> label = 2;

     // A unique identifier for this record in the dataset.
     //
     // Whilst not necessary, this allows better
     // debugging where there are data issues.
     //
     // This is not used by the algorithm directly.
     optional string uid = 3;

     // Textual metadata describing the record.
     //
     // This may include JSON-serialized information
     // about the source of the record.
     //
     // This is not used by the algorithm directly.
     optional string metadata = 4;

     // An optional serialized JSON object that allows per-record
     // hyper-parameters/configuration/other information to be set.
     //
     // The meaning/interpretation of this field is defined by
     // the algorithm author and may not be supported.
     //
     // This is used to pass additional inference configuration
     // when batch inference is used (e.g. types of scores to return).
     optional string configuration = 5;
 }
```

建立協定緩衝區後，請將其存放在 Amazon SageMaker AI 可存取的 Amazon S3 位置，並且可做為 `create_training_job` 中的 `InputDataConfig` 的部分來傳遞。

**注意**  
針對所有 Amazon SageMaker AI 演算法，`InputDataConfig` 的 `ChannelName` 必須設定為 `train`。部分演算法也支援驗證或測試 `input channels`。這些通常會透過使用鑑效組來評估模型的效能。鑑效組不會用於初始訓練，但可用來進一步微調模型。

## 訓練模型還原序列化
<a name="td-deserialization"></a>

Amazon SageMaker AI 模型會以 model.tar.gz 格式存放在 `create_training_job` 呼叫之 `OutputDataConfig` `S3OutputPath` 參數所指定的 S3 儲存貯體內。S3 儲存貯體必須與筆記本執行個體位於相同的 AWS 區域。建立託管模型時，這類模型成品大多可以指定。也可以在您筆記本執行個體中開啟和檢視。當 `model.tar.gz` 解壓縮後，其含有序列化的 Apache MXNet 物件 `model_algo-1`。舉例而言，您可以如下所示，將 K 平均數模型載入記憶體內並加以檢視：

```
import mxnet as mx
print(mx.ndarray.load('model_algo-1'))
```

# 推論的一般資料格式
<a name="cdf-inference"></a>

Amazon SageMaker AI 演算法可接受和產生多種不同的 http 承載的 MIME 類型，用於擷取線上和迷你批次的預測。您可以使用多個 AWS 服務在執行推論之前轉換或預先處理記錄。至少需要為以下各項轉換資料：
+ 推論請求序列化 (由您處理) 
+ 推論請求還原序列化 (由演算法處理) 
+ 推論回應序列化 (由演算法處理) 
+ 推論回應還原序列化 (由您處理) 

**Topics**
+ [針對推論請求序列化轉換資料](#ir-serialization)
+ [針對推論回應還原序列化轉換資料](#ir-deserialization)
+ [適用於所有演算法的一般請求格式](#common-in-formats)
+ [使用含內建演算法的批次轉換](#cm-batch)

## 針對推論請求序列化轉換資料
<a name="ir-serialization"></a>

Amazon SageMaker AI 演算法推論請求的內容類型選項包括：`text/csv`，`application/json`，和 `application/x-recordio-protobuf`。不支援所有這些類型的演算法可以支援其他類型。例如，XGBoost 僅支援此清單中的 `text/csv`，但也支援 `text/libsvm`。

對 `text/csv` 而言，至 `invoke_endpoint` 的 Body 引數值應是由逗號將各功能值分隔開的字串。舉例而言，含有四個功能的模型的記錄可能看起來會是：`1.5,16.0,14,23.0`。在訓練資料上進行的任何轉換作業，在取得推論前，也應在資料上執行。功能的順序有其重要性，必須維持不變。

`application/json` 更加靈活，為開發人員提供了多種可能的格式，可使用在應用程式中。在高階流程中，JavaScript 內的承載看起來可能會如下列所示：

```
let request = {
  // Instances might contain multiple rows that predictions are sought for.
  "instances": [
    {
      // Request and algorithm specific inference parameters.
      "configuration": {},
      // Data in the specific format required by the algorithm.
      "data": {
         "<field name>": dataElement
       }
    }
  ]
}
```

您有以下選項可供指定 `dataElement`：

**協定緩衝區相等**

```
// Has the same format as the protocol buffers implementation described for training.
let dataElement = {
  "keys": [],
  "values": [],
  "shape": []
}
```

**簡單數字向量**

```
// An array containing numeric values is treated as an instance containing a
// single dense vector.
let dataElement = [1.5, 16.0, 14.0, 23.0]

// It will be converted to the following representation by the SDK.
let converted = {
  "features": {
    "values": dataElement
  }
}
```

**多重記錄**

```
let request = {
  "instances": [
    // First instance.
    {
      "features": [ 1.5, 16.0, 14.0, 23.0 ]
    },
    // Second instance.
    {
      "features": [ -2.0, 100.2, 15.2, 9.2 ]
    }
  ]
}
```

## 針對推論回應還原序列化轉換資料
<a name="ir-deserialization"></a>

Amazon SageMaker AI 演算法會以多種配置傳回 JSON。高階流程內的結構為：

```
let response = {
  "predictions": [{
    // Fields in the response object are defined on a per algorithm-basis.
  }]
}
```

預測中所包含的欄位會因演算法而各有不同。以下範例為 K 平均數演算法的輸出結果。

**單一記錄推論** 

```
let response = {
  "predictions": [{
    "closest_cluster": 5,
    "distance_to_cluster": 36.5
  }]
}
```

**多重記錄推論**

```
let response = {
  "predictions": [
    // First instance prediction.
    {
      "closest_cluster": 5,
      "distance_to_cluster": 36.5
    },
    // Second instance prediction.
    {
      "closest_cluster": 2,
      "distance_to_cluster": 90.3
    }
  ]
}
```

**多重記錄推論 (含 protobuf 輸入)**

```
{
  "features": [],
  "label": {
    "closest_cluster": {
      "values": [ 5.0 ] // e.g. the closest centroid/cluster was 1.0
    },
    "distance_to_cluster": {
      "values": [ 36.5 ]
    }
  },
  "uid": "abc123",
  "metadata": "{ "created_at": '2017-06-03' }"
}
```

SageMaker AI 演算法也支援 JSONLINES 格式，其中每項記錄回應內容與 JSON 格式相同。多記錄結構是每項記錄回應物件的集合，以換行字元分隔。用於 2 輸入資料點之內建 KMeans 演算法的回應內容為：

```
{"distance_to_cluster": 23.40593910217285, "closest_cluster": 0.0}
{"distance_to_cluster": 27.250282287597656, "closest_cluster": 0.0}
```

執行批次轉換時，建議您將 `CreateTransformJobRequest` 的 `Accept` 欄位設定為 `application/jsonlines`，以使用 `jsonlines` 回應類型。

## 適用於所有演算法的一般請求格式
<a name="common-in-formats"></a>

大多數演算法會使用以下多種推論請求格式。

### JSON 請求格式
<a name="cm-json"></a>

**內容類型：** 應用程式/JSON

**密集格式**

```
let request =   {
    "instances":    [
        {
            "features": [1.5, 16.0, 14.0, 23.0]
        }
    ]
}


let request =   {
    "instances":    [
        {
            "data": {
                "features": {
                    "values": [ 1.5, 16.0, 14.0, 23.0]
                }
            }
        }
    ]
}
```

**稀疏格式**

```
{
	"instances": [
		{"data": {"features": {
					"keys": [26, 182, 232, 243, 431],
					"shape": [2000],
					"values": [1, 1, 1, 4, 1]
				}
			}
		},
		{"data": {"features": {
					"keys": [0, 182, 232, 243, 431],
					"shape": [2000],
					"values": [13, 1, 1, 4, 1]
				}
			}
		},
	]
}
```

### JSONLINES 請求格式
<a name="cm-jsonlines"></a>

**內容類型：**應用程式/JSONLINES

**密集格式**

密集格式的單一記錄可以表示為：

```
{ "features": [1.5, 16.0, 14.0, 23.0] }
```

或：

```
{ "data": { "features": { "values": [ 1.5, 16.0, 14.0, 23.0] } }
```

**稀疏格式**

稀疏格式的單一記錄會表示為：

```
{"data": {"features": { "keys": [26, 182, 232, 243, 431], "shape": [2000], "values": [1, 1, 1, 4, 1] } } }
```

多記錄會表示為上述單一記錄表示的集合，以換行字元分隔：

```
{"data": {"features": { "keys": [0, 1, 3], "shape": [4], "values": [1, 4, 1] } } }
{ "data": { "features": { "values": [ 1.5, 16.0, 14.0, 23.0] } }
{ "features": [1.5, 16.0, 14.0, 23.0] }
```

### CSV 請求格式
<a name="cm-csv"></a>

**內容類型：** text/CSV; label\$1size=0

**注意**  
因式分解機不提供 CSV 支援。

### RECORDIO 請求格式
<a name="cm-recordio"></a>

內容類型：application/x-recordio-protobuf

## 使用含內建演算法的批次轉換
<a name="cm-batch"></a>

執行批次轉換時，建議您使用 JSONLINES 回應類型，而非 JSON (如果演算法支援)。若要這樣做，請將 `CreateTransformJobRequest` 中的 `Accept` 欄位設定為 `application/jsonlines`。

建立轉換任務時，`SplitType` 必須根據輸入資料的 `ContentType` 來設定。同樣的，`AssembleWith` 必須根據 `CreateTransformJobRequest` 中的 `Accept` 欄位來設定。使用下表來設定這些欄位：


| ContentType | 建議的 SplitType | 
| --- | --- | 
| application/x-recordio-protobuf | RecordIO | 
| text/csv | Line | 
| application/jsonlines | Line | 
| application/json | None | 
| application/x-image | None | 
| image/\$1 | None | 


| 接受 | 建議的 AssembleWith | 
| --- | --- | 
| application/x-recordio-protobuf | None | 
| application/json | None | 
| application/jsonlines | Line | 

如需特定演算法回應格式的詳細資訊，請參閱以下各項：
+ [DeepAR 推論格式](deepar-in-formats.md)
+ [因式分解機回應格式](fm-in-formats.md)
+ [IP Insights 推論資料格式](ip-insights-inference-data-formats.md)
+ [K 平均值回應格式](km-in-formats.md)
+ [k-NN 請求和回應格式](kNN-inference-formats.md)
+ [線性學習程式回應格式](LL-in-formats.md)
+ [NTM 回應格式](ntm-in-formats.md)
+ [適用於 Object2Vec 推論的資料格式](object2vec-inference-formats.md)
+ [適用於 Object2Vec 的編碼器內嵌](object2vec-encoder-embeddings.md)
+ [PCA 回應格式](PCA-in-formats.md)
+ [RCF 回應格式](rcf-in-formats.md)

# 內建演算法的執行個體類型
<a name="cmn-info-instance-types"></a>

大多數 Amazon SageMaker AI 演算法已設計為可利用 GPU 運算進行訓練。雖然每個執行個體的成本較高，但 GPU 的訓練速度更快，更具成本效益。例外有註明在本教學中。

若要了解支援的 EC2 執行個體，請參閱[執行個體詳細資訊](https://aws.amazon.com/sagemaker-ai/pricing/#Instance_details)。

何種硬體組態最能發揮效率，資料的大小和類型有很大的影響。當相同的模型要不斷循環訓練時，最初在多種執行個體類型上進行測試，可找出長程下來最具成本效益的組態。此外，在 GPU 上訓練效率最佳的演算法，在推論時的效率可能並不需要 GPU。請進行實驗，找出最具效率的解決方案。若要取得自動執行個體建議或執行自訂負載測試，請使用 [Amazon SageMaker Inference Recommender](https://docs.aws.amazon.com/sagemaker/latest/dg/inference-recommender.html)。

如需 SageMaker AI 硬體規格的詳細資訊，請參閱 [Amazon SageMaker AI 定價](https://aws.amazon.com/sagemaker/ai/pricing/)。

**UltraServer**

UltraServer 使用低延遲、高頻寬加速器互連來連接多個 Amazon EC2 執行個體。它們旨在處理需要大量處理能力的大規模 AI/ML 工作負載。如需詳細資訊，請參閱 [Amazon EC2 UltraServer](https://aws.amazon.com/ec2/ultraservers/)。若要開始使用 UltraServers，請參閱[為您的訓練任務或 HyperPod 叢集預留訓練計畫](https://docs.aws.amazon.com/sagemaker/latest/dg/reserve-capacity-with-training-plans.html)。

若要在 Amazon SageMaker AI 上開始使用 UltraServers，[請建立訓練計畫](https://docs.aws.amazon.com/sagemaker/latest/dg/reserve-capacity-with-training-plans.html)。訓練計畫中提供 UltraServer 後，請使用 AWS 管理主控台、Amazon SageMaker AI API 或 建立訓練任務 AWS CLI。請記得在訓練計畫中指定您購買的 UltraServer 執行個體類型。

UltraServer 一次可以執行一或多個任務。UltraServer 會將執行個體分組在一起，這為您在組織中指派 UltraServer 容量提供了一定的彈性。當您設定任務時，也請記住組織的資料安全指導方針，因為一個 UltraServer 中的執行個體可以存取相同 UltraServer 上另一個執行個體中另一個任務的資料。

如果您在 UltraServer 中遇到硬體故障，SageMaker AI 會自動嘗試解決問題。隨著 SageMaker AI 調查並解決問題，您可能會透過 AWS Health Events 或 接收通知和動作 AWS 支援。

訓練任務完成後，SageMaker AI 會停止執行個體，但如果計劃仍處於作用中狀態，這些執行個體仍會保留在您的訓練計劃中。若要在任務完成後讓 UltraServer 中的執行個體持續執行，您可以使用[受管暖集區](https://docs.aws.amazon.com/sagemaker/latest/dg/train-warm-pools.html)。

如果您的訓練計畫有足夠的容量，您甚至可以在多個 UltraServer 上執行訓練任務。根據預設，每個 UltraServer 都隨附 18 個執行個體，其中包含 17 個執行個體和 1 個備用執行個體。如果您需要更多執行個體，則必須購買更多 UltraServer。建立訓練任務時，您可以使用 `InstancePlacementConfig` 參數設定任務在 UltraServer 之間的放置方式。

如果您未設定任務置放，SageMaker AI 會自動將任務配置到 UltraServer 中的執行個體。此預設策略是根據盡力而為，即在使用不同的 UltraServer 之前優先填入單一 UltraServer 中的所有執行個體。例如，如果您請求 14 個執行個體，並且訓練計畫中擁有 2 個 UltraServer，則 SageMaker AI 會使用第一個 UltraServer 中的所有執行個體。如果您請求 20 個執行個體，並且訓練計畫中擁有 2 個 UltraServer，則 SageMaker AI 將使用第一個 UltraServer 中的全部 17 個執行個體，然後使用第二個 UltraServer 中的 3 個執行個體。UltraServer 內的執行個體使用 NVLink 進行通訊，但個別 UltraServer 使用 Elastic Fabric Adapter (EFA)，這可能會影響模型訓練效能。

# 內建演算法的日誌
<a name="common-info-all-sagemaker-models-logs"></a>

Amazon SageMaker AI 演算法會產生 Amazon CloudWatch Logs，其中提供訓練流程的詳細資訊。若要查看日誌，請在 AWS 管理主控台中選擇 **CloudWatch**、選擇**日誌**，然後選擇 /aws/sagemaker/TrainingJobs **日誌群組**。每一項訓練工作進行訓練的各節點都有一個日誌串流。日誌串流的名稱會以建立工作時 `TrainingJobName` 參數所指定的值為開頭。

**注意**  
若工作失敗，而日誌未出現在 CloudWatch 內，可能再訓練開始前就已發生錯誤。原因包括訓練影像指定錯誤，或 S3 位置指定錯誤。

日誌的內會因演算法而異。不過一般可以看到下列資訊：
+ 日誌開頭對所提供的引數的確認
+ 訓練時發生的錯誤
+ 演算法準確度或數值效能的測量資料
+ 演算法的時間以及演算法的任何重要階段

## 常見錯誤
<a name="example-errors"></a>

若訓練工作失敗，`FailureReason` 所提供的錯誤詳細資訊會在訓練工作描述中將值傳回，如下所示：

```
sage = boto3.client('sagemaker')
sage.describe_training_job(TrainingJobName=job_name)['FailureReason']
```

其他僅會在 CloudWatch 日誌中回報。常見錯誤包括下列項目：

1. 超參數指定錯誤，或指定的超參數對該演算法無效。

   **來自 CloudWatch 日誌**

   ```
   [10/16/2017 23:45:17 ERROR 139623806805824 train.py:48]
   Additional properties are not allowed (u'mini_batch_siz' was
   unexpected)
   ```

1. 超參數指定的值無效。

   **FailureReason**

   ```
   AlgorithmError: u'abc' is not valid under any of the given
   schemas\n\nFailed validating u'oneOf' in
   schema[u'properties'][u'feature_dim']:\n    {u'oneOf':
   [{u'pattern': u'^([1-9][0-9]*)$', u'type': u'string'},\n
   {u'minimum': 1, u'type': u'integer'}]}\
   ```

   **FailureReason**

   ```
   [10/16/2017 23:57:17 ERROR 140373086025536 train.py:48] u'abc'
   is not valid under any of the given schemas
   ```

1. protobuf 檔案格式不正確。

   **來自 CloudWatch 日誌**

   ```
   [10/17/2017 18:01:04 ERROR 140234860816192 train.py:48] cannot
                      copy sequence with size 785 to array axis with dimension 784
   ```