执行摘要
- 一句话:新增 GLM-5.2 模型在 Ascend NPU 上的 32 节点 GRPO 训练示例脚本。
- 推荐动作:该 PR 是一个有价值但无需精读代码的示例脚本提交。值得精读的程度较低,因为变更仅为一个 Shell 脚本,不涉及核心逻辑。但值得关注的设计决策和配置包括:
- 如何为 GLM-5.2 这类 MoE 模型在 32 节点规模下配置专家并行(EP=64)和推理并行(INFER_EP=64)。
- 针对 Ascend NPU 优化的 Megatron 配置细节,如
use_fused_rmsnorm=True,experimental_attention_variant="dsa"。
- GRPO 算法的具体参数设置(如
clip_ratio_low=0.2, clip_ratio_high=0.28),这反映了该训练配方的具体调优思路。
功能与动机
为 GLM-5.2 模型提供在 Ascend NPU 硬件上进行大规模(32 节点)强化学习训练的可运行示例。PR body 中明确指出脚本用于在 DAPO-Math-17k 数据集上,结合 Megatron 和 vLLM-Ascend 进行 GLM-5.2 的 GRPO 训练,并强调需要设置环境变量 VERL_VLLM_ASCEND_GLM52_PATCH=1。
实现拆解
- 新增训练脚本:在
examples/ascend_extras/grpo_trainer/ 目录下新增 run_glm5_2_megatron.sh 脚本,作为 PR 的唯一变更文件,提供了完整的训练启动命令和配置。
- 环境与硬件检查:脚本开头通过
python3 检查 torch.npu.is_available(),确保运行在 Ascend NPU 设备上,并打印详细的依赖版本信息(vllm, megatron, mindspeed 等)。
- 训练配置定义:脚本内部通过变量定义了关键的训练参数,包括:并行度(PP=8, TP=8, EP=64, INFER_TP=8, INFER_DP=8, INFER_EP=64)、训练批次大小、序列长度(2K prompt, 6K response)、以及 GRPO 算法参数(KL 损失系数、裁剪比率等)。
- 命令行参数构建:将上述配置组装成
DATA_ARGS, MODEL_ARGS, ALGORITHM_ARGS, ACTOR_ARGS 等数组,最终传递给 verl-trainer 命令。
- 依赖环境说明:脚本头部注释明确列出了运行所需的 vllm, megatron, mindspeed 等软件栈的具体版本和 Commit ID,为用户复现环境提供精确指引。
关键文件:
examples/ascend_extras/grpo_trainer/run_glm5_2_megatron.sh(模块 训练示例;类别 other;类型 core-logic): PR 的唯一变更文件,是完整的 GLM-5.2 在 Ascend 上的 32 节点 GRPO 训练脚本,包含了所有环境、硬件、模型和算法配置。
关键符号:未识别
关键源码片段
examples/ascend_extras/grpo_trainer/run_glm5_2_megatron.sh
PR 的唯一变更文件,是完整的 GLM-5.2 在 Ascend 上的 32 节点 GRPO 训练脚本,包含了所有环境、硬件、模型和算法配置。
#!/bin/bash
# Usage:
# 0. This script is designed to run on Ascend NPUs. Nvidia/AMD GPUs are not supported
# 1. Start a ray cluster of 32 nodes
# 2. Run this script to start the training job
# ... ( 依赖版本声明部分省略 ) ...
set -x
# Stop before configuring training if this machine has no available Ascend NPUs.
if ! python3 -c 'import torch; import torch_npu; raise SystemExit(not torch.npu.is_available())'; then
echo "Error: This script requires available Ascend NPUs." >&2
exit 1
fi
# Project Configuration
project_name='verl_megatron_dapo_math_17k_examples'
experiment_name='glm5_2-32nodes'
# Model Weights Paths
MODEL_PATH=${WORK_DIR}/glm52_weights
RAY_DATA_HOME=${RAY_DATA_HOME:-"${HOME}/verl"}
CKPTS_DIR=${CKPTS_DIR:-"${RAY_DATA_HOME}/ckpts/${project_name}/${experiment_name}"}
# ... ( 文件系统路径、训练配置省略 ) ...
NNODES=32
# Train config
PP=8
TP=8
EP=64
ETP=1
CP=1
INFER_TP=8
INFER_DP=8
INFER_EP=64
# ... ( 其他超参数省略 ) ...
# Actor Model Configuration - 关键并行配置示例
ACTOR_ARGS=(
actor_rollout_ref.actor.megatron.pipeline_model_parallel_size=$PP
actor_rollout_ref.actor.megatron.tensor_model_parallel_size=$TP
actor_rollout_ref.actor.megatron.expert_model_parallel_size=$EP
actor_rollout_ref.actor.megatron.expert_tensor_parallel_size=$ETP
actor_rollout_ref.actor.megatron.context_parallel_size=$CP
actor_rollout_ref.actor.megatron.override_transformer_config.sequence_parallel=True
actor_rollout_ref.actor.megatron.param_offload=True
actor_rollout_ref.actor.megatron.optimizer_offload=True
# ... ( 更多 Megatron 和 GRPO 配置 ) ...
)
评论区精华
Review 中的核心讨论集中在提升脚本的易用性和健壮性:
- 环境变量处理:评审者
wucong25 建议将 export VERL_VLLM_ASCEND_GLM52_PATCH=1 默认添加到脚本中,而不是依赖用户手动设置。作者 lxb007981 表示已修复此问题,从最终提交的脚本看,脚本开头确实添加了 export VERL_VLLM_ASCEND_GLM52_PATCH=1,并移除了原有对用户手动设置的依赖描述。
- 硬件平台声明:
wucong25 建议在脚本注释中明确说明当前仅支持 Ascend NPU,不支持 NVIDIA 和 AMD GPU。作者同样表示已修复,最终脚本在 Usage 注释中明确标注了 “This script is designed to run on Ascend NPUs. Nvidia/AMD GPUs are not supported”。
- 讨论结论与状态:两个主要问题均已由作者在提交前修复,评审者
wuxibin89 最终批准了 PR。整个讨论过程高效,聚焦于用户友好性和文档清晰度。
- 脚本用户友好性改进 (documentation): 作者
lxb007981 接受建议并已修复。最终脚本在开头自动设置了环境变量,并在 Usage 注释中明确标注了硬件限制。
风险与影响
关联脉络
- PR #7779 [vllm, hardware] fix: patch vllm-ascend for GLM-5.2 RL training on Ascend NPUs: 本 PR 的训练脚本依赖于 PR#7779 引入的 vllm-ascend 补丁(通过环境变量 VERL_VLLM_ASCEND_GLM52_PATCH 激活),两者是功能上的配套关系。
- PR #7604 [megatron, ci] chore: upgrade Ascend stack to Megatron 0.18.0: 本脚本依赖的 Megatron 和 MindSpeed 版本与 PR#7604 升级后的 Ascend 技术栈一致,属于同一升级浪潮下的示例补充。
- PR #7724 [veomni] feat: add async_activation_offload config: 同属为 Ascend/NPU 硬件生态增加训练支持和优化能力的系列工作,虽然引擎不同(Megatron vs VeOmni),但方向一致。
参与讨论