

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

# 設定 Autopilot 實驗的預設參數 (適用於管理員)
<a name="autopilot-set-default-parameters-create-experiment"></a>

當您使用 Studio Classic 使用者介面建立 Autopilot 實驗時，Autopilot 支援設定預設值以簡化 Amazon SageMaker Autopilot 的組態。系統管理員可以使用 Studio Classic [生命週期組態](studio-lcc.md) (LCC) 在組態檔中設定基礎結構、網路與安全性值，並預先填入 `AutoML` 任務的[進階設定](autopilot-automate-model-development-create-experiment-ui.md#advanced-settings)。

這樣，他們就可以完全控制與 Amazon SageMaker Studio Classic 關聯的資源 (包括 SageMaker AI 執行個體、資料來源、輸出資料和其他相關服務) 的網路連線以及存取權限。具體來說，管理員可以為 Studio Classic 網域或個別使用者設定檔設定所需的網路架構，例如 Amazon VPC、子網路和安全群組。使用 Studio Classic 使用者介面建立 Autopilot 實驗時，資料科學家可以專注於資料科學特定的參數。此外，管理員可以透過設定預設加密金鑰，管理員可以在執行 Autopilot 實驗的執行個體管理資料的加密。

**注意**  
此特徵目前在亞太地區 (香港) 及中東 (巴林) 選擇加入的區域不可用。

在以下各節中，您可以在使用 Studio Classic 使用者介面建立 Autopilot 實驗時，找到支援預設值設定的完整參數清單，並了解如何設定這些預設值。

**Topics**
+ [支援的預設參數清單](#autopilot-list-default-parameters-create-experiment)
+ [設定預設 Autopilot 實驗參數](#autopilot-set-default-parameters-create-experiment-howto)

## 支援的預設參數清單
<a name="autopilot-list-default-parameters-create-experiment"></a>

下列參數支援使用組態檔設定預設值，以便使用 Studio Classic 使用者介面建立 Autopilot 實驗。設定後，這些值會自動填入 Studio Classic 使用者介面中 Autopilot 的**建立實驗**標籤的對應欄位。如需每個欄位的完整說明，請參閱[進階設定 (選用)](autopilot-automate-model-development-create-experiment-ui.md#advanced-settings)。
+ **安全：**Amazon VPC、子網路與安全群組。
+ **Access：** AWS IAM 角色 ARNs。
+ **Encryption：** AWS KMS key IDs。
+ **標籤：**用於標籤和組織 SageMaker AI 資源的鍵值對。

## 設定預設 Autopilot 實驗參數
<a name="autopilot-set-default-parameters-create-experiment-howto"></a>

系統管理員可以在組態檔設定預設值，然後手動將檔案放置在特定使用者 Studio Classic 環境中的建議位置，或將檔案傳送至生命週期組態指令碼 (LCC)，以自動針對指定網域或使用者設定檔自訂 Studio Classic 環境。
+ 若要設定組態檔，請先從  填入其預設參數。

  若要設定 [支援的預設參數清單](#autopilot-list-default-parameters-create-experiment) 列出的任何或所有預設值，管理員可以建立名為 `config.yaml` 的組態檔，其結構應符合此[樣本組態檔](https://sagemaker.readthedocs.io/en/stable/overview.html#configuration-file-structure)。下列的程式碼片段顯示了包含所有受支援的 `AutoML` 參數的樣本組態檔。如需有關此檔案格式的詳細資訊，請參閱[完整結構描述](https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/config/config_schema.py)。

  ```
  SchemaVersion: '1.0'
  SageMaker:
    AutoMLJob:
      # https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateAutoMLJob.html
      AutoMLJobConfig:
        SecurityConfig:
          EnableInterContainerTrafficEncryption: true
          VolumeKmsKeyId: '{{kms-key-id}}'
          VpcConfig:
            SecurityGroupIds:
              - '{{security-group-id-1}}'
              - '{{security-group-id-2}}'
            Subnets:
              - '{{subnet-1}}'
              - '{{subnet-2}}'
      OutputDataConfig:
        KmsKeyId: '{{kms-key-id}}'
      RoleArn: '{{arn:aws:iam::111222333444:role/Admin}}'
      Tags:
      - Key: '{{tag_key}}'
        Value: '{{tag_value}}'
  ```
+ 然後，[手動將檔案複製到其建議的路徑或使用[生命週期組態 (LCC)，將組態檔](#autopilot-intelligent-defaults-lcc-setup)](#autopilot-intelligent-defaults-manual-setup)置於建議的位置。

  組態檔必須存在於使用者 Studio Classic 環境中的下列位置中的至少一個。依預設，SageMaker AI 會在兩個位置搜尋組態檔：
  + 首先，在 `/etc/xdg/sagemaker/config.yaml`。我們將此檔案稱為*管理員組態檔*。
  + 然後，在 `/root/.config/sagemaker/config.yaml`。我們將此文件稱為*使用者組態檔*。

  使用*管理員*組態檔，管理員可以定義一組預設值。或者，他們可以使用*使用者*組態檔來取代*管理員*組態檔設定的值，或設定其他預設參數值。

  下列程式碼片段顯示樣本指令碼，該指令碼會將預設參數組態檔寫入使用者 Studio Classic 環境中的*管理員*位置。您可以將 `/etc/xdg/sagemaker` 取代為 `/root/.config/sagemaker`，以將檔案寫入*使用者*位置。

  ```
  ## Sample script with AutoML intelligent defaults
  #!/bin/bash
  
  sudo mkdir -p /etc/xdg/sagemaker
  
  echo "SchemaVersion: '1.0'
  CustomParameters:
    AnyStringKey: 'AnyStringValue'
  SageMaker:
    AutoMLJob:
      # https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateAutoMLJob.html
      AutoMLJobConfig:
        SecurityConfig:
          EnableInterContainerTrafficEncryption: true
          VolumeKmsKeyId: '{{kms-key-id}}'
          VpcConfig:
            SecurityGroupIds:
              - '{{security-group-id-1}}'
              - '{{security-group-id-2}}'
            Subnets:
              - '{{subnet-1}}'
              - '{{subnet-2}}'
      OutputDataConfig:
        KmsKeyId: '{{kms-key-id}}'
      RoleArn: '{{arn:aws:iam::111222333444:role/Admin}}'
      Tags:
      - Key: '{{tag_key}}'
        Value: '{{tag_value}}'
  " | sudo tee /etc/xdg/sagemaker/config.yaml
  ```
  + **手動複製檔案**–若要手動複製組態檔，請從 Studio Classic 終端機執行上個步驟建立的[指令碼](#autopilot-intelligent-defaults-manual-setup)。在此情況下，執行指令碼的使用者設定檔可以使用僅適用於它們的預設值來建立 Autopilot 實驗。
  + **建立 SageMaker AI 生命週期組態** – 或者，您可以使用[生命週期組態](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-lcc.html) (LCC) 來自動化 Studio Classic 環境的自訂。LCC 是由 Amazon SageMaker Studio Classic 生命週期事件 (例如啟動 Studio Classic 應用程式) 觸發的 Shell 指令碼。此自訂功能包括安裝自訂套件、設定筆記本擴充功能、預先載入資料集、設定原始程式碼儲存庫，或是預先填入預設參數。系統管理員可以將 LCC 附加至 Studio Classic 網域，以自動設定該網域中每個使用者設定檔的預設值。

    以下各節將詳細說明如何建立生命週期組態，讓使用者可以在啟動 Studio Classic 時自動載入 Autopilot 預設參數。您可以選擇使用 SageMaker AI 主控台或 AWS CLI建立 LCC。

------
#### [ Create a LCC from the SageMaker AI Console ]

    使用下列步驟建立包含預設參數的 LCC、將 LCC 附加至網域或使用者設定檔，然後啟動使用 SageMaker AI 主控台預先填入 LCC 設定的預設參數的 Studio Classic 應用程式。
    + **若要使用 SageMaker AI 主控台建立執行包含預設值的[指令碼](#autopilot-intelligent-defaults-script)的生命週期組態**
      + 開啟位於 [https://console.aws.amazon.com/sagemaker/](https://console.aws.amazon.com/sagemaker/) 的 SageMaker AI 主控台。
      + 在左側，導覽至**管理員組態**，然後選擇**生命週期組態**。
      + 從**生命週期組態**頁面，導覽至 Studio Classic 索引標籤，然後選擇**建立組態**。
      + 在**名稱** 中，使用英數字元和 “-” 來輸入名稱，但不能輸入空格。名稱最多可使用 63 個字元。
      + 將您的[指令碼](#autopilot-intelligent-defaults-script)貼到**指令碼**區段。
      + 選擇**建立組態**以建立生命週期組態。這會建立類型為 `Kernel gateway app` 的 LCC。
    +  **將生命週期組態附加至 Studio Classic 網域、空間或使用者設定檔**

      依照將[生命週期組態附加至 Studio Classic 網域或使用者設定檔](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-lcc-create-console.html#studio-lcc-create-console-step2)中的步驟，將 LCC 附加至 Studio Classic 網域或特定使用者設定檔。
    +  **使用生命週期組態啟動您的 Studio Classic 應用程式**

      一旦 LCC 附加到網域或使用者設定檔，受影響的使用者就可以從 Studio 中的 Studio Classic 登陸頁面啟動 Studio Classic 應用程式，以自動取得 LCC 設定的預設值。建立 Autopilot 實驗時，這會自動填入 Studio Classic 使用者介面。

------
#### [ Create a LCC from the AWS CLI ]

    使用下列程式碼片段來啟動使用 AWS CLI執行[指令碼](#autopilot-intelligent-defaults-manual-setup)的 Studio Classic 應用程式。請注意，`lifecycle_config.sh` 是在此範例指定給指令碼的名稱。

    開始之前：
    + 完成從 建立生命週期組態中所述的 AWS CLI 先決條件，確保您已更新並設定 。 [AWS CLI](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-lcc-create-cli.html)
    + 安裝 [OpenSSL](https://www.openssl.org/source/) 文件。 AWS CLI 命令會使用開放原始碼程式庫 *OpenSSL*，以 Base64 格式編碼您的指令碼。此要求可防止由於間距和換行編碼而發生的錯誤。

    您現在可以按照以下三個步驟操作：
    +  **參考組態指令碼 `lifecycle_config.sh` 建立新的生命週期組態**

      ```
      LCC_CONTENT=`openssl base64 -A -in {{lifecycle_config.sh}}`
      
      ## Create a new lifecycle config 
      aws sagemaker create-studio-lifecycle-config --region {{region}} \
      --studio-lifecycle-config-name {{lcc-name}} \
      --studio-lifecycle-config-content $LCC_CONTENT \
      --studio-lifecycle-config-app-type default
      ```

      記下傳回之新建立之生命週期組態的 ARN。需要此 ARN 才能將生命週期組態附加至您的應用程式。
    +  **將生命週期組態附加至 `JupyterServerApp`**

      以下範例示範如何建立附加生命週期組態的新使用者設定檔。若要更新現有的使用者設定檔，請使用 AWS CLI [update-user-profile](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sagemaker/update-user-profile.html) 命令。若要建立或更新網域，請參閱 [create-domain](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sagemaker/create-domain.html) 及 [update-domain](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sagemaker/update-domain.html)。將上個步驟的生命週期組態 ARN 新增至 `JupyterServerAppSettings` 應用程式類型的設定。您可以使用生命週期組態清單，同時新增多個生命週期組態。

      ```
      # Create a new UserProfile
      aws sagemaker create-user-profile --domain-id {{domain-id}} \
      --user-profile-name {{user-profile-name}} \
      --region {{region}} \
      --user-settings '{
      "JupyterServerAppSettings": {
        "LifecycleConfigArns":
          ["{{lifecycle-configuration-arn}}"]
        }
      }'
      ```

      一旦 LCC 連接到網域或使用者設定檔，受影響的使用者可以依照關閉和更新 [Amazon SageMaker Studio Classic 中的步驟來關閉和更新現有的 Studio Classic](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-tasks-update-studio.html) 應用程式，或從 AWS 主控台啟動新的 Studio Classic 應用程式，以自動取得 LCC 設定的預設值。建立 Autopilot 實驗時，這會自動填入 Studio Classic 使用者介面。或者，他們可以使用 啟動新的 Studio Classic 應用程式 AWS CLI ，如下所示。
    +  **使用 啟動具有生命週期組態的 Studio Classic 應用程式 AWS CLI**

      ```
      # Create a Jupyter Server application
      aws sagemaker create-app --domain-id {{domain-id}} \
      --user-profile-name {{user-profile-name}} \
      --region {{region}} \
      --app-type JupyterServer \
      --resource-spec LifecycleConfigArn={{lifecycle-configuration-arn}} \
      --app-name default
      ```

      如需有關使用 AWS CLI建立生命週期組態的詳細資訊，請參閱[從 AWS CLI建立生命週期組態](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-lcc-create-cli.html)。

------