

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 생성형 AI 추론 권장 사항 배포
<a name="generative-ai-inference-recommendations-deploy"></a>

권장 작업이 완료되면 각 권장 사항에 배포 준비 구성이 포함됩니다. 선택한 구성을 SageMaker AI Studio의 단일 작업을 사용하거나 API를 통해 프로그래밍 방식으로 SageMaker AI 추론 엔드포인트에 배포할 수 있습니다.

## 배포 구성 이해
<a name="generative-ai-inference-recommendations-deploy-overview"></a>

작업 응답의 각 권장 사항에는 다음 정보가 포함된 `DeploymentConfiguration` 객체가 포함됩니다.

`ImageUri`  
권장 인스턴스 유형에 최적화된 컨테이너 이미지 URI입니다.

`InstanceType`  
배포에 권장되는 인스턴스 유형입니다.

`InstanceCount`  
성능 목표를 충족하는 데 필요한 인스턴스 수입니다.

`CopyCountPerInstance`  
인스턴스당 실행할 모델 복사본 수입니다. 1보다 큰 값으로 설정하면 처리량을 높이기 위해 각 인스턴스에 모델의 여러 복사본이 로드됩니다.

`EnvironmentVariables`  
텐서 병렬 크기 및 최대 시퀀스 길이와 같이 최적의 성능을 위해 구성된 환경 변수입니다.

`S3`  
최적화된 모델 출력을 포함하여 모델 아티팩트에 대한 S3 채널 참조입니다.

## API를 사용하여 배포
<a name="generative-ai-inference-recommendations-deploy-api"></a>

권장 사항을 프로그래밍 방식으로 배포하려면 권장 사항의 모델 패키지를 사용하여 SageMaker AI 모델 및 엔드포인트를 생성합니다. 각 권장 사항에는 모델 패키지 ARN 및 추론 사양 이름이 있는 `ModelDetails` 객체가 포함됩니다. 모델 패키지에는 컨테이너 이미지, 환경 변수 및 모델 아티팩트 채널이 이미 포함되어 있으므로 가장 간단한 배포 경로입니다.

```
import boto3

client = boto3.client("sagemaker", region_name="us-west-2")

# Get the recommendation from a completed job
response = client.describe_ai_recommendation_job(
    AIRecommendationJobName="my-recommendation-job"
)

# Select a recommendation (e.g., the first one)
recommendation = response["Recommendations"][0]
model_details = recommendation["ModelDetails"]
deploy_config = recommendation["DeploymentConfiguration"]

# Create a model from the model package.
# The model package already contains the container image, environment
# variables, and S3 data channels (base model + optimization artifacts).
model_name = "my-recommended-model"
container_def = {
    "ModelPackageName": model_details["ModelPackageArn"],
}
# If the recommendation uses a named inference specification (e.g., for
# a specific optimization variant), specify it so SageMaker selects the
# correct container and instance configuration from the model package.
if model_details.get("InferenceSpecificationName"):
    container_def["InferenceSpecificationName"] = model_details["InferenceSpecificationName"]

client.create_model(
    ModelName=model_name,
    PrimaryContainer=container_def,
    ExecutionRoleArn="arn:aws:iam::111122223333:role/ExampleRole",
)

# Create an endpoint configuration
endpoint_config_name = "my-recommended-endpoint-config"
production_variant = {
    "VariantName": "AllTraffic",
    "ModelName": model_name,
    "InstanceType": deploy_config["InstanceType"],
    "InitialInstanceCount": deploy_config.get("InstanceCount", 1),
}
copy_count = deploy_config.get("CopyCountPerInstance")
if copy_count and copy_count > 1:
    production_variant["InferenceAmiVersion"] = "al2-ami-sagemaker-inference-gpu-2"
    production_variant["RoutingConfig"] = {"RoutingStrategy": "LEAST_OUTSTANDING_REQUESTS"}

client.create_endpoint_config(
    EndpointConfigName=endpoint_config_name,
    ProductionVariants=[production_variant],
)

# Create the endpoint
endpoint_name = "my-recommended-endpoint"
client.create_endpoint(
    EndpointName=endpoint_name,
    EndpointConfigName=endpoint_config_name,
)
print(f"Endpoint {endpoint_name} is being created.")
```

엔드포인트가 생성된 후 상태에 도달할 때까지 `DescribeEndpoint` API를 사용하여 엔드포인트의 `InService` 상태를 모니터링할 수 있습니다.

```
import time

while True:
    response = client.describe_endpoint(EndpointName=endpoint_name)
    status = response["EndpointStatus"]
    print(f"Endpoint status: {status}")
    if status in ("InService", "Failed"):
        break
    time.sleep(60)
```

## SageMaker AI Studio에서 배포
<a name="generative-ai-inference-recommendations-deploy-studio"></a>

단일 작업으로 SageMaker AI Studio에서 직접 권장 구성을 배포할 수도 있습니다. SageMaker AI Studio에서 완료된 권장 사항 작업으로 이동하여 권장 사항과 해당 성능 지표를 검토하고 배포하려는 구성을 선택합니다.