

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Menyebarkan Model Kompilasi Menggunakan Boto3
<a name="neo-deployment-hosting-services-boto3"></a>

Anda harus memenuhi bagian [prasyarat](https://docs.aws.amazon.com//sagemaker/latest/dg/neo-deployment-hosting-services-prerequisites) jika model dikompilasi menggunakan AWS SDK untuk Python (Boto3),, AWS CLI atau konsol Amazon AI. SageMaker Ikuti langkah-langkah di bawah ini untuk membuat dan menerapkan SageMaker Neo-compiled model menggunakan [Amazon Web Services SDK for Python (Boto3)](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html). 

**Topics**
+ [Menyebarkan Model](#neo-deployment-hosting-services-boto3-steps)

## Menyebarkan Model
<a name="neo-deployment-hosting-services-boto3-steps"></a>

Setelah Anda memenuhi [prasyarat](https://docs.aws.amazon.com//sagemaker/latest/dg/neo-deployment-hosting-services-prerequisites), gunakan,, dan API`create_model`. `create_enpoint_config` `create_endpoint` 

Contoh berikut menunjukkan cara menggunakan API ini untuk menerapkan model yang dikompilasi dengan Neo: 

```
import boto3
client = boto3.client('sagemaker')

# create sagemaker model
create_model_api_response = client.create_model(
                                    ModelName={{'my-sagemaker-model'}},
                                    PrimaryContainer={
                                        'Image': {{<insert the ECR Image URI>}},
                                        'ModelDataUrl': {{'s3://path/to/model/artifact/model.tar.gz'}},
                                        'Environment': {}
                                    },
                                    ExecutionRoleArn={{'ARN for AmazonSageMaker-ExecutionRole'}}
                            )

print ("create_model API response", create_model_api_response)

# create sagemaker endpoint config
create_endpoint_config_api_response = client.create_endpoint_config(
                                            EndpointConfigName={{'sagemaker-neomxnet-endpoint-configuration'}},
                                            ProductionVariants=[
                                                {
                                                    'VariantName': {{<provide your variant name>}},
                                                    'ModelName': {{'my-sagemaker-model}}',
                                                    'InitialInstanceCount': 1,
                                                    'InstanceType': {{<provide your instance type here>}}
                                                },
                                            ]
                                       )

print ("create_endpoint_config API response", create_endpoint_config_api_response)

# create sagemaker endpoint
create_endpoint_api_response = client.create_endpoint(
                                    EndpointName={{'provide your endpoint name'}},
                                    EndpointConfigName={{<insert your endpoint config name>}},
                                )

print ("create_endpoint API response", create_endpoint_api_response)
```

**catatan**  
`AmazonS3ReadOnlyAccess`Kebijakan `AmazonSageMakerFullAccess` dan kebijakan harus dilampirkan pada peran `AmazonSageMaker-ExecutionRole` IAM. 

Untuk sintaks lengkap`create_model`,`create_endpoint_config`, dan `create_endpoint` API, lihat [https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_model](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_model), [https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_endpoint_config](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_endpoint_config), dan [https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_endpoint](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_endpoint), masing-masing. 

Jika Anda tidak melatih model Anda menggunakan SageMaker AI, tentukan variabel lingkungan berikut: 

------
#### [ MXNet and PyTorch ]

```
"Environment": {
    "SAGEMAKER_PROGRAM": "inference.py",
    "SAGEMAKER_SUBMIT_DIRECTORY": {{"/opt/ml/model/code"}},
    "SAGEMAKER_CONTAINER_LOG_LEVEL": "20",
    "SAGEMAKER_REGION": {{"insert your region"}},
    "MMS_DEFAULT_RESPONSE_TIMEOUT": "500"
}
```

------
#### [ TensorFlow ]

```
"Environment": {
    "SAGEMAKER_PROGRAM": "inference.py",
    "SAGEMAKER_SUBMIT_DIRECTORY": {{"/opt/ml/model/code"}},
    "SAGEMAKER_CONTAINER_LOG_LEVEL": "20",
    "SAGEMAKER_REGION": {{"insert your region"}}
}
```

------

 Jika Anda melatih model menggunakan SageMaker AI, tentukan variabel lingkungan `SAGEMAKER_SUBMIT_DIRECTORY` sebagai URI bucket Amazon S3 lengkap yang berisi skrip pelatihan. 