使用GPU工作負載 AMI - AWS Batch

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

使用GPU工作負載 AMI

若要在 AWS Batch 運算資源上執行GPU工作負載,您必須使用 AMI搭配 GPU支援。如需詳細資訊,請參閱Amazon Elastic Container Service 開發人員指南中的在 Amazon 和 Amazon GPUsECS上使用 ECS- 最佳化AMIs

在受管運算環境中,如果運算環境指定任何 p2p3p4g4、、 p5 g3 g3sg5執行個體類型或執行個體系列,則 AWS Batch 會使用 Amazon ECSGPU最佳化的 AMI。

在未受管理的運算環境中,AMI建議使用 Amazon ECS GPU最佳化。您可以使用 AWS Command Line Interface 或 AWS Systems Manager 參數存放區 GetParameterGetParametersGetParametersByPath操作來擷取建議的 Amazon ECS GPU最佳化 的中繼資料AMIs。

注意

p5 執行個體系列僅在等於或高於 Amazon ECS GPU最佳化20230912的版本上受支援AMI,且與 p2g2執行個體類型不相容。如果您需要使用p5執行個體,請確定您的運算環境不包含 p2g2執行個體,並使用最新的預設批次 AMI。建立新的運算環境將使用最新的,AMI但如果您要將運算環境更新為包含 p5,則可以AMI在 ComputeResource 屬性true中將 設定為 updateToLatestImageVersion,以確保使用的是最新的。如需GPU執行個體AMI相容性的詳細資訊,請參閱 Amazon Elastic Container Service 開發人員指南中的在 Amazon GPUs上使用 ECS

下列範例示範如何使用 GetParameter命令。

AWS CLI
$ aws ssm get-parameter --name /aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended \ --region us-east-2 --output json

輸出包含 Value 參數中AMI的資訊。

{
    "Parameter": {
        "Name": "/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended",
        "LastModifiedDate": 1555434128.664,
        "Value": "{\"schema_version\":1,\"image_name\":\"amzn2-ami-ecs-gpu-hvm-2.0.20190402-x86_64-ebs\",\"image_id\":\"ami-083c800fe4211192f\",\"os\":\"Amazon Linux 2\",\"ecs_runtime_version\":\"Docker version 18.06.1-ce\",\"ecs_agent_version\":\"1.27.0\"}",
        "Version": 9,
        "Type": "String",
        "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended"
    }
}
Python
from __future__ import print_function import json import boto3 ssm = boto3.client('ssm', 'us-east-2') response = ssm.get_parameter(Name='/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended') jsonVal = json.loads(response['Parameter']['Value']) print("image_id = " + jsonVal['image_id']) print("image_name = " + jsonVal['image_name'])

輸出僅包含 AMI ID 和AMI名稱:

image_id   = ami-083c800fe4211192f
image_name = amzn2-ami-ecs-gpu-hvm-2.0.20190402-x86_64-ebs

下列範例示範 的使用GetParameters

AWS CLI
$ aws ssm get-parameters --names /aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_name \ /aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_id \ --region us-east-2 --output json

這時輸出會包含個別參數的完整中繼資料:

{
    "InvalidParameters": [],
    "Parameters": [
        {
            "Name": "/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_id",
            "LastModifiedDate": 1555434128.749,
            "Value": "ami-083c800fe4211192f",
            "Version": 9,
            "Type": "String",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_id"
        },
        {
            "Name": "/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_name",
            "LastModifiedDate": 1555434128.712,
            "Value": "amzn2-ami-ecs-gpu-hvm-2.0.20190402-x86_64-ebs",
            "Version": 9,
            "Type": "String",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_name"
        }
    ]
}
Python
from __future__ import print_function import boto3 ssm = boto3.client('ssm', 'us-east-2') response = ssm.get_parameters( Names=['/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_name', '/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_id']) for parameter in response['Parameters']: print(parameter['Name'] + " = " + parameter['Value'])

輸出包含 AMI ID 和AMI名稱,使用名稱的完整路徑。

/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_id = ami-083c800fe4211192f
/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_name = amzn2-ami-ecs-gpu-hvm-2.0.20190402-x86_64-ebs

下列範例示範如何使用 GetParametersByPath命令。

AWS CLI
$ aws ssm get-parameters-by-path --path /aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended \ --region us-east-2 --output json

輸出包含指定路徑下所有參數的完整中繼資料。

{
    "Parameters": [
        {
            "Name": "/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/ecs_agent_version",
            "LastModifiedDate": 1555434128.801,
            "Value": "1.27.0",
            "Version": 8,
            "Type": "String",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/ecs_agent_version"
        },
        {
            "Name": "/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/ecs_runtime_version",
            "LastModifiedDate": 1548368308.213,
            "Value": "Docker version 18.06.1-ce",
            "Version": 1,
            "Type": "String",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/ecs_runtime_version"
        },
        {
            "Name": "/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_id",
            "LastModifiedDate": 1555434128.749,
            "Value": "ami-083c800fe4211192f",
            "Version": 9,
            "Type": "String",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_id"
        },
        {
            "Name": "/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_name",
            "LastModifiedDate": 1555434128.712,
            "Value": "amzn2-ami-ecs-gpu-hvm-2.0.20190402-x86_64-ebs",
            "Version": 9,
            "Type": "String",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_name"
        },
        {
            "Name": "/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/os",
            "LastModifiedDate": 1548368308.143,
            "Value": "Amazon Linux 2",
            "Version": 1,
            "Type": "String",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/os"
        },
        {
            "Name": "/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/schema_version",
            "LastModifiedDate": 1548368307.914,
            "Value": "1",
            "Version": 1,
            "Type": "String",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/schema_version"
        }
    ]
}
Python
from __future__ import print_function import boto3 ssm = boto3.client('ssm', 'us-east-2') response = ssm.get_parameters_by_path(Path='/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended') for parameter in response['Parameters']: print(parameter['Name'] + " = " + parameter['Value'])

輸出包含指定路徑上所有參數名稱的值,並使用名稱的完整路徑。

/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/ecs_agent_version = 1.27.0
/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/ecs_runtime_version = Docker version 18.06.1-ce
/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_id = ami-083c800fe4211192f
/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_name = amzn2-ami-ecs-gpu-hvm-2.0.20190402-x86_64-ebs
/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/os = Amazon Linux 2
/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/schema_version = 1

如需詳細資訊,請參閱 Amazon Elastic Container Service 開發人員指南 中的擷取 Amazon ECS最佳化AMI中繼資料