Amazon Web Services has published a detailed guide on running distributed machine learning training on Amazon EKS using Ray Train and the Ray Train Deep Learning Container (DLC). This guide demonstrates how to fine-tune a large language model—specifically, the Qwen2.5-1.5B model—using PyTorch’s Fully Sharded Data Parallel (FSDP) framework across eight GPUs distributed across two EFA-enabled g6.12xlarge instances in a single Availability Zone.
What Happened
The sample configuration leverages a fully integrated, pre-built container image from AWS to execute distributed training without any custom container image builds. The entire training pipeline—from infrastructure setup to job execution—is orchestrated through a series of scripts and configuration files, with no manual intervention required to align CUDA, NCCL, or EFA versions.
Using the Ray Train Deep Learning Container (DLC), the training environment is provisioned on Amazon Elastic Kubernetes Service (EKS). The Ray framework manages the distributed execution of the training loop, while the Elastic Fabric Adapter (EFA) enables low-latency, high-bandwidth inter-node communication between the two GPU instances. The training job is initiated from within the EKS control plane, using a single Python script that runs once per GPU, with all model parameters and training logic defined in a minimal, reusable function.
The cluster is configured via a single YAML manifest file, which defines both the head and worker pods. Both pods use the same Ray Train DLC image, eliminating the need for separate head and worker images. The training loop uses FSDP to split the model’s weights, gradients, and optimizer states across the eight GPUs, reducing memory overhead while maintaining full model fidelity. Each GPU holds approximately 1.5 GB of model data, with communication occurring in every training step through NCCL-based collective operations.
Key Components and Their Roles
Ray Train Deep Learning Container (DLC)
The Ray Train DLC is a pre-assembled, publicly available container image hosted in Amazon ECR Public. It includes a complete stack of distributed training components: Ray with its training libraries (such as TorchTrain, Tune, and Data), PyTorch compiled with CUDA 13.0.2, cuDNN, and NCCL 13.0.2, and NCCL 2.29.7. The container is built and tested as a unified unit by AWS, ensuring that all components are compatible and function together under a wide range of distributed training workloads.
Unlike traditional container builds, where developers must manually align CUDA, NCCL, and EFA versions, the DLC eliminates this complexity. AWS validates each release through rigorous multi-node EFA and KubeRay training tests, ensuring that the container is stable and performs well under real-world distributed training conditions. The container includes all necessary diagnostics, such as NCCL performance tests, which are already available in the path, allowing teams to validate communication paths without additional setup.
Elastic Fabric Adapter (EFA) and Networking Stack
Inter-node communication in distributed training is a critical performance bottleneck. The EFA provides a high-performance, low-latency network interface that enables direct GPU-to-GPU communication between nodes, bypassing the traditional TCP/IP stack. In this setup, EFA traffic is routed through the AWS OFI NCCL plugin, which acts as a bridge between NCCL and the EFA fabric. This path is activated via four environment variables: FI_PROVIDER, NCCL_NET_PLUGIN, NCCL_SOCKET_IFNAME, and NCCL_DEBUG.
When the EFA path is active, communication between the two g6.12xlarge instances occurs through the full stack: NCCL → AWS OFI NCCL plugin → libfabric → EFA. This path provides significantly higher throughput and lower latency than the fallback TCP sockets, which are used only when the EFA interface is unavailable or misconfigured. The sample configuration explicitly sets all four variables in the manifest, ensuring that the EFA path is not only enabled but also visible and verifiable during runtime.
KubeRay and Kubernetes Orchestration
KubeRay is an open-source Kubernetes operator that simplifies the deployment and management of Ray clusters. It allows users to define a Ray cluster using a single YAML manifest file, which specifies both a head group and a worker group. KubeRay then automatically creates the necessary pods, starts Ray in the appropriate role (head or worker), and configures the cluster so that all nodes join the Ray process group.
Each pod in the cluster runs the same Ray Train DLC image. The role—whether head or worker—is determined at runtime by the command-line arguments passed when starting Ray, not by the container image itself. This design allows a single image to serve both roles, reducing image complexity and eliminating the need for separate head and worker images.

The head pod runs on a CPU-based m7i.xlarge instance and hosts the Ray head, which manages the global control store, job server, and dashboard. It does not have any GPUs assigned, so no training workloads are scheduled on it. The worker pods, running on the g6.12xlarge instances, each claim four GPUs and one EFA interface. Ray Train automatically distributes the training function across the eight GPUs, with four workers assigned to each instance.
Training Loop and Model Fine-Tuning
The training code is minimal and consists of a single Python function, train_func , which runs once per GPU. The function retrieves its rank and device from the Ray context, loads the Qwen2.5-1.5B model using Hugging Face, and applies FSDP to split the model’s weights, gradients, and optimizer state across the eight GPUs.
During each training step, the model performs a forward pass, where the weights are gathered across all ranks, and a backward pass, where gradients are reduce-scattered to ensure that each rank only updates its local slice of the model. This process is repeated in every step, and the full model is communicated between the two instances via the EFA path. The FSDP implementation ensures that memory usage is reduced by a factor of eight, making it feasible to train large models on hardware with limited memory per GPU.
Infrastructure and Deployment Flow
The entire deployment process is managed through a series of idempotent scripts, each designed to be safe and repeatable. The configuration is centralized in a single file, scripts/env.sh, which defines variables such as the AWS region, instance type, number of nodes, GPU count per node, and training parameters. These variables are used across all scripts and can be easily modified for different runs or environments.
The deployment sequence begins with find_gpu_capacity.sh, which scans available Availability Zones and regions to determine where g6.12xlarge instances are offered. It checks for both instance availability and on-demand capacity quotas, and uses a real Capacity Reservation to validate the actual launchability of the node group. This step ensures that the cluster is provisioned in a zone where the hardware is actually available and where capacity is sufficient.
Next, deploy_cluster.sh creates the EKS control plane, the VPC, the OpenID Connect (OIDC) provider, and the m7i.xlarge system node group. The system node group is deployed in subnets that are known to support g6.12xlarge instances, ensuring that the control plane is accessible and stable.
deploy_node_group.sh adds the two g6.12xlarge instances with EFA enabled. Each instance is labeled with role: gpu-worker and nvidia.com/gpu.present=true. The latter label is critical because it ensures that the NVIDIA device plugin detects the GPUs and runs its DaemonSet on the correct nodes. Without this label, the device plugin would fail to detect GPUs and no pods would be scheduled on the nodes.
install_gpu_plugins.sh ensures that both the NVIDIA and EFA device plugins are properly installed and functional. On newer versions of eksctl, these plugins are bundled into the node group, so the script may skip installation. Otherwise, it installs them at pinned versions and verifies that both nvidia.com/gpu and vpc.amazonaws.com/efa are allocatable on every GPU node.
install_kuberay.sh deploys the KubeRay operator to the system node, where it manages the Ray cluster lifecycle. The operator runs continuously and monitors the cluster for changes, automatically restarting pods if they fail or become unresponsive.
Finally, deploy_ray_train_job.sh renders the RayCluster manifest using envsubst and applies it to the cluster. It then waits for both worker pods to become ready and verifies that the head is accessible. Once confirmed, it copies the training code to the head pod and submits the job via kubectl exec using the Ray job submission API. The script streams logs from all eight ranks and exits only when the job completes or fails.

After the job runs, the script performs a final check to validate that the EFA path was used. If the job fails or if EFA is not detected, the script exits with an error, making it suitable for use as a continuous integration (CI) gate. The final state of the cluster is displayed using kubectl get nodes, showing the instance names, GPU count, and EFA availability.
Why This Approach Matters
Traditional distributed training setups often require teams to spend hours—sometimes days—aligning versions of CUDA, NCCL, and EFA. These components must be compatible across all nodes and must be built into a custom container image. Any mismatch results in degraded performance or complete failure, with NCCL falling back to TCP sockets, which can reduce throughput by orders of magnitude.
The Ray Train DLC eliminates this complexity by providing a pre-tested, integrated stack. AWS validates each release through multi-node EFA and KubeRay training tests, ensuring that the container is stable and performs well under real-world conditions. This allows developers to focus on their model and training logic rather than on low-level infrastructure alignment.
Because configuration is external to the container image, teams can modify training parameters—such as batch size, sequence length, or number of training steps—without rebuilding or re-pushing any images. Changes to the model, training loop, or Python packages are made in the code or configuration files, and the container remains unchanged. This makes the system highly reusable and scalable across different models and hardware setups.
Configuration Flexibility and Adaptability
The sample setup is designed to be easily adaptable to different workloads. For instance, if a team wants to change the model, they only need to update the MODEL_ID variable in env.sh. If they want to adjust training parameters such as steps or batch size, they can modify the STEPS, SEQ_LEN, or BATCH_SIZE variables. No changes to the container image or training code are required.
If an additional Python package is needed—such as a custom data loader or a specific library not included in the base image—the training job can specify it through the runtime_env parameter. Ray installs the package at submission time, and the container image remains unchanged. This allows teams to add new dependencies without re-building the image or managing version conflicts.
Changing the instance family—such as switching from g6.12xlarge to p5—requires only a change in the GPU_NODE_TYPE variable. The image and training code remain the same, and the p5 family supports GPUDirect RDMA, which can further improve performance and reduce memory overhead. The EFA device plugin includes support for g6.12xlarge, and moving to a GPUDirect-capable family does not require any changes to the container or training code.
Limitations and Areas for Improvement
While the sample demonstrates a successful distributed training run, it has several limitations that must be addressed for real-world deployment.
In real-world applications, training requires actual datasets, data loading pipelines, and model checkpoints. The current setup does not include any mechanism for persistent storage or model checkpointing, which are essential for long-running training jobs.
Second, failure handling is minimal. The current setup does not include any form of automatic recovery from node failures. If one of the g6.12xlarge instances crashes, the training job will fail, and no recovery mechanism is in place. To address this, teams can enable FailureConfig in Ray Train, which allows long-running jobs to survive a node failure by restarting the worker pod on a different node.

Third, while EFA supports cross-AZ communication, the sample runs in a single Availability Zone to avoid latency. Cross-zone communication is not tested, and the performance characteristics under such conditions are unknown. For production workloads requiring high availability, teams may need to evaluate multi-zone deployments with EFA.
Fourth, performance gains are measured only against the TCP fallback. There is no data on actual throughput under real-world workloads, such as training with large datasets or complex models. The sample does not provide benchmarks or performance metrics for different model sizes or training durations.
Performance on larger models or different architectures, such as vision-language models or transformer-based models with different attention mechanisms, is not evaluated. This limits the generalizability of the results.
Next Steps and Future Enhancements
Teams can extend this setup in several directions to meet real-world needs:
- Replace random batches with real datasets: Integrate real-world datasets from Hugging Face, Amazon S3, or Amazon FSx for Lustre. This would require building a data loading pipeline using PyTorch DataLoader or Ray Data.
- Implement model checkpoints: Save model weights at regular intervals to Amazon S3 or Amazon FSx for Lustre. This allows training to be resumed after a failure or to be shared across teams.
- Pin the DLC image to a versioned tag: Use a versioned tag such as train-ml-cuda-v1.1 to ensure reproducibility. This is critical for experiments where consistent results are required across runs.
- Enable FailureConfig: Allow long-running training jobs to survive node failures by automatically restarting workers on healthy nodes. This improves fault tolerance and reduces downtime.
- Move to GPUDirect RDMA instance families: Use instance families like p5, which support RDMA and offer higher bandwidth and lower latency. The same container and training code can be reused, with performance improvements due to direct GPU memory access.
Additionally, future work could explore integration with AWS SageMaker, which provides managed training jobs and model deployment services. By combining Ray Train with SageMaker, teams could achieve end-to-end AI workflows—from training to inference—without managing infrastructure.
The Ray Train DLC is designed to work with any PyTorch-based training loop. As long as the model and data are compatible, the same code can be reused across different hardware configurations, model sizes, and training scenarios. This makes it a powerful tool for both research and production AI workflows.
For more details, see the original AWS blog post: Distributed Training with Ray Train DLCs and EFA on ES.
For PyTorch documentation on FSDP, see PyTorch.
For NVIDIA’s NCCL documentation, see CUDA Platform Guide.
For NCCL technical details, see NVIDIA NCCL Developer Site.
Sources & further reading
Featured image: original publisher image. Via original publisher. Image source

