Distributed training with Ray Train DLCs and EFA on EKS
Ray Train DLCs and EFA let you run distributed PyTorch training on EKS without building custom container images.

Distributed Training on EKS Made Simple with Ray Train DLCs and EFA
Running largeâscale PyTorch jobs on Kubernetes often stalls at the container level: you must keep CUDA, NCCL, the Elastic Fabric Adapter (EFA) stack, and a compatible Ray version perfectly aligned. The Ray Train Deep Learning Container (DLC) eliminates that friction by providing a preâbuilt, fully tested image that includes everything needed for multiânode training on Amazon EKS.
---
1. Why Use the Ray Train DLC?
| Feature | What It Means for You | |---|---| | Allâinâone stack | The image bundles a matching CUDA runtime, cuDNN, NCCL, the EFA userspace libraries, the AWS OFI NCCL plugin, and RayâŻ2.58 with Train, Tune, and Data. No manual version juggling. | | Public ECR image | Pulls without credentials, so you never need to maintain a private registry or push custom builds. | | Driverâforward compatibility | On startup the entrypoint checks the host NVIDIA driver; if itâs older than the imageâs CUDA, bundled forwardâcompatibility libraries are enabled automatically. | | Single image for head and workers | The same tag runs both the Ray head and the GPU workers, simplifying manifests and avoiding duplicate images. | | Runtimeâenvironment package installs | Any extra Python dependency can be installed at job submit time via `runtime_env`, keeping the base image immutable. |
By offloading the networking and driver concerns to the DLC, you focus on the model code and experiment configuration.
---
2. Setting Up the Cluster with KubeRay
- Create an EKS cluster with at least one CPUâonly node for the KubeRay operator and one or more EFAâenabled GPU nodes (e.g., `g6.12xlarge`).
- Install the KubeRay operator using the official Helm chart. It watches a custom `RayCluster` resource and creates the head and worker pods automatically.
- Define a `RayCluster` manifest that references the DLC image (`public.ecr.aws/deep-learning-containers/ray:train-ml-cuda-v1.1`). Example snippets:
```yaml apiVersion: ray.io/v1 kind: RayCluster metadata: name: qwen-train spec: headGroupSpec: serviceType: ClusterIP rayStartParams: num-gpus: "0" template: spec: containers: - name: ray-head image: public.ecr.aws/deep-learning-containers/ray:train-ml-cuda-v1.1 env: - name: FIPROVIDER value: efa - name: NCCLSOCKET_IFNAME value: eth0 workerGroupSpecs: - replicas: 2 minReplicas: 2 maxReplicas: 2 groupName: gpu-workers rayStartParams: num-gpus: "4" template: spec: containers: - name: ray-worker image: public.ecr.aws/deep-learning-containers/ray:train-ml-cuda-v1.1 resources: limits: nvidia.com/gpu: 4 vpc.amazonaws.com/efa: 1 ```
- Submit a training job using `ray job submit` or the Ray Dashboard. Provide a `runtime_env` block if you need extra packages:
```json { "runtime_env": { "pip": ["transformers==4.40.0", "accelerate"] } } ```
The operator ensures that if any pod crashes, it is recreated and reâjoined to the Ray head, preserving cluster state.
---
3. Running a RealâWorld Example â FineâTuning Qwen2.5â1.5B
The sample repository (linked in the original blog) demonstrates fineâtuning the Qwen2.5â1.5B model with PyTorch Fully Sharded Data Parallel (FSDP) across eight L4 GPUs spread over two `g6.12xlarge` nodes. Key takeaways:
- No custom Dockerfile â the DLC already contains PyTorchâŻ2.13, torchvision, DeepSpeed, flashâattn, and the Transformer Engine compiled for CUDAâŻ13.
- EFAâaccelerated collectives â NCCL automatically uses the EFA fabric because the image ships the AWS OFI NCCL plugin and the manifest sets `FI_PROVIDER=efa`.
- Reproducibility â Pin the image tag (`train-ml-cuda-v1.1`) or a digest to guarantee byteâidentical runs across experiments.
- Scalable resource spec â Adjust `replicas`, `nvidia.com/gpu`, and `vpc.amazonaws.com/efa` in the manifest to scale up or down without touching the container.
Running the job is as simple as: ```bash ray job submit \ --address http://<head-service>:8265 \ --runtime-env-json '{"pip": ["datasets", "evaluate"]}' \ -- python train.py --model qwen2.5-1.5b --batch-size 8 --steps 500 ``` All communication between the two nodes travels over the lowâlatency EFA network, delivering nearâbareâmetal throughput.
---
4. Best Practices and Gotchas
- Validate EFA availability: Ensure the subnet has the `EFA` service enabled and that the instance type supports it.
- Monitor NCCL diagnostics: The DLC includes `allreduceperf`. Running it inside a pod can quickly confirm that NCCL is using EFA rather than falling back to TCP.
- Pin image digests for production: Tags like `v1.1` receive security patches; for strict reproducibility, use the immutable digest (`sha256:âŚ`).
- Leverage Ray Dashboard: It provides realâtime visibility into worker health, GPU utilization, and network traffic, helping you spot bottlenecks early.
- Avoid mixing driver versions: If the host driver is newer than the imageâs CUDA, the forwardâcompatibility shim works, but the reverse (older driver, newer CUDA) will cause failures.
---
Closing Thoughts
The combination of Ray Train DLCs, EFA, and KubeRay turns what used to be a multiâday containerâbuilding exercise into a few YAML edits and a single `ray job submit` command. By relying on AWSâmaintained images that are continuously tested on multiânode EFA setups, data science teams can iterate faster, scale more reliably, and keep their focus on model innovation rather than lowâlevel stack compatibility.
Source
Read original sourceWhy we picked this
Detailed tutorial on distributed training of a large model using Ray Train on AWS, a core AI tooling piece.