

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

# 部署自訂模型
<a name="deploying-custom-model"></a>

您可以使用 Amazon Bedrock 主控台 AWS Command Line Interface或 AWS SDKs 部署自訂模型。如需使用部署進行推論的相關資訊，請參閱[使用部署進行隨需推論](https://docs.aws.amazon.com/bedrock/latest/userguide/use-custom-model-on-demand.html)。

**Topics**
+ [

## 部署自訂模型 (主控台)
](#deploy-custom-model-console)
+ [

## 部署自訂模型 (AWS Command Line Interface)
](#deploy-custom-model-cli)
+ [

## 部署自訂模型AWS SDKs)
](#deploy-custom-model-sdk)

## 部署自訂模型 (主控台)
<a name="deploy-custom-model-console"></a>

您可以如下所示從**自訂模型**頁面部署自訂模型。您也可以從具有相同欄位的**隨需自訂模型**頁面部署模型。若要尋找此頁面，請在導覽窗格的**推論和評估**中選擇**隨需自訂模型**。

**部署自訂模型**

1.  AWS 管理主控台 使用[具有 Amazon Bedrock 許可的 IAM 角色](https://docs.aws.amazon.com//bedrock/latest/userguide/getting-started.html)登入 ，然後開啟位於 https：//[https://console.aws.amazon.com/nova/](https://console.aws.amazon.com/nova/) 的 Amazon Bedrock 主控台。

1. 從左側導覽窗格中，選擇**基礎模型**下的**自訂模型**。

1. 在**模型**索引標籤中，選擇您要部署之模型的選項按鈕。

1. 選擇**設定推論**，然後選擇**隨需部署**。

1. 在**部署詳細資訊**中，提供下列資訊：
   + **部署名稱** (必要)：輸入部署的唯一名稱。
   + **描述** (選用)：輸入部署描述。
   + **標籤 ** (選用)：新增成本分配和資源管理的標籤。

1. 選擇**建立**。當狀態顯示 `Completed` 時，自訂模型已準備好進行隨需推論。如需使用自訂模型的詳細資訊，請參閱[使用部署進行隨需推論](https://docs.aws.amazon.com/bedrock/latest/userguide/use-custom-model-on-demand.html)。

## 部署自訂模型 (AWS Command Line Interface)
<a name="deploy-custom-model-cli"></a>

若要使用 部署用於隨需推論的自訂模型 AWS Command Line Interface，請使用 `create-custom-model-deployment`命令搭配自訂模型的 Amazon Resource Name (ARN)。此命令使用 [CreateCustomModelDeployment](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateCustomModelDeployment.html) API 操作。它會傳回部署的 ARN，您可以在提出推論請求時將其用作 `modelId`。如需使用部署進行推論的相關資訊，請參閱[使用部署進行隨需推論](https://docs.aws.amazon.com/bedrock/latest/userguide/use-custom-model-on-demand.html)。

```
aws bedrock create-custom-model-deployment \
--model-deployment-name "Unique name" \
--model-arn "Custom Model ARN" \
--description "Deployment description" \
--tags '[
    {
        "key": "Environment",
        "value": "Production"
    },
    {
        "key": "Team",
        "value": "ML-Engineering"
    },
    {
        "key": "Project",
        "value": "CustomerSupport"
    }
]' \
--client-request-token "unique-deployment-token" \
--region region
```

## 部署自訂模型AWS SDKs)
<a name="deploy-custom-model-sdk"></a>

若要部署用於隨需推論的自訂模型，請搭配自訂模型的 Amazon Resource Name (ARN) 使用 [CreateCustomModelDeployment](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateCustomModelDeployment.html) API 操作。回應會傳回部署的 ARN，您可以在提出推論請求時將其用作 `modelId`。如需使用部署進行推論的相關資訊，請參閱[使用部署進行隨需推論](https://docs.aws.amazon.com/bedrock/latest/userguide/use-custom-model-on-demand.html)。

下列程式碼說明如何使用適用於 Python 的 SDK (Boto3) 部署自訂模型。

```
def create_custom_model_deployment(bedrock_client):
    """Create a custom model deployment
    Args:
        bedrock_client: A boto3 Bedrock client for making API calls
 
    Returns:
        str: The ARN of the created custom model deployment
 
    Raises:
        Exception: If there is an error creating the deployment
    """
 
    try:
        response = bedrock_client.create_custom_model_deployment(
            modelDeploymentName="Unique deployment name",
            modelArn="Custom Model ARN",
            description="Deployment description",
            tags=[
                {'key': 'Environment', 'value': 'Production'},
                {'key': 'Team', 'value': 'ML-Engineering'},
                {'key': 'Project', 'value': 'CustomerSupport'}
            ],
            clientRequestToken=f"deployment-{uuid.uuid4()}"
        )
 
        deployment_arn = response['customModelDeploymentArn']
        print(f"Deployment created: {deployment_arn}")
        return deployment_arn
 
    except Exception as e:
        print(f"Error creating deployment: {str(e)}")
        raise
```