Prhub

#7101 [docker] feat: upgrade vllm and megatron version, add packages to support DeepSeek-V4

原始 PR 作者 ETOgaosion 合并时间 2026-07-28 14:00 文件变更 46 提交数 23 评论 6 代码增减 +521 / -115

执行摘要

升级 vLLM 至 0.24.0 与 Megatron 至 core_v0.18.0,支持 DeepSeek-V4

根据PR标题和body,升级目的是支持DeepSeek-V4模型训练,同时跟随vLLM 0.24.0和Megatron core_v0.18.0的版本更新以获取新特性与修复。Issue评论指出新版本中 transformers 版本不易统一,因此选择在Docker镜像中固定版本。

此PR值得精读,尤其是vllm_fp8_utils.py中面向vLLM版本的动态类型解析设计,可用于其他跨版本兼容场景。Dockerfile参数化改进和CI简化建议可作为后续基础设施变更的参考。建议在合并后尽快触发一轮端到端训练测试验证MoE兼容层。

讨论亮点

主要讨论集中在两个方面:

  • Gemini Code Assist bot 指出 Dockerfile 中 vllm-omni 版本硬编码为 0.24.0,建议使用新定义的 VLLM_OMNI_VERSION 构建参数以确保一致性(docker/Dockerfile.stable.vllm)。
  • wuxibin89 询问是否可以移除 CI 中运行时安装 megatron-bridge 和 Megatron-LM 的步骤,HollowMan6 和 ETOgaosion 确认这些依赖已内置在镜像中,可以安全移除(.github/workflows/e2e_ppo_trainer_megatron_vllm.yml)。

实现拆解

  1. Docker镜像更新:修改 docker/Dockerfile.stable.vllm 和 docker/Dockerfile.stable.sglang,将vLLM安装从源码编译改为pip预编译包,引入 VLLM_OMNI_VERSION 构建参数;同步更新Megatron桥接库版本。
  2. CI工作流简化:在 .github/workflows/e2e_ppo_trainer_megatron_vllm.yml 等文件中移除运行时安装megatron-bridge和Megatron-LM的步骤(这些依赖已内置在镜像中)。
  3. vLLM MoE兼容抽象层:在 verl/utils/vllm/vllm_fp8_utils.py 中新增 _is_expert_weight_module、_is_fused_moe_block、_resolve_expert_weight_module 三个函数,处理vLLM 0.24.0中FusedMoE从类变为工厂函数的重构;修改 get_module_from_param_name 使用新函数。
  4. 其他兼容适配:verl/utils/reward_score/prime_code/testing_util.py 用 module_from_string 替代未维护的 pyext;verl/trainer/constants_ppo.py 转发 PYTHONPATH 到Ray workers;更新 setup.py 中的依赖。
文件 模块 状态 重要度
verl/utils/vllm/vllm_fp8_utils.py MoE 兼容层 modified 8.07
tests/utils/test_vllm_fp8_utils_moe_on_cpu.py MoE 测试 added 7.75
verl/utils/reward_score/prime_code/testing_util.py 奖励评分 modified 6.33
verl/trainer/constants_ppo.py 运行时配置 modified 5.0
docker/Dockerfile.stable.vllm Docker 构建 modified 5.08
.github/workflows/e2e_ppo_trainer_megatron_vllm.yml CI 工作流 modified 4.49

关键符号

_is_expert_weight_module _is_fused_moe_block _resolve_expert_weight_module get_module_from_param_name module_from_string get_ppo_ray_runtime_env

关键源码片段

verl/utils/vllm/vllm_fp8_utils.py dependency-wiring

核心兼容层:适配 vLLM 0.24.0 MoE 重构,新增 `_is_expert_weight_module`、`_is_fused_moe_block` 等函数,确保 fp8 权重遍历在类 / 函数两种布局下正确工作。

# 模块加载时检测 FusedMoE 是类还是工厂函数,以兼容 vLLM 0.24.0 的重构。
if isinstance(FusedMoE, type):
    # vLLM < 0.24: FusedMoE 自身就是包含专家权重的 Module 类
    _MOE_STOP_CLASSES = (FusedMoE,)
    _EXPERT_WEIGHT_CLASSES = (FusedMoE,)
else:
    # vLLM >= 0.24: FusedMoE 是工厂函数,权重位于 RoutedExperts 子模块
    _stop_classes: list[type] = []
    _weight_classes: list[type] = []
    try:
        from vllm.model_executor.layers.fused_moe import RoutedExperts
        _stop_classes.append(RoutedExperts)
        _weight_classes.append(RoutedExperts)
    except ImportError:
        pass
    try:
        from vllm.model_executor.layers.fused_moe import MoERunner
        _stop_classes.append(MoERunner)
    except ImportError:
        pass
    _MOE_STOP_CLASSES = tuple(_stop_classes)
    _EXPERT_WEIGHT_CLASSES = tuple(_weight_classes)
​
def _is_expert_weight_module(module) -> bool:
    # 判断 module 是否直接拥有融合专家权重 (w13_weight / w2_weight)
    if _EXPERT_WEIGHT_CLASSES and isinstance(module, _EXPERT_WEIGHT_CLASSES):
        return True
    return hasattr(module, "w13_weight") and hasattr(module, "w2_weight")
​
def _is_fused_moe_block(module) -> bool:
    # 判断 module 是否为融合 MoE 块 ( 遍历模块树时需停止深入 )
    if _MOE_STOP_CLASSES and isinstance(module, _MOE_STOP_CLASSES):
        return True
    return hasattr(module, "routed_experts") or _is_expert_weight_module(module)
​
def _resolve_expert_weight_module(module):
    # 返回实际拥有专家权重的子模块 (>=0.24 时为 routed_experts, 否则为自身 )
    routed_experts = getattr(module, "routed_experts", None)
    if routed_experts is not None:
        return routed_experts
    return module

评论区精华

VLLM_OMNI_VERSION 参数化 设计

gemini-code-assist bot 指出 vllm-omni 版本硬编码为 0.24.0,建议使用新定义的 VLLM_OMNI_VERSION 构建参数以确保一致性。

结论:未见作者明确回应,但最终代码已使用参数化版本(根据后续提交推断)。 · 已解决

CI 移除运行时 Megatron 安装 设计

wuxibin89 询问是否可移除 CI 中 on-fly megatron-bridge 和 Megatron-LM 安装。HollowMan6 和 ETOgaosion 确认这些依赖已内置在镜像中,可以移除。

结论:确认移除,CI 文件已相应更新。 · 已解决

风险与影响

  1. MoE兼容风险:新的抽象层仅通过单元测试模拟验证,尚未在真实全精度训练或多种量化配置(FP8, MXFP8)下全面测试,可能出现权重遍历遗漏。
  2. CI可靠性风险:移除运行时安装后,如果镜像构建不及时或缺失依赖,CI可能失效;目前仅更新了部分CI文件,其他工作流(megatron_sglang等)是否一致未明确。
  3. DeepSeek-V4支持:新增依赖包和版本升级是否足够支撑DeepSeek-V4训练尚未经过端到端验证。
  4. 回归风险:vllm_fp8_utils.py 中 get_module_from_param_name 的修改可能影响所有使用fp8权重的路径;module_from_string 替换 pyext 可能改变错误处理行为。

用户影响:使用vLLM 0.24.0和Megatron core_v0.18.0后,基于旧版本的Docker镜像不再兼容,需重新构建;训练流程无API变化。系统影响:CI流程简化,构建速度可能提升;奖励评分模块不再依赖pyext,提升Python 3.12兼容性。团队影响:需要确认所有CI镜像已同步更新;后续DeepSeek-V4训练需基于此PR构建。

依赖版本升级兼容 MoE 模块重构风险 CI 流程变更 DeepSeek-V4 支持待验证

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论