

# Neuron 태스크 정의 예제
<a name="ecs-inference-task-def"></a>

## 관리형 디바이스 할당 예제
<a name="ecs-inference-task-def-managed"></a>

다음 예제는 `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로 바꿉니다.

## 수동 디바이스 지정 예제
<a name="ecs-inference-task-def-ec2"></a>

다음 예제에서는 EC2 시작 유형과 `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"
        }
    ]
}
```