Compute

Ray Train DLC + EFA 在 EKS 八卡训练 Qwen2.5

The Ray Train Deep Learning Container ships the full CUDA-through-EFA stack, so you build no image. This post walks through a reproducible sample that fine-tunes Qwen2.5-1.5B with

Full article body is primarily in Chinese for SEO depth; key points above are localized. Use the language switcher and deep links for global navigation.

Ray Train DLC + EFA 在 EKS 八卡训练 Qwen2.5

Ray Train Deep Learning Container(DLC)与 Elastic Fabric Adapter(EFA)结合使用,能在 Amazon EKS 上轻松实现多机多卡训练,无需自行构建镜像即可完成 Qwen2.5-1.5B 的 FSDP 微调。本文适合有 AWS EKS 经验的团队或独立开发者,用于在八卡配置下验证分布式训练性能。决策时优先考虑实例类型与 EFA 节点数量:相同实例族下,节点越多通信开销越低,但需平衡成本与吞吐。

为什么 Ray Train DLC + EFA 值得在 EKS 上使用

AWS 官方博客 2026-10-28 发布的样例展示了 Ray Train DLC 的核心优势——它内置了完整 CUDA-through-EFA 栈,包括 PyTorch、NCCL、EFA、libfabric 和 aws-ofi-nccl 插件,所有组件已由 AWS 联合测试并发布到 public.ecr.aws 公共仓库。相比传统方式,你无需维护镜像、驱动匹配或网络插件的版本一致性问题。

在 EKS 环境中,KubeRay operator 创建 RayCluster 资源,一次 manifest 定义头节点与工作节点,DLC 镜像(tag 为 public.ecr.aws/deep-learning-containers/ray:train-ml-cuda-v1.1)同时运行头节点与工作节点。训练代码只需传入一个函数和 ScalingConfig,Ray Train 自动调度八个 GPU 上的 FSDP 并通过 EFA 实现跨节点集体通信。

这意味着你可以在不修改训练代码的情况下,切换实例族或节点规模,只需更新 manifest 与 env.sh 脚本。样例集群由一个 m7i.xlarge 系统节点(运行 KubeRay 和 Ray head)加两个 g6.12xlarge GPU 节点组成,每个 GPU 节点部署单个四卡工作 pod,整体成本约 9.5 美元/小时(含控制平面和 NAT Gateway)。

准备环境与部署流程

部署流程包含四步脚本,全部支持 idempotent 操作,可重复执行而不影响现有资源:

  1. 确认容量与 Region:运行 find_gpu_capacity.sh 探测 g6.12xlarge 在目标 Region 的 Availability Zone 是否可用,并检查 On-Demand vCPU 配额。
  2. 部署 EKS 集群与节点组:deploy_cluster.sh 创建 VPC、控制平面与 m7i.xlarge 系统节点;deploy_node_group.sh 添加两台 g6.12xlarge 实例并启用 EFA 接口。
  3. 安装设备插件:install_gpu_plugins.sh 确保 NVIDIA GPU 与 EFA 设备插件可分配 nvidia.com/gpu 与 vpc.amazonaws.com/efa。
  4. 部署 KubeRay operator:install_kuberay.sh 将 operator 安装到系统节点。

执行 ./deploy_all.sh 后,集群处于 Ready 状态。整个过程 20-30 分钟完成(含容量预留确认),无需手动配置节点标签或 EFA 设备映射。

训练代码与 manifest 配置

训练代码位于 code/train.py,完全与容器无关:

  • 每 GPU 运行 train_func,通过 ray.train.get_context 获取 world_size 与 rank。
  • 使用 Hugging Face Transformers 加载 Qwen2.5-1.5B(bfloat16),应用 FSDP 并设置 auto_wrap_policy(子模块 >10M 参数独立单元)。
  • PyTorch 普通训练循环 + AdamW + ray.train.report 监控 loss。
  • Driver 端:ray.init(address="auto"),统计 GPU 数量,创建 TorchTrainer 并 fit。

唯一依赖 RayCluster manifest(manifest/raycluster.yaml),worker group 仅指定镜像、环境变量(FI_PROVIDER=efa、NCCL_NET_PLUGIN=ofi 等)与资源请求。head 节点设置 NVIDIA_VISIBLE_DEVICES=void,防止 GPU hook 冲突。manifest 高度可复用,EFA 请求通过 EFA device plugin 自动挂载。

性能与成本对比

配置方式镜像构建工作量EFA 支持难度多节点性能成本(8卡运行)
传统 PyTorch + 手动镜像高高依赖 TCP更高(额外维护)
Ray Train DLC + EFA无无通过 EFA 提升 2倍+9.5 美元/小时

样例通过 EFA 实现跨 AZ 的 NCCL 通信,实际吞吐显著优于 TCP 回退。DLC 版本 pinned 为 train-ml-cuda-v1.1,可通过 digest 实现字节级复现。

延伸阅读

风险与边界

运行此方案需注意 EFA 设备仅支持特定实例族(如 g6.12xlarge),跨 AZ 通信受 VPC 限制;长时间训练可能因驱动兼容或 pod 驱逐导致中断;成本随实例时长线性增长,建议设置自动缩放或预留容量以控制预算。以上内容基于 AWS 官方 2026-10-28 样例,仅供参考,不构成任何商业或技术承诺。

Disclaimer:本文非法律意见,仅为技术说明参考。实际使用请以 AWS 控制台与文档当日数据为准。

English summary

The Ray Train Deep Learning Container combined with Elastic Fabric Adapter enables reproducible multi-node distributed training on Amazon EKS using only a single manifest and one training function. For the Qwen2.5-1.5B model with PyTorch FSDP across eight L4 GPUs on two g6.12xlarge instances, no custom image is built; the public DLC image public.ecr.aws/deep-learning-containers/ray:train-ml-cuda-v1.1 supplies the complete CUDA-to-EFA stack. KubeRay operator creates head and worker pods, Ray Train automatically schedules eight ranks and forms the distributed process group. EFA collectives achieve near 2x higher throughput than TCP fallback while the training script remains unchanged. The complete stack costs approximately $9.50 per hour and is fully reproducible via pinned tags and scripts. This approach scales to larger models or instance families with minimal code adjustments and is ideal for teams needing production-ready distributed LLM fine-tuning on Kubernetes without infrastructure maintenance.

适用于 GrokCode 倍率榜。信息仅供参考,不构成购买、投资或法律意见。