执行摘要
- 一句话:为 Ascend NPU 添加 sglang CI 工作流
- 推荐动作:值得关注的设计决策:使用 common_params 数组重构冗长的 python 参数调用,这是一种常见的脚本优化模式。但务必验证 review 中指出的版本兼容问题是否已解决。该 PR 为 NPU sglang CI 的基石,后续 NPU 相关 PR 可参考此模板。
功能与动机
PR #6015 旨在为 Ascend NPU 添加持续集成(CI)覆盖 sglang 后端,确保 NPU 上 sglang rollout 功能的可靠性。PR body 提及 'All CI test cases have been tested locally and executed successfully',说明本地验证通过。
实现拆解
- 新增 CI Workflow 文件:在 .github/workflows/ 创建 reward_model_sglang_ascend.yml、e2e_ppo_trainer_megatron_sglang_ascend.yml、e2e_ppo_trainer_megatron_sglang_2_ascend.yml,分别定义 reward model 和 PPO 端到端测试的 Job,配置 Ascend NPU 运行环境、路径触发、超时 60 分钟。
- 重构 Megatron 测试脚本:在 tests/special_e2e/run_ppo_trainer_megatron.sh 中,将原本直接调用
python -m verl.trainer.main_ppo 的长参数改为先构建 common_params 数组再引用,减少重复;新增 SUPPORT_NPU 变量和 NPU 相关配置(如 flash attention、profiling 调整),使脚本可同时适配 GPU 与 NPU。
- 调整 CI 触发路径:各 workflow 通过
paths 字段精准控制触发条件,避免不必要的 CI 运行,例如对 docker/**、docs/**、examples/** 等目录排除。
- 删除旧式参数传递方式,提升脚本可维护性。
关键文件:
tests/special_e2e/run_ppo_trainer_megatron.sh(模块 测试脚本;类别 test;类型 test-coverage): 核心测试脚本,重构参数组织方式并加入 NPU 支持,是 CI 执行的关键入口。
.github/workflows/reward_model_sglang_ascend.yml(模块 CI 工作流;类别 infra;类型 infrastructure): 新增 CI 工作流,用于在 Ascend NPU 上测试 reward model + sglang 组合。
.github/workflows/e2e_ppo_trainer_megatron_sglang_ascend.yml(模块 CI 工作流;类别 infra;类型 infrastructure): 新增端到端 PPO 训练 + sglang rollout CI,覆盖 Megatron 后端在 NPU 上的主要训练流程。
.github/workflows/e2e_ppo_trainer_megatron_sglang_2_ascend.yml(模块 CI 工作流;类别 infra;类型 infrastructure): 另一套 e2e PPO 训练 CI,参数与上一个相似但可能测试不同模型或配置,增加覆盖范围。
关键符号:未识别
关键源码片段
tests/special_e2e/run_ppo_trainer_megatron.sh
核心测试脚本,重构参数组织方式并加入 NPU 支持,是 CI 执行的关键入口。
# 重构后的 common_params 数组统一了所有 Hydra 配置参数,
# 避免重复拼写 python 命令,提升可维护性。
common_params=(
algorithm.adv_estimator="${ADV_ESTIMATOR}"
data.train_files="${TRAIN_FILES}"
data.val_files="${VAL_FILES}"
data.train_batch_size=${train_prompt_bsz}
data.max_prompt_length=${MAX_PROMPT_LENGTH}
data.max_response_length=${MAX_RESPONSE_LENGTH}
data.return_raw_chat=${RETURN_RAW_CHAT}
actor_rollout_ref.model.path="${MODEL_PATH}"
actor_rollout_ref.actor.ppo_mini_batch_size=${train_prompt_mini_bsz}
# ... 后续参数以相同方式追加
)
# 最后通过 "${common_params[@]}" 展开传给 trainer
python3 -m verl.trainer.main_ppo \
--config-path=config \
--config-name='ppo_megatron_trainer.yaml' \
"${common_params[@]}"
评论区精华
- gemini-code-assist[bot] 指出 Dockerfile 中
torch==2.7.1 与 sgl-kernel-npu 内置 torch2.8.0 版本不匹配,可能导致二进制不兼容(评论路径 docker/ascend/Dockerfile.ascend.sglang_8.5.0_a2 和 a3)。
- 同一 bot 建议清理下载的
.zip 和 .whl 文件以减小镜像大小,并移除 --no-check-certificate 降低安全风险。
- yyyy2000 建议在 workflow 中也删除
"${HOME}/profiling" 目录(文件 .github/workflows/e2e_ppo_trainer_megatron_sglang_ascend.yml 第 145 行)。
- PyTorch 版本与 sgl-kernel-npu 不匹配 (correctness): 未在 thread 中看到明确修复;可能 PR 已经调整版本或该问题在后续提交中解决。
- Dockerfile 中清理下载文件与安全证书跳过 (security): 未看到回复,可能未采纳或已经在后续更新中处理。
- CI 工作流中删除 profiling 目录 (other): 未在 thread 中看到回应,但该建议较为合理,可能被采纳。
风险与影响
- 风险:
- 版本兼容风险:review 指出的 PyTorch 版本 mismatch 若未修复,sgl-kernel-npu 可能在运行时崩溃。
- 镜像安全:Dockerfile 使用
--no-check-certificate 下载,中间人攻击风险;下载后未清理,镜像膨胀。
- CI 覆盖盲区:workflow 的路径排除列表可能遗漏关键入口(如
verl/trainer/main_*.py 被排除),导致部分变更不触发 CI。
- NPU 环境稳定性:NPU 硬件/驱动可能出现偶发故障,CI 超时 60 分钟可能不足。
- 影响:影响范围限于 Ascend NPU 上的 CI 流程。新增三个 workflow 使 sglang 后端在 NPU 上获得自动化测试覆盖,减少回归风险。重构后的测试脚本更易维护,参数扩展性更好。对现有 GPU CI 无影响。
- 风险标记:版本兼容风险, 安全证书跳过, 镜像清理遗漏, CI 覆盖盲区
关联脉络
- PR #6291 [doc] chore: update vllm and vllm ascend from 0.13.0 to 0.18.0 in docs and dockerfile: 同样涉及 NPU 和 sglang 版本更新,与本文 CI 的工作流环境相关。
- PR #6307 [vllm] refactor: MXFP8 support for ascend NPU: NPU 相关重构,与本文 CI 覆盖的 NPU 测试路径可能有交集。
参与讨论