View a markdown version of this page

Neuron 任务定义示例 - Amazon Elastic Container Service

Neuron 任务定义示例

托管设备分配示例

以下示例显示了使用 resourceRequirements 参数请求实例上所有 Neuron 设备的任务定义。该方法仅适用于托管实例。

{ "family": "ecs-neuron", "requiresCompatibilities": ["MANAGED_INSTANCES"], "networkMode": "awsvpc", "cpu": "8192", "memory": "16384", "executionRoleArn": "${YOUR_EXECUTION_ROLE}", "containerDefinitions": [ { "name": "neuron-inference", "image": "763104351884.dkr.ecr.us-east-1.amazonaws.com/huggingface-vllm-inference-neuronx:0.11.0-optimum0.4.5-neuronx-py310-sdk2.26.1-ubuntu22.04", "essential": true, "command": [ "--model", "${YOUR_HUGGING_FACE_MODEL_ID}", "--port", "8080", "--tensor-parallel-size", "2", "--allow-non-cached-model" ], "portMappings": [ { "containerPort": 8080, "protocol": "tcp" } ], "resourceRequirements": [ { "type": "NeuronDevice", "value": "ALL" } ] } ] }

在此示例中,容器镜像包括一个针对 AWS Neuron 进行优化的 vLLM 推理服务器。镜像入口点从 HuggingFace 下载一个模型,并针对 Neuron 进行编译,然后在端口 8080 上启动一个兼容 OpenAI 的 API 服务器。将 ${YOUR_HUGGING_FACE_MODEL_ID} 替换为您的 HuggingFace 模型 ID。

手动指定设备示例

以下示例显示了 inf1.xlarge 的一个 Linux 任务定义,即结合使用 EC2 启动类型和 linuxParameters.devices 指定 Neuron 设备路径。

{ "family": "ecs-neuron", "requiresCompatibilities": ["EC2"], "placementConstraints": [ { "type": "memberOf", "expression": "attribute:ecs.os-type == linux" }, { "type": "memberOf", "expression": "attribute:ecs.instance-type == inf1.xlarge" } ], "executionRoleArn": "${YOUR_EXECUTION_ROLE}", "containerDefinitions": [ { "entryPoint": [ "/usr/local/bin/entrypoint.sh", "--port=8500", "--rest_api_port=9000", "--model_name=resnet50_neuron", "--model_base_path=s3://amzn-s3-demo-bucket/resnet50_neuron/" ], "portMappings": [ { "hostPort": 8500, "protocol": "tcp", "containerPort": 8500 }, { "hostPort": 8501, "protocol": "tcp", "containerPort": 8501 }, { "hostPort": 0, "protocol": "tcp", "containerPort": 80 } ], "linuxParameters": { "devices": [ { "containerPath": "/dev/neuron0", "hostPath": "/dev/neuron0", "permissions": [ "read", "write" ] } ], "capabilities": { "add": [ "IPC_LOCK" ] } }, "cpu": 0, "memoryReservation": 1000, "image": "763104351884.dkr.ecr.us-east-1.amazonaws.com/tensorflow-inference-neuron:1.15.4-neuron-py37-ubuntu18.04", "essential": true, "name": "resnet50" } ] }