

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

# 部署模型
<a name="jumpstart-deploy"></a>

當您從 JumpStart 部署模型時，SageMaker AI 會託管模型並部署可用於推論的端點。JumpStart 也提供範例筆記本，您可以在部署模型後用來存取模型。

**重要**  
自 2023 年 11 月 30 日起，先前的 Amazon SageMaker Studio 體驗現在名為 Amazon SageMaker Studio Classic。下節專門介紹如何使用 Studio Classic 應用程式。如需使用已更新 Studio 體驗的資訊，請參閱 [Amazon SageMaker Studio](studio-updated.md)。  
Studio Classic 仍會針對現有工作負載進行維護，但無法再用於加入。您只能停止或刪除現有的 Studio Classic 應用程式，而且無法建立新的應用程式。建議您[將工作負載遷移至新的 Studio 體驗](studio-updated-migrate.md)。

**注意**  
如需 Studio 中 JumpStart 模型部署的詳細資訊，請參閱[在 Studio 中部署模型](jumpstart-foundation-models-use-studio-updated-deploy.md)

## 模型部署組態
<a name="jumpstart-config"></a>

選擇模型後，會開啟模型的索引標籤。在**部署模型**窗格中，選擇**部署組態**以設定模型部署。

 ![The Deploy Model pane.](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/jumpstart/jumpstart-deploy.png) 

部署模型的預設執行個體類型取決於模型。執行個體類型是執行訓練工作的硬體。在下列範例中，`ml.p2.xlarge` 執行個體是此特定 BERT 模型的預設值。

您也可以變更端點名稱、新增 `key;value` 資源索引標籤、啟用或取消使用任何與模型相關的 JumpStart 資源的 `jumpstart-` 前置詞，以及指定 Amazon S3 儲存貯體來存放 SageMaker AI 端點使用的模型成品。

 ![JumpStart Deploy Model pane with Deployment Configuration open to select its settings.](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/jumpstart/jumpstart-deploy-config.png) 

選擇**安全設定**以指定模型的 AWS Identity and Access Management (IAM) 角色、Amazon Virtual Private Cloud (Amazon VPC) 和加密金鑰。

 ![JumpStart Deploy Model pane with Security Settings open to select its settings.](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/jumpstart/jumpstart-deploy-security.png) 

## 模型部署安全性
<a name="jumpstart-config-security"></a>

使用 JumpStart 部署模型時，您可以為該模型指定 IAM 角色、Amazon VPC 和加密金鑰。如果您未為這些項目指定任何值：您的 Studio Classic 執行時期角色將為預設 IAM 角色；使用預設加密；不使用 Amazon VPC。

### IAM 角色
<a name="jumpstart-config-security-iam"></a>

您可以選取作為訓練工作和託管工作一部分傳遞的 IAM 角色。SageMaker AI 使用此角色來存取訓練資料和模型成品。如果您未選取 IAM 角色，SageMaker AI 會使用您的 Studio Classic 執行時期角色部署模型。如需關於 IAM 角色的詳細資訊，請參閱[AWS Identity and Access Management 適用於 Amazon SageMaker AI](security-iam.md)。

您傳遞的角色必須能夠存取模型所需的資源，並且必須包含下列所有項目。
+ 針對訓練工作：[CreateTrainingJob API：執行角色權限](https://docs.aws.amazon.com//sagemaker/latest/dg/sagemaker-roles.html#sagemaker-roles-createtrainingjob-perms)。
+ 針對託管工作：[CreateModel API：執行角色權限](https://docs.aws.amazon.com//sagemaker/latest/dg/sagemaker-roles.html#sagemaker-roles-createmodel-perms)。

**注意**  
您可以縮小以下每個角色授予的 Amazon S3 權限範圍。使用 Amazon Simple Storage Service (Amazon S3) 的 ARN，以及 JumpStart Amazon S3 儲存貯體完成此操作。  

```
[
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:ListBucket"
      ],
      "Resource": [
        "arn:aws:s3:::jumpstart-cache-prod-{{<region>}}/*",
        "arn:aws:s3:::jumpstart-cache-prod-{{<region>}}",
        "arn:aws:s3:::{{<bucket>}}/*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
           "cloudwatch:PutMetricData",
           "logs:CreateLogStream",
          "logs:PutLogEvents",
          "logs:CreateLogGroup",
          "logs:DescribeLogStreams",
          "ecr:GetAuthorizationToken"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "ecr:BatchGetImage",
        "ecr:BatchCheckLayerAvailability",
        "ecr:GetDownloadUrlForLayer"
      ],
      "Resource": [
        "*"
      ]
    },
  ]
}
```

**尋找 IAM 角色**

如果選取此選項，則必須從下拉式清單中選取現有的 IAM 角色。

 ![JumpStart Security Settings IAM section with Find IAM role selected.](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/jumpstart/jumpstart-deploy-security-findiam.png) 

**輸入 IAM 角色**

如果選取此選項，則必須手動輸入現有 IAM 角色的 ARN。如果您的 Studio Classic 執行時期角色或 Amazon VPC 封鎖 `iam:list* ` 呼叫，您必須使用此選項才能使用現有的 IAM 角色。

 ![JumpStart Security Settings IAM section with Input IAM role selected.](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/jumpstart/jumpstart-deploy-security-inputiam.png) 

### Amazon VPC
<a name="jumpstart-config-security-vpc"></a>

所有 JumpStart 模型均以網路隔離模式執行。建立模型容器之後，就不能再進行呼叫。您可以選取作為訓練工作和託管工作一部分傳遞的 Amazon VPC 角色。SageMaker AI 使用此 Amazon VPC 從您的 Amazon S3 儲存貯體中推送和提取資源。這個 Amazon VPC 不同於限制從您 Studio Classic 執行個體存取公用網際網路的 Amazon VPC。如需 Studio Classic Amazon VPC 的詳細資訊，請參閱[將 VPC 中的 Studio 筆記本連線至外部資源](studio-notebooks-and-internet-access.md)。

您傳遞的 Amazon VPC 不需要存取公用網際網路，但確實需要存取 Amazon S3。Amazon S3 適用的 Amazon VPC 端點必須至少允許存取模型所需的下列資源。

```
{
  "Effect": "Allow",
  "Action": [
    "s3:GetObject",
    "s3:PutObject",
    "s3:ListMultipartUploadParts",
    "s3:ListBucket"
  ],
  "Resources": [
    "arn:aws:s3:::jumpstart-cache-prod-{{<region>}}/*",
    "arn:aws:s3:::jumpstart-cache-prod-{{<region>}}",
    "arn:aws:s3:::{{bucket}}/*"
  ]
}
```

如果您未選取 Amazon VPC，則不會使用任何 Amazon VPC。

**尋找 VPC**

如果選取此選項，則必須從下拉式清單中選取現有的 Amazon VPC 角色。選取 Amazon VPC 之後，您必須為 Amazon VPC 選取子網路和安全群組。如需有關子網路和安全群組的詳細資訊，請參閱[ VPC 和子網路概觀](https://docs.aws.amazon.com//vpc/latest/userguide/VPC_Subnets.html)。

 ![JumpStart Security Settings VPC section with Find VPC selected.](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/jumpstart/jumpstart-deploy-security-findvpc.png) 

**VPC 輸入**

如果選取此選項，則必須手動選取構成 Amazon VPC 的子網路和安全群組。如果您的 Studio Classic 執行時期角色或 Amazon VPC 封鎖 `ec2:list*` 呼叫，您必須使用此選項來選取子網路和安全群組。

 ![JumpStart Security Settings VPC section with Input VPC selected.](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/jumpstart/jumpstart-deploy-security-inputvpc.png) 

### 加密金鑰
<a name="jumpstart-config-security-encryption"></a>

您可以選取做為訓練任務和託管任務一部分傳遞的 AWS KMS 金鑰。SageMaker AI 使用此金鑰來加密容器的 Amazon EBS 磁碟區，以及 Amazon S3 中用於託管工作的重新包裝模型和訓練工作的輸出。如需 AWS KMS 金鑰的詳細資訊，請參閱 [AWS KMS 金鑰](https://docs.aws.amazon.com//kms/latest/developerguide/concepts.html#kms_keys)。

您傳遞的金鑰必須信任您傳遞的 IAM 角色。如果您未指定 IAM 角色， AWS KMS 金鑰必須信任您的 Studio Classic 執行期角色。

如果您未選取 AWS KMS 金鑰，SageMaker AI 會為 Amazon EBS 磁碟區中的資料和 Amazon S3 成品提供預設加密。

**尋找加密金鑰**

如果您選取此選項，則必須從下拉式清單中選取現有的 AWS KMS 金鑰。

 ![JumpStart Security Settings encryption section with Find encryption keys selected.](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/jumpstart/jumpstart-deploy-security-findencryption.png) 

**輸入加密金鑰**

如果您選取此選項，則必須手動輸入 AWS KMS 金鑰。如果您的 Studio Classic 執行角色或 Amazon VPC 封鎖`kms:list* `呼叫，您必須使用此選項來選取現有的 AWS KMS 金鑰。

 ![JumpStart Security Settings encryption section with Input encryption keys selected.](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/jumpstart/jumpstart-deploy-security-inputencryption.png) 

## 設定 JumpStart 模型的預設值
<a name="jumpstart-config-defaults"></a>

您可以為 IAM 角色、VPC 和 KMS 金鑰等參數設定預設值，以預先填入 JumpStart 模型部署和訓練。設定預設值之後，Studio Classic 使用者介面會自動將您的具體安全設定和標籤提供給 JumpStart 模型，以簡化部署和訓練工作流程。系統管理員和使用者可以初始化在 YAML 格式的組態檔中指定的預設值。

SageMaker Python SDK 會依預設使用兩個組態檔案：一個針對管理員，另一個針對使用者。管理員可以使用系統管理員組態檔案定義一組預設值。終端使用者可以覆寫管理員組態檔案中設定的值，並使用終端使用者組態檔設定其他預設值。如需詳細資訊，請參閱[預設組態檔案位置](https://sagemaker.readthedocs.io/en/stable/overview.html#default-configuration-file-location)。

下列程式碼範例列出在 Amazon SageMaker Studio Classic 中使用 SageMaker Python SDK 時組態檔案的預設位置。

```
# Location of the admin config file
/etc/xdg/sagemaker/config.yaml

# Location of the user config file
/root/.config/sagemaker/config.yaml
```

在使用者組態檔案中指定的值會取代管理員組態檔案中設定的值。Amazon SageMaker AI 網域中的每個使用者設定檔都是唯一的。使用者描述檔的 Studio Classic 應用程式直接與使用者描述檔關聯。如需詳細資訊，請參閱[網域使用者設定檔](domain-user-profile.md)。

管理員可以選擇性透過 `JupyterServer` 生命週期組態設定 JumpStart 模型訓練和部署的組態預設。如需詳細資訊，請參閱[建立生命週期組態並將其與 Amazon SageMaker Studio Classic 建立關聯](studio-lcc-create.md)。

### 預設值組態 YAML 檔案
<a name="jumpstart-config-defaults-yaml"></a>

您的設定檔應該遵守 SageMaker Python SDK [設定檔案結構](https://sagemaker.readthedocs.io/en/stable/overview.html#configuration-file-structure)。請注意，`TrainingJob`、`Model` 和 `EndpointConfig` 組態中的特定欄位適用於 JumpStart 模型訓練和部署預設值。

```
SchemaVersion: '1.0'
SageMaker:
  TrainingJob:
    OutputDataConfig:
      KmsKeyId: {{example-key-id}}
    ResourceConfig:
      # Training configuration - Volume encryption key
      VolumeKmsKeyId: {{example-key-id}}
    # Training configuration form - IAM role
    RoleArn: arn:aws:iam::{{123456789012}}:role/SageMakerExecutionRole
    VpcConfig:
      # Training configuration - Security groups
      SecurityGroupIds:
      - {{sg-1}}
      - {{sg-2}}
      # Training configuration - Subnets
      Subnets:
      - {{subnet-1}}
      - {{subnet-2}}
    # Training configuration - Custom resource tags
    Tags:
    - Key: {{Example-key}}
      Value: {{Example-value}}
  Model:
    EnableNetworkIsolation: {{true}}
    # Deployment configuration - IAM role
    ExecutionRoleArn: arn:aws:iam::{{123456789012}}:role/SageMakerExecutionRole
    VpcConfig:
      # Deployment configuration - Security groups
      SecurityGroupIds:
      - {{sg-1}}
      - {{sg-2}}
      # Deployment configuration - Subnets
      Subnets:
      - {{subnet-1}}
      - {{subnet-2}}
  EndpointConfig:
    AsyncInferenceConfig:
      OutputConfig:
        KmsKeyId: {{example-key-id}}
    DataCaptureConfig:
      # Deployment configuration - Volume encryption key
      KmsKeyId: {{example-key-id}}
    KmsKeyId: {{example-key-id}}
    # Deployment configuration - Custom resource tags
    Tags:
    - Key: {{Example-key}}
      Value: {{Example-value}}
```