跳至内容

如何对我的 Amazon SageMaker AI 无服务器推理端点的问题进行故障排除?

2 分钟阅读
0

当我使用 Amazon SageMaker AI 无服务器推理端点处理我的工作负载时,我收到了错误。

解决方法

根据您收到的错误消息对问题进行故障排除。

容器映像大小对于无服务器推理端点而言过大

无服务器推理端点支持自带容器 (BYOC),类似于实时端点。由于 AWS Lambda 支持此特定类型的推理,因此此特定类型推断的容器大小必须小于 10 GB。

如果您的容器超过 10 GB 限制,则您会收到一条类似于以下内容的错误消息:

“映像大小 11271073144 大于支持的大小 10737418240”

要解决此问题,请执行以下操作之一:

  • 删除未使用的软件包并最大限度减少 Docker 文件中的层数,以减小映像大小并优化 Docker 容器。
  • 使用较小的基础映像并创建新的端点配置。指定用于托管实时端点的所需实例类型和其他相关参数。
  • 从无服务器端点转换为实时端点。创建新的端点配置,以指定用于托管实时端点的实例类型和其他参数。然后,使用新配置更新您的现有端点。
  1. 要创建新的端点配置,请使用以下模板:
    import boto3
    
    client = boto3.client('sagemaker', region_name = 'us-east-1')
    
    endpoint_config_name = 'new-endpoint-config'
    production_variants = [
        {
            'VariantName': 'AllTraffic',
            'ModelName': 'ModelName',
            'InitialInstanceCount': 1,
            'InstanceType': 'ml.m5.xlarge',
            'InitialVariantWeight': 1.0
        }
    ]
    
    create_endpoint_config_response = client.create_endpoint_config(
        EndpointConfigName=endpoint_config_name,
        ProductionVariants=production_variants
    )
    **注意:**请将 YourVariantName 替换为您的实例变体的名称,将 YourModelName 替换为您的模型的名称。将 1 替换为您的初始实例数量。将 ml.m5.xlarge 替换为您的实例类型。将 1.0 替换为您的实例的初始变体权重。
  2. 使用新配置创建新端点,以将其从无服务器端点转换为实时端点。或者,使用新配置更新现有无服务器端点。
    创建新的端点示例:
    endpoint_name = 'new-endpoint'
    
    create_endpoint_response = client.create_endpoint(
        EndpointName=endpoint_name,
        EndpointConfigName=endpoint_config_name
    )
    更新现有端点示例:
    endpoint_name = 'my-old-endpoint'
    
    update_endpoint_response = client.update_endpoint(
        EndpointName=endpoint_name,
        EndpointConfigName=endpoint_config_name
    )

要确定容器大小,请从 Amazon Elastic Container Registry (ECR) 检索映像 URI。然后,运行以下 Docker 命令来获取 Docker 映像的详细信息:

docker images

无服务器推理端点中的内存或磁盘空间不足

SageMaker AI 无服务器端点的最大内存分配为 6 GB,临时磁盘存储容量为 5 GB。

如果无服务器端点的内存超过限制,则您会收到一条类似于以下内容的错误消息:

“UnexpectedStatusException: 托管端点时出错: 失败。原因: 由于内存不足,Ping 失败。”

要解决此问题,请从以下选项中选择:

  • 调整 MemorySizeInMB 参数。
  • 优化您的 Worker 配置。
  • 将端点部署为实时端点并提供所需的实例详细信息。

调整 MemorySizeInMB 参数

  1. 使用增加后的 MemorySizeInMB 创建新的无服务器端点配置。
    示例:
    import boto3
    
    client = boto3.client('sagemaker', region_name='us-east-1')
    
    endpoint_config_name = "new-endpoint-config"
    
    endpoint_config_response = client.create_endpoint_config(
        EndpointConfigName=endpoint_config_name,
        ProductionVariants=[
            {
                "VariantName": YourVariantName,
                "ModelName": YourModelName,
                "ServerlessConfig": {
                    "MemorySizeInMB": NewMemorySize,
                    "MaxConcurrency": 1,
                },
            },
        ],
    )
    **注意:**请将 YourVariantName 替换为您的变体名称,将 YourModelName 替换为您的模型名称。将 NewMemorySize 替换为内存大小限制。您可以使用的最大值为 6 GB。
  2. 使用新配置更新无服务器端点。
    示例:
    endpoint_name = 'my-old-endpoint'
    
    update_endpoint_response = client.update_endpoint(
        EndpointName=endpoint_name,
        EndpointConfigName=endpoint_config_name
    )

优化您的 Worker 配置

为避免内存错误,请在容器中仅创建一个使用所有可用 CPU 资源的 Worker。此方法与实时端点不同,在实时端点中,某些 SageMaker AI 容器可能会为每个 vCPU 创建一个 Worker。

对于使用 SageMaker AI 推理工具包的预构建容器,请通过将 SAGEMAKER_MODEL_SERVER_WORKERS 设置为 1 来修改推理模型创建。

示例:

import boto3

client = boto3.client('sagemaker', region_name='us-east-1')

response = client.create_model(
    ModelName='YourModelName',
    Containers=[
    {
        'Image': "YourImage"
        'Mode': 'SingleModel',
        'ModelDataUrl': "YourModelDataURL",
        'Environment': {
            'SAGEMAKER_CONTAINER_LOG_LEVEL': '20',
            'SAGEMAKER_MODEL_SERVER_WORKERS': '1'
        }
    }
    ],
    ExecutionRoleArn=role
)

**注意:**请将 YourModelName 替换为您的模型名称,将 YourImage 替换为您的映像名称,将 YourModelDataUrl 替换为您的模型数据 URL。

将端点部署为实时端点并提供所需的实例详细信息

有关如何将端点部署为实时端点的信息,请参阅本文中的“从无服务器端点转换为实时端点”。

磁盘空间不足

如果您的无服务器端点没有可用的磁盘空间,则您可能会收到以下错误消息:

“OSError:[错误 28] 设备无剩余空间”

要解决此问题,请执行以下操作:

  • 确保压缩后的模型解压缩后的大小不超过可用磁盘空间。文件解压缩后的大小是其压缩大小的三倍。
  • 使用较小的模型构件,然后确保 .tar 存档中的所有文件在部署中都是必需的。
  • 如果无服务器推理不可行,请部署到实时端点以自定义实例规格。

无服务器推理端点中的冷启动场景

由于资源预置的按需特性以及 SageMaker AI 无服务器推理的限制,目前没有明确的方法可以预热 SageMaker AI 无服务器推理端点。有关详细信息,请参阅最大限度减少冷启动

对于分配的 ProvisionedConcurrency,SageMaker AI 会使端点保持热状态,以便在几毫秒内做出响应。为了最大限度减少冷启动延迟问题,请使用 ProvisionedConcurrency 更新您的端点。有关详细信息,请参阅使用 Amazon CloudWatch 监控 Amazon SageMaker AI 的指标

完成以下步骤:

  1. 使用小于或等于 MaxConcurrencyProvisionedConcurrency 创建新的无服务器端点配置。
    配置示例:
    import boto3
    client = boto3.client('sagemaker', region_name='us-east-1')
    
    endpoint_config_name = "new-endpoint-config"
    
    endpoint_config_response = client.create_endpoint_config(
        EndpointConfigName=endpoint_config_name,
        ProductionVariants=[
            {
                "VariantName": YourVariantName,
                "ModelName": YourModelName,
                "ServerlessConfig": {
                    "MemorySizeInMB": NewMemorySize,
                    "MaxConcurrency": 1,
                    "ProvisionedConcurrency": 1,
                },
            },
        ],
    )
    **注意:**请将 YourVariantName 替换为您的变体名称,将 YourModelName 替换为您的模型名称。将 NewMemorySize 替换为内存大小限制。您可以使用的最大值为 6 GB。
  2. 使用新配置更新端点。
    示例:
    endpoint_name = 'my-serverless-endpoint'
    update_endpoint_response = client.update_endpoint(
        EndpointName=endpoint_name,
        EndpointConfigName=endpoint_config_name
    )

**注意:**最佳做法是使用 SageMaker AI 无服务器推理基准测试工具包来确定无服务器端点的最有效部署配置。

相关信息

使用 Amazon SageMaker AI 无服务器推理功能部署模型

AWS 官方已更新 10 个月前