Neuron 태스크 정의 예시
Neuron 태스크 정의 예시
AWS Neuron 머신 러닝 워크로드를 위한 태스크 정의 예시를 알아봐요. 관리형 디바이스 할당과 수동 디바이스 지정 방식을 다뤄요.
출처: 문서
본문
관리형 디바이스 할당 예시 (Managed device allocation example)
다음 예시는 resourceRequirements 파라미터를 사용해 인스턴스의 모든 Neuron 디바이스를 요청하는 태스크 정의를 보여줘요. 이 접근 방식은 Managed Instances에서만 사용할 수 있어요.
{
"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 추론 서버를 포함해요. 이미지의 진입점(entrypoint)은 HuggingFace에서 모델을 다운로드하고, Neuron용으로 컴파일하며, 포트 8080에서 OpenAI 호환 API 서버를 시작해요. ${YOUR_HUGGING_FACE_MODEL_ID}를 사용자의 HuggingFace 모델 ID로 바꾸세요.
수동 디바이스 지정 예시 (Manual device specification example)
다음 예시는 EC2 launch type을 사용하고 linuxParameters.devices로 Neuron 디바이스 경로를 지정하는 inf1.xlarge용 Linux 태스크 정의를 보여줘요.
{
"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"
}
]
}