在AWS SageMaker中,实时推理配置存储大小是通过EC2实例类型和实例数量来决定的。下面是一个示例代码,展示了如何设置实时推理配置存储大小:
import boto3
# 创建SageMaker客户端
sagemaker_client = boto3.client('sagemaker')
# 设置实例类型和数量
instance_type = 'ml.m4.xlarge'
instance_count = 1
# 设置存储大小(以GB为单位)
volume_size = 10
# 创建实时推理配置
response = sagemaker_client.create_endpoint_config(
EndpointConfigName='my-endpoint-config',
ProductionVariants=[
{
'VariantName': 'AllTraffic',
'ModelName': 'my-model',
'InstanceType': instance_type,
'InitialInstanceCount': instance_count,
'InitialVariantWeight': 1,
'InstanceVolumeSizeInGB': volume_size
},
]
)
# 输出实时推理配置的ARN
print(response['EndpointConfigArn'])
在上述代码中,我们首先创建了一个SageMaker客户端。然后,我们设置了实例类型(instance_type
)和实例数量(instance_count
)来定义实时推理配置。接下来,我们设置了存储大小(volume_size
)来指定实例的存储容量。
最后,我们使用create_endpoint_config
方法创建了一个名为my-endpoint-config
的实时推理配置。该配置使用ml.m4.xlarge
实例类型,1个实例,以及10GB的存储容量。在成功创建实时推理配置后,我们将输出其ARN(Amazon Resource Name)。
请注意,上述示例代码仅用于演示目的。在实际使用中,你需要根据自己的需求进行适当的配置。