Prhub

#5900 [veomni] feat: bump veomni to v0.1.8

verl-project/verl · 作者 deerlu · 合并时间 2026-04-15 17:13

分析状态 已生成
文件变更 8提交数 1 · 评论 3
代码增减 +78 / -11
veomni trainer perf misc

执行摘要

升级 VeOmni 至 v0.1.8,修复并行参数并新增打包序列 Flash Attention 预处理。

根据PR body和Issue讨论,升级VeOmni至v0.1.8以修复并行状态初始化和支持Flash Attention。具体地,deerlu在Issue评论中确认已升级CI中的VeOmni版本,以使用新特性如参数修复和Flash Attention优化。

建议工程师精读此PR,重点关注_prepare_veomni_flash_attention_kwargs函数的实现细节和设备处理,以及配置自动重写机制的设计决策,这些对理解VeOmni集成和序列并行优化有参考价值。

讨论亮点

review中,gemini-code-assist[bot]指出_prepare_veomni_flash_attention_kwargs函数返回的张量可能设备不匹配,建议将cu_seq_lens等移动到与输入position_ids相同的设备。此建议可能已被采纳以确保正确性,但PR讨论中未显示具体修改。最终PR由wuxibin89批准合并。

实现拆解

  1. 依赖版本升级:更新多个CI工作流文件(如.github/workflows/e2e_ppo_trainer_veomni_vllm.yml),将VeOmni安装从@v0.1.4@v0.1.5改为@v0.1.8,并添加--ignore-requires-python --no-deps标志和固定transformers版本为4.57.3,确保测试环境一致性。
  2. 配置类增强:在verl/workers/config/engine.py中,为VeOmniEngineConfig添加_mutable_fields以允许attn_implementation可变,并在__post_init__中自动将flash_attention_2/3/4重写为对应的VeOmni SP-aware变体(如veomni_flash_attention_2_with_sp),通过日志记录变更。
  3. 核心逻辑实现:在verl/workers/engine/veomni/transformer_impl.py中:
    • 导入prepare_fa_kwargs_from_position_ids工具。
    • 修改parallel_state.init_parallel_state调用,将ep_size参数替换为extra_parallel_sizes元组。
    • 更新build_parallelize_model调用中的basic_modules,使用集合操作去重合并模块列表。
    • 新增_prepare_veomni_flash_attention_kwargs函数,支持2D和3D打包位置ID格式,调用VeOmni工具预计算cu_seq_lens和最大长度,并返回Flash Attention所需参数字典。
  4. 测试与文档配套:调整tests/special_e2e/sft/test_sft_engine_all.sh中的输出信息,更清晰地标识veomni后端测试;其他CI工作流同步更新依赖版本以覆盖veomni相关测试。
文件 模块 状态 重要度
verl/workers/engine/veomni/transformer_impl.py VeOmni 引擎 modified 7.36
verl/workers/config/engine.py 引擎配置 modified 6.08
.github/workflows/e2e_ppo_trainer_veomni_vllm.yml CI 流水线 modified 2.88
tests/special_e2e/sft/test_sft_engine_all.sh SFT 测试 modified 3.06
verl/workers/config/engine.py configuration

配置类文件,修改 VeOmniEngineConfig 以自动重写 attn_implementation,提升序列并行兼容性,并添加日志记录。

def __post_init__(self):
    super().__post_init__()
    assert self.strategy in ["veomni"], f"strategy {self.strategy} not supported"
​
    # 自动重写flash_attention实现为VeOmni序列并行感知版本,提升兼容性
    replacements = {
        "flash_attention_2": "veomni_flash_attention_2_with_sp",
        "flash_attention_3": "veomni_flash_attention_3_with_sp",
        "flash_attention_4": "veomni_flash_attention_4_with_sp",
    }
    if self.attn_implementation in replacements:
        new_impl = replacements[self.attn_implementation]
        logger.info(f"Replacing attn_implementation from '{self.attn_implementation}' to '{new_impl}'")
        self.attn_implementation = new_impl # 修改配置值以使用VeOmni优化版本

关键符号

_prepare_veomni_flash_attention_kwargs

评论区精华

设备匹配问题 正确性

gemini-code-assist[bot] 在 review 中建议,`_prepare_veomni_flash_attention_kwargs` 函数返回的 cu_seq_lens 张量应确保与输入 position_ids 设备一致,以避免运行时设备不匹配错误。

结论:建议可能被采纳以增强函数健壮性,但 PR 讨论未显示具体修改;最终 PR 已合并,推测问题已解决。 · 已解决

风险与影响

主要风险包括:1) 设备不匹配风险:如果prepare_fa_kwargs_from_position_ids返回CPU张量而模型在GPU/NPU运行,可能导致运行时错误;2) 依赖兼容性:升级VeOmni至v0.1.8可能引入不兼容变更,影响现有训练流程;3) 配置重写副作用:自动重写attn_implementation可能干扰用户显式配置,需确保日志清晰。风险集中在verl/workers/engine/veomni/transformer_impl.py的核心路径。

影响范围:使用VeOmni引擎进行序列并行训练的用户将受益于改进的Flash Attention支持和参数修复,提升训练性能和稳定性。影响程度中等:直接修改了引擎配置和核心预处理逻辑,但未改变高层API;CI测试更新确保覆盖veomni后端,保障持续集成可靠性。

设备匹配风险 依赖升级风险 配置重写副作用

关联 Issue

未识别关联 Issue

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

完整报告

执行摘要

  • 一句话:升级VeOmni至v0.1.8,修复并行参数并新增打包序列Flash Attention预处理。
  • 推荐动作:建议工程师精读此PR,重点关注_prepare_veomni_flash_attention_kwargs函数的实现细节和设备处理,以及配置自动重写机制的设计决策,这些对理解VeOmni集成和序列并行优化有参考价值。

功能与动机

根据PR body和Issue讨论,升级VeOmni至v0.1.8以修复并行状态初始化和支持Flash Attention。具体地,deerlu在Issue评论中确认已升级CI中的VeOmni版本,以使用新特性如参数修复和Flash Attention优化。

实现拆解

  1. 依赖版本升级:更新多个CI工作流文件(如.github/workflows/e2e_ppo_trainer_veomni_vllm.yml),将VeOmni安装从@v0.1.4@v0.1.5改为@v0.1.8,并添加--ignore-requires-python --no-deps标志和固定transformers版本为4.57.3,确保测试环境一致性。
  2. 配置类增强:在verl/workers/config/engine.py中,为VeOmniEngineConfig添加_mutable_fields以允许attn_implementation可变,并在__post_init__中自动将flash_attention_2/3/4重写为对应的VeOmni SP-aware变体(如veomni_flash_attention_2_with_sp),通过日志记录变更。
  3. 核心逻辑实现:在verl/workers/engine/veomni/transformer_impl.py中:
    • 导入prepare_fa_kwargs_from_position_ids工具。
    • 修改parallel_state.init_parallel_state调用,将ep_size参数替换为extra_parallel_sizes元组。
    • 更新build_parallelize_model调用中的basic_modules,使用集合操作去重合并模块列表。
    • 新增_prepare_veomni_flash_attention_kwargs函数,支持2D和3D打包位置ID格式,调用VeOmni工具预计算cu_seq_lens和最大长度,并返回Flash Attention所需参数字典。
  4. 测试与文档配套:调整tests/special_e2e/sft/test_sft_engine_all.sh中的输出信息,更清晰地标识veomni后端测试;其他CI工作流同步更新依赖版本以覆盖veomni相关测试。

关键文件:

  • verl/workers/engine/veomni/transformer_impl.py(模块 VeOmni引擎;类别 source;类型 core-logic;符号 _prepare_veomni_flash_attention_kwargs): 核心实现文件,包含参数修复、新函数添加和basic_modules优化,直接影响VeOmni引擎的并行初始化和Flash Attention预处理。
  • verl/workers/config/engine.py(模块 引擎配置;类别 source;类型 configuration): 配置类文件,修改VeOmniEngineConfig以自动重写attn_implementation,提升序列并行兼容性,并添加日志记录。
  • .github/workflows/e2e_ppo_trainer_veomni_vllm.yml(模块 CI流水线;类别 infra;类型 infrastructure): CI工作流文件,升级VeOmni依赖版本至v0.1.8,并调整安装参数,确保测试环境一致性和新功能验证。
  • tests/special_e2e/sft/test_sft_engine_all.sh(模块 SFT测试;类别 test;类型 test-coverage): 测试脚本,微调输出信息以更清晰地标识veomni后端测试,辅助验证升级后功能。

关键符号:_prepare_veomni_flash_attention_kwargs

关键源码片段

verl/workers/config/engine.py

配置类文件,修改VeOmniEngineConfig以自动重写attn_implementation,提升序列并行兼容性,并添加日志记录。

def __post_init__(self):
    super().__post_init__()
    assert self.strategy in ["veomni"], f"strategy {self.strategy} not supported"
​
    # 自动重写flash_attention实现为VeOmni序列并行感知版本,提升兼容性
    replacements = {
        "flash_attention_2": "veomni_flash_attention_2_with_sp",
        "flash_attention_3": "veomni_flash_attention_3_with_sp",
        "flash_attention_4": "veomni_flash_attention_4_with_sp",
    }
    if self.attn_implementation in replacements:
        new_impl = replacements[self.attn_implementation]
        logger.info(f"Replacing attn_implementation from '{self.attn_implementation}' to '{new_impl}'")
        self.attn_implementation = new_impl # 修改配置值以使用VeOmni优化版本

评论区精华

review中,gemini-code-assist[bot]指出_prepare_veomni_flash_attention_kwargs函数返回的张量可能设备不匹配,建议将cu_seq_lens等移动到与输入position_ids相同的设备。此建议可能已被采纳以确保正确性,但PR讨论中未显示具体修改。最终PR由wuxibin89批准合并。

  • 设备匹配问题 (correctness): 建议可能被采纳以增强函数健壮性,但PR讨论未显示具体修改;最终PR已合并,推测问题已解决。

风险与影响

  • 风险:主要风险包括:1) 设备不匹配风险:如果prepare_fa_kwargs_from_position_ids返回CPU张量而模型在GPU/NPU运行,可能导致运行时错误;2) 依赖兼容性:升级VeOmni至v0.1.8可能引入不兼容变更,影响现有训练流程;3) 配置重写副作用:自动重写attn_implementation可能干扰用户显式配置,需确保日志清晰。风险集中在verl/workers/engine/veomni/transformer_impl.py的核心路径。
  • 影响:影响范围:使用VeOmni引擎进行序列并行训练的用户将受益于改进的Flash Attention支持和参数修复,提升训练性能和稳定性。影响程度中等:直接修改了引擎配置和核心预处理逻辑,但未改变高层API;CI测试更新确保覆盖veomni后端,保障持续集成可靠性。
  • 风险标记:设备匹配风险, 依赖升级风险, 配置重写副作用

关联脉络

  • PR #5935 [ci] chore: Add veomni npu ci test: 同涉及VeOmni引擎的CI测试更新,关联veomni功能验证和依赖版本管理。

参与讨论