|
| 1 | +# AWS EFA |
| 2 | + |
| 3 | +In this guide, we’ll walk through how to run high-performance distributed training on AWS using [Amazon Elastic Fabric Adapter (EFA) :material-arrow-top-right-thin:{ .external }](https://aws.amazon.com/hpc/efa/){:target="_blank"} with `dstack`. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +EFA is a network interface for Amazon EC2 that enables low-latency, high-bandwidth inter-node communication — essential for scaling distributed deep learning. With `dstack`, EFA is automatically enabled when you create fleets with supported instance types. |
| 8 | + |
| 9 | +## Prerequisite |
| 10 | + |
| 11 | +Before you start, make sure the `aws` backend is properly configured. |
| 12 | + |
| 13 | +<div editor-title="~/.dstack/server/config.yml"> |
| 14 | + |
| 15 | +```yaml |
| 16 | +projects: |
| 17 | +- name: main |
| 18 | + backends: |
| 19 | + - type: aws |
| 20 | + creds: |
| 21 | + type: default |
| 22 | + regions: ["us-west-2"] |
| 23 | + |
| 24 | + public_ips: false |
| 25 | + vpc_name: my-custom-vpc |
| 26 | +``` |
| 27 | +
|
| 28 | +</div> |
| 29 | +
|
| 30 | +!!! info "Multiple network interfaces" |
| 31 | + To use P4, P5, or P6 instances, set `public_ips` to `false` — this allows AWS to attach multiple network interfaces for EFA. In this case, the `dstack` server can reach your VPC’s private subnets. |
| 32 | + |
| 33 | +!!! info "VPC" |
| 34 | + If you use a custom VPC, verify that it permits all internal traffic between nodes for EFA to function properly |
| 35 | + |
| 36 | +## Create a fleet |
| 37 | + |
| 38 | +Once your backend is ready, define a fleet configuration. |
| 39 | + |
| 40 | +<div editor-title="examples/clusters/efa/fleet.dstack.yml"> |
| 41 | + |
| 42 | + ```yaml |
| 43 | + type: fleet |
| 44 | + name: my-efa-fleet |
| 45 | + |
| 46 | + nodes: 2 |
| 47 | + placement: cluster |
| 48 | + |
| 49 | + resources: |
| 50 | + gpu: H100:8 |
| 51 | + ``` |
| 52 | + |
| 53 | +</div> |
| 54 | + |
| 55 | +Provision the fleet with `dstack apply`: |
| 56 | + |
| 57 | +<div class="termy"> |
| 58 | + |
| 59 | +```shell |
| 60 | +$ dstack apply -f examples/clusters/efa/fleet.dstack.yml |
| 61 | +
|
| 62 | +Provisioning... |
| 63 | +---> 100% |
| 64 | +
|
| 65 | + FLEET INSTANCE BACKEND INSTANCE TYPE GPU PRICE STATUS CREATED |
| 66 | + my-efa-fleet 0 aws (us-west-2) p4d.24xlarge H100:8:80GB $98.32 idle 3 mins ago |
| 67 | + 1 aws (us-west-2) p4d.24xlarge $98.32 idle 3 mins ago |
| 68 | +``` |
| 69 | + |
| 70 | +</div> |
| 71 | + |
| 72 | +??? info "Instance types" |
| 73 | + `dstack` selects suitable instances automatically, but not |
| 74 | + [all types support EFA :material-arrow-top-right-thin:{ .external }](https://aws.amazon.com/hpc/efa/){:target="_blank"}. |
| 75 | + To enforce EFA, you can specify `instance_types` explicitly: |
| 76 | + |
| 77 | + ```yaml |
| 78 | + type: fleet |
| 79 | + name: my-efa-fleet |
| 80 | + |
| 81 | + nodes: 2 |
| 82 | + placement: cluster |
| 83 | + |
| 84 | + resources: |
| 85 | + gpu: L4 |
| 86 | +
|
| 87 | + instance_types: ["g6.8xlarge"] # If not specified, g6.xlarge is used (won't have EFA) |
| 88 | + ``` |
| 89 | + |
| 90 | +## Run NCCL tests |
| 91 | + |
| 92 | +To confirm that EFA is working, run NCCL tests: |
| 93 | + |
| 94 | +<div editor-title="examples/clusters/nccl-tests/.dstack.yml"> |
| 95 | + |
| 96 | +```yaml |
| 97 | +type: task |
| 98 | +name: nccl-tests |
| 99 | +
|
| 100 | +nodes: 2 |
| 101 | +
|
| 102 | +startup_order: workers-first |
| 103 | +stop_criteria: master-done |
| 104 | +
|
| 105 | +env: |
| 106 | + - NCCL_DEBUG=INFO |
| 107 | +commands: |
| 108 | + - | |
| 109 | + if [ $DSTACK_NODE_RANK -eq 0 ]; then |
| 110 | + mpirun \ |
| 111 | + --allow-run-as-root \ |
| 112 | + --hostfile $DSTACK_MPI_HOSTFILE \ |
| 113 | + -n $DSTACK_GPUS_NUM \ |
| 114 | + -N $DSTACK_GPUS_PER_NODE \ |
| 115 | + --bind-to none \ |
| 116 | + all_reduce_perf -b 8 -e 8G -f 2 -g 1 |
| 117 | + else |
| 118 | + sleep infinity |
| 119 | + fi |
| 120 | +
|
| 121 | +resources: |
| 122 | + gpu: 1..8 |
| 123 | + shm_size: 16GB |
| 124 | +``` |
| 125 | + |
| 126 | +</div> |
| 127 | + |
| 128 | +Run it with `dstack apply`: |
| 129 | + |
| 130 | +<div class="termy"> |
| 131 | + |
| 132 | +```shell |
| 133 | +$ dstack apply -f examples/clusters/nccl-tests/.dstack.yml |
| 134 | +
|
| 135 | +Provisioning... |
| 136 | +---> 100% |
| 137 | +``` |
| 138 | + |
| 139 | +</div> |
| 140 | + |
| 141 | +!!! info "Docker image" |
| 142 | + You can use your own container by setting `image`. If omitted, `dstack` uses its default image with drivers, NCCL tests, and tools pre-installed. |
| 143 | + |
| 144 | +## Run distributed training |
| 145 | + |
| 146 | +Here’s an example using `torchrun` for a simple multi-node PyTorch job: |
| 147 | + |
| 148 | +<div editor-title="examples/distributed-training/torchrun/.dstack.yml"> |
| 149 | + |
| 150 | +```yaml |
| 151 | +type: task |
| 152 | +name: train-distrib |
| 153 | +
|
| 154 | +nodes: 2 |
| 155 | +
|
| 156 | +python: 3.12 |
| 157 | +env: |
| 158 | + - NCCL_DEBUG=INFO |
| 159 | +commands: |
| 160 | + - git clone https://github.com/pytorch/examples.git pytorch-examples |
| 161 | + - cd pytorch-examples/distributed/ddp-tutorial-series |
| 162 | + - uv pip install -r requirements.txt |
| 163 | + - | |
| 164 | + torchrun \ |
| 165 | + --nproc-per-node=$DSTACK_GPUS_PER_NODE \ |
| 166 | + --node-rank=$DSTACK_NODE_RANK \ |
| 167 | + --nnodes=$DSTACK_NODES_NUM \ |
| 168 | + --master-addr=$DSTACK_MASTER_NODE_IP \ |
| 169 | + --master-port=12345 \ |
| 170 | + multinode.py 50 10 |
| 171 | +
|
| 172 | +resources: |
| 173 | + gpu: 1..8 |
| 174 | + shm_size: 16GB |
| 175 | +``` |
| 176 | + |
| 177 | +</div> |
| 178 | + |
| 179 | +Provision and launch it via `dstack apply`. |
| 180 | + |
| 181 | +<div class="termy"> |
| 182 | + |
| 183 | +```shell |
| 184 | +$ dstack apply -f examples/distributed-training/torchrun/.dstack.yml |
| 185 | +
|
| 186 | +Provisioning... |
| 187 | +---> 100% |
| 188 | +``` |
| 189 | + |
| 190 | +</div> |
| 191 | + |
| 192 | +Instead of setting `python`, you can specify your own Docker image using `image`. Make sure that the image is properly configured for EFA. |
| 193 | + |
| 194 | +!!! info "What's next" |
| 195 | + 1. Learn more about [distributed tasks](https://dstack.ai/docs/concepts/tasks#distributed-tasks) |
| 196 | + 2. Check [dev environments](https://dstack.ai/docs/concepts/dev-environments), |
| 197 | + [services](https://dstack.ai/docs/concepts/services), and [fleets](https://dstack.ai/docs/concepts/fleets) |
| 198 | + 3. Read the [Clusters](https://dstack.ai/docs/guides/clusters) guide |
0 commit comments