verl 算法基线评测指南:基于 GSM8k / DAPO-Math-17k / LeetCode 的 RL 后训练复现与结果速查
2026/9/12 6:40:28 网站建设 项目流程

verl 算法基线评测指南:基于 GSM8k / DAPO-Math-17k / LeetCode 的 RL 后训练复现与结果速查

【免费下载链接】verlverl/HybridFlow: A Flexible and Efficient RL Post-Training Framework项目地址: https://gitcode.com/GitHub_Trending/ve/verl

本篇指南围绕 verl(HybridFlow)在数学与代码推理任务上的**算法基线(Algorithm Baselines)**展开,系统整理仓库文档记录的 GSM8k、DAPO-Math-17k、LeetCode 等数据集上的 RL 后训练评测结果,并给出从数据预处理、奖励函数实现到训练脚本调用的完整复现路径。读完本文,你将掌握 verl 中各主流算法(PPO、GRPO、GRPO-LoRA、ReMax、SPPO、SPIN、GPG、RLOO、PRIME、DAPO 等)在数学推理任务上的典型分数区间、不同训练后端(FSDP / FSDP2 / Megatron)的配置差异,以及影响复现结果的几个关键参数(如entropy_coeff、答案提取格式)。

一、文档定位与基线总览

baseline.md 是 verl 官方维护的可复现基准速查表,其核心价值在于:给定一份经过标准预处理的评测数据集,读者可以按表中记录的"硬件 + 模型 + 方法"组合,直接复现对应的 RL 训练并对照测试分数。文档覆盖三个任务族:

  • 数学推理:GSM8k(主流评测集)与 DAPO math-17k(训练集,配合 AIME'24 测试);
  • 代码推理:LeetCode(文档标注"Below is the result on leetcode if not specified otherwise");
  • 多模态数学:GEO3k(作为 Qwen2.5-VL 的评测集)。

文档末尾还附了两条直接影响复现结果的注意事项:

  1. 部分早期实验(表中标注[1]的项)在评测时仅按"####"格式提取答案,更灵活的答案提取、更长的响应长度与更好的提示词工程可以进一步提升分数;
  2. 自 verl 0.3.x(2025-05-30)起,actor_rollout_ref.actor.entropy_coeff的默认值已改为0.0,与早期版本不同,复现旧结果时必须显式对齐该参数。

注意:表中分数为文档记录的历史实验数据,随模型版本、提示词、解码参数与评测提取规则变化,复现时以实际运行为准;仓库内 recipe 目录(recipe/,当前为空)在文档发布时计划存放更全面的 benchmark 结果。

二、数学数据集与预处理:GSM8k

2.1 数据来源与预处理命令

GSM8k 采用openai/gsm8k原始数据,通过仓库自带的预处理脚本转换为 verl 训练所需的 parquet 格式:

python3 examples/data_preprocess/gsm8k.py

该脚本(examples/data_preprocess/gsm8k.py)的核心逻辑:

  • 从 HuggingFace 加载openai/gsm8ktrain/test两个 split;
  • 对每条样本的question追加指令后缀Let's think step by step and output the final answer after "####".,强制模型以####标记最终答案;
  • 用正则#### (\-?[0-9\.\,]+)answer中提取标准答案作为ground_truth
  • 输出字段结构为data_sourceprompt(Chat 格式的 user 消息)、ability: "math"reward_model: {style: "rule", ground_truth: solution}extra_info

默认输出目录为~/data/gsm8k/,生成train.parquettest.parquet;支持--local_dataset_path指定本地数据集(离线环境)、--local_save_dir指定保存目录(--local_dir已废弃但保留兼容),以及--hdfs_dir将结果同步到 HDFS(底层复用 verl/utils/hdfs_io.py 的copy/makedirs)。

2.2 GSM8k 奖励函数实现

预处理阶段抽取的ground_truth与推理阶段模型的输出做匹配,即构成规则奖励。对应实现位于 verl/utils/reward_score/gsm8k.py:

  • extract_solution(solution_str, method="strict"|"flexible")
    • strict:正则#### (\-?[0-9\.\,]+)提取,且要求模型确实输出了####格式(同时检验了格式规范性),取最后一个匹配并去掉逗号;
    • flexible:仅取文本中最后一个合法数字,不要求####前缀;
    • 实现细节:对超长输出仅匹配末尾 300 个字符_SOLUTION_CLIP_CHARS = 300),因为数学题的最终答案通常出现在末尾,可显著降低超长字符串上的正则匹配开销;
  • compute_score(solution_str, ground_truth, method, format_score=0.0, score=1.0):提取失败返回 0;提取成功且与 ground truth 相等返回score(默认 1.0),否则返回format_score(默认 0.0)。

这也解释了文档 Note [1]:strict 模式要求####格式,若评测时改用 flexible 模式或更长的响应上限,分数会更高。

2.3 数学数据集(MATH)

GSM8k 的姊妹数据集 MATH 由 examples/data_preprocess/math_dataset.py 处理:加载DigitalLearningGmbH/MATH-lighteval(原lighteval/MATH已下线),提示词后缀改为Let's think step by step and output the final answer within \boxed{}.,答案通过 verl/utils/reward_score/math_reward.py 的last_boxed_only_string/remove_boxed\boxed{}中提取。多个数学训练脚本(如 GRPO Megatron 示例)会同时传入 GSM8k 与 MATH 两份数据:

gsm8k_train_path=$HOME/data/gsm8k/train.parquet math_train_path=$HOME/data/math/train.parquet train_files="['$gsm8k_train_path', '$math_train_path']"

2.4 GSM8k 算法基线结果表

以下为文档记录、默认在GSM8k评测集上的结果(除非另行说明):

硬件模型方法测试分数复现参考(仓库内对应脚本/文档)
NVIDIA GPUgoogle/gemma-2-2b-ithf checkpoint23.9官方模型基准
NVIDIA GPUgoogle/gemma-2-2b-itSFT52.06SFT 示例见 examples/sft/gsm8k/run_gemma_2b_fsdp.sh
NVIDIA GPUgoogle/gemma-2-2b-itSFT + PPO64.02examples/ppo_trainer/run_qwen3_8b_fsdp.sh(PPO 训练入口参考)
NVIDIA GPUQwen/Qwen2.5-0.5B-Instructhf checkpoint49.6官方模型基准
NVIDIA GPUQwen/Qwen2.5-0.5B-InstructPPO56.7PPO FSDP 训练入口参考
NVIDIA GPUQwen/Qwen2.5-0.5B-InstructPRIME58.7verl-recipe 的 prime 脚本(外部仓库)
NVIDIA GPUQwen/Qwen2.5-0.5B-InstructGRPO-LoRA54.3LoRA 调优见 examples/tuning/lora/
NVIDIA GPUQwen/Qwen2.5-1.5B-InstructGRPO-LoRA77.9同上
NVIDIA GPUQwen/Qwen2.5-3B-InstructGRPO-LoRA86.1同上
NVIDIA GPUdeepseek-ai/deepseek-llm-7b-chatPPO (Megatron)69.5 [1]Megatron PPO 配置见 verl/trainer/config/ppo_megatron_trainer.yaml
NVIDIA GPUQwen/Qwen2-7B-InstructGRPO89序列平衡 GRPO 脚本(文档引用的旧版 seq_balance 脚本)
NVIDIA GPUQwen/Qwen2-7B-InstructGRPO (FSDP2)89.8GRPO FSDP 训练参考 examples/grpo_trainer/
NVIDIA GPUQwen/Qwen2-7B-InstructGRPO (Megatron)89.6examples/grpo_trainer/run_qwen2-7b_math_megatron_fsdp.sh
NVIDIA GPUQwen/Qwen2.5-7B-InstructReMax97examples/remax_trainer/run_qwen2.5_math_7b_sync_fsdp.sh
NVIDIA GPUQwen/Qwen2.5-7B-InstructSPPO65.6 (MATH)verl-recipe 的 sppo 说明(外部仓库)
NVIDIA GPUQwen/Qwen2.5-7B-InstructGRPO-LoRA93.4LoRA 调优见 examples/tuning/lora/
NVIDIA GPUMixtral-8x22B-Instruct-v0.1Instruct model83.7官方模型基准
NVIDIA GPUMixtral-8x22B-Instruct-v0.1RLOO (Megatron)92.3RLOO 训练入口见 examples/rloo_trainer/
NVIDIA GPUQwen/Qwen2.5-7B-InstructSPIN92verl-recipe 的 spin 说明(外部仓库)
NVIDIA GPUQwen/Qwen2-7B-InstructGPG88GPG 训练见 examples/gpg_trainer/
NVIDIA GPUQwen/Qwen2-7B-InstructGPG (Megatron)88examples/gpg_trainer/run_qwen3_8b_megatron.sh
NVIDIA GPUQwen/Qwen2.5-VL-7B-InstructGRPO (Megatron)65.4 (GEO3k)examples/grpo_trainer/run_qwen2_5_vl_7b_megatron.sh
AMD MI300deepseek-ai/deepseek-llm-7b-chatPPO70.5 [1]AMD 运行环境见 docker/rocm/README.md
AMD MI300deepseek-ai/deepseek-llm-7b-chatGRPO71.4 [1]同上
NVIDIA GPUQwen/Qwen2.5-14B-InstructGRPO-LoRA94.6LoRA 调优见 examples/tuning/lora/
NVIDIA GPUQwen/Qwen2.5-32B-InstructGRPO-LoRA95.8同上
NVIDIA GPUQwen/Qwen2.5-72B-InstructGRPO-LoRA96.0同上

从表中可以读出的规律:GRPO-LoRA 系列随模型规模单调提升(0.5B 的 54.3 → 72B 的 96.0);同一模型在 FSDP2 与 Megatron 后端的 GRPO 分数高度一致(Qwen2-7B 分别为 89.8 / 89.6),说明后端选择主要影响吞吐与显存,而非算法上限。

三、数学数据集与预处理:DAPO math-17k

DAPO(Dynamic Actor Policy Optimization)实验采用专门的训练/测试数据对:

  • 训练集BytedTsinghua-SIA/DAPO-Math-17k(约 17k 条数学题,HuggingFace 公开数据集);
  • 测试集BytedTsinghua-SIA/AIME-2024(AIME'24 竞赛题)。

文档特别注明:对Qwen/Qwen2.5-Math-7B,为支持更长的响应长度,实验直接将max_position_embeddings扩展到 32768,且未观察到性能退化。

仓库内的预处理脚本 examples/data_preprocess/dapo_multiturn_w_tool.py 演示了如何把 DAPO-Math-17k 转成多轮 + 工具(Code Interpreter)格式:为每条样本的extra_info注入need_tools_kwargs=Truetools_kwargs.code_interpreter.create_kwargs.ground_truth,使沙箱工具可用答案做校验。纯文本(无工具)的 DAPO 复现脚本由 verl-recipe 外部仓库提供(test_dapo_7b_math.sh)。

硬件模型方法测试分数说明
NVIDIA GPUQwen/Qwen2.5-Math-7B (32k)DAPO36.3长上下文(32k)训练,AIME'24 测试
NVIDIA GPUQwen/Qwen2.5-7B-InstructDAPO + Code Interpreter40.0多轮工具调用 + 沙箱代码解释器

四、代码数据集:LeetCode 与 PRIME

文档在代码任务上记录的基线如下(默认评测集为LeetCode):

硬件模型方法测试分数说明
NVIDIA GPUPRIME-RL/Eurus-2-7B-SFTPRIME36.1代码推理 PRIME 训练

PRIME(Process Reinforcement through Implicit Rewards)的训练入口可参考仓库中 examples/data_preprocess/preprocess_search_r1_dataset.py 等代码类数据预处理脚本(PRIME 的具体训练脚本与评测记录位于 verl-recipe 外部仓库)。从源码结构看,verl 对这类"过程奖励 / 隐式奖励"算法主要通过algorithm.adv_estimator与自定义 reward manager 组合实现,可参考 verl/trainer/config/algorithm.py 中可用的优势估计器配置。

五、复现路径:从数据到训练脚本

5.1 完整复现链路

以 Qwen2.5-7B + ReMax 复现 GSM8k 97 分为例,链路为:

# 1) 预处理 GSM8k 与 MATH(生成 ~/data/gsm8k/*.parquet、~/data/math/*.parquet) python3 examples/data_preprocess/gsm8k.py python3 examples/data_preprocess/math_dataset.py # 2) 运行 ReMax 同步训练(vLLM rollout + FSDP 训练 + 同步 TransferQueue trainer) bash examples/remax_trainer/run_qwen2.5_math_7b_sync_fsdp.sh

该脚本(examples/remax_trainer/run_qwen2.5_math_7b_sync_fsdp.sh)的关键配置要点:

  • 算法algorithm.adv_estimator=remaxalgorithm.use_kl_in_reward=Truealgorithm.kl_penalty=klalgorithm.kl_ctrl.kl_coef=0.0
  • 数据data.train_batch_size=128data.max_prompt_length=1024data.max_response_length=2048data.filter_overlong_prompts=Truedata.truncation='error'
  • Actoractor_rollout_ref.actor.optim.lr=1e-6ppo_mini_batch_size=64、动态批大小(use_dynamic_bsz=True+ppo_max_token_len_per_gpu=24576)、use_kl_loss=False(KL 已并入奖励)、entropy_coeff=0(与文档 Note [2] 一致)、FSDP 不卸载参数/优化器、ulysses_sequence_parallel_size=2
  • Rollout:vLLM、tensor_model_parallel_size=2gpu_memory_utilization=0.7n=4采样;
  • 同步模式:通过+ray_kwargs.ray_init.runtime_env.env_vars.TRANSFER_QUEUE_ENABLE=1启用同步 TransferQueue trainer,入口为verl.trainer.main_ppo_sync

5.2 Megatron 后端复现:GRPO on GSM8k + MATH

examples/grpo_trainer/run_qwen2-7b_math_megatron_fsdp.sh 对应表中 Qwen2-7B GRPO (Megatron) 89.6 的复现脚本,展示了 verl 的 Megatron + FSDP 混合并行配置:

  • 并行:训练侧TP=4, PP=1actor_rollout_ref.actor.megatron.tensor_model_parallel_size/pipeline_model_parallel_size),use_megatron_fsdp=True+use_mbridge=True启用 Megatron-FSDP 混合并行与通信桥;生成侧独立设置GEN_TP=4actor_rollout_ref.rollout.tensor_model_parallel_size);
  • 数据train_files="['$gsm8k_train_path', '$math_train_path']"data.max_prompt_length=512data.max_response_length=512
  • 算法algorithm.adv_estimator=grpoalgorithm.use_kl_in_reward=False(KL 作为 actor loss 正则项)、actor_rollout_ref.actor.use_kl_loss=Truekl_loss_coef=0.001kl_loss_type=low_var_klentropy_coeff=0
  • Rolloutactor_rollout_ref.rollout.name=vllmmode=async(异步 rollout)、n=2gpu_memory_utilization=0.4
  • 运行环境:GPU 环境通过uv run --frozen --all-packages --extra vllm --extra megatron拉起 driver 与 Ray worker(ray_kwargs.ray_init.runtime_env.py_executable),NPU 环境回退到系统 Python;这是仓库当前推荐的在 GPU 上安装 verl 依赖的方式(见 README.md 与 docs/start/install.rst)。

5.3 训练入口与配置文件

所有 RL 训练脚本最终都汇聚到统一入口:

python3 -m verl.trainer.main_ppo --config-path=config --config-name='ppo_megatron_trainer.yaml' ... # Megatron 后端 python3 -m verl.trainer.main_ppo_sync ... # 同步 TransferQueue 后端

参数按命名空间分组(data.*actor_rollout_ref.model.*actor_rollout_ref.actor.*actor_rollout_ref.rollout.*actor_rollout_ref.ref.*algorithm.*trainer.*),底层由 verl/trainer/config/config.py 解析,各分组定义在 verl/trainer/config/ 下的data/model/actor/rollout/ref/algorithm/critic/reward/等子目录,完整的默认配置可通过verl/trainer/config/ppo_trainer.yamlverl/trainer/config/ppo_megatron_trainer.yaml等 YAML 模板查看(另有_generated_ppo_*_trainer.yaml为不同后端的生成物)。

六、复现注意事项与参数对齐

6.1 答案提取方式影响分数(Note [1])

表中标注[1]的实验(deepseek-llm-7b-chat PPO/GRPO 等)在评测时仅用"####"正则提取 GSM8k 答案。若需复现更高分:

  • 改用 verl/utils/reward_score/gsm8k.py 中的flexible提取模式(取最后一个合法数字);
  • 增大data.max_response_length,允许模型输出更完整的推理链;
  • 优化提示词工程(如显式要求输出格式)。

6.2 entropy_coeff 默认值变更(Note [2])

自 verl 0.3.x(2025-05-30)起,actor_rollout_ref.actor.entropy_coeff默认值为0.0,即默认关闭熵正则。复现更早版本记录的结果(尤其带[1]标注的 PPO 实验)时,需要在训练脚本中显式设置该参数以对齐旧行为。

6.3 长上下文训练

DAPO 实验将 Qwen2.5-Math-7B 的max_position_embeddings扩展到 32768 以容纳长响应,复现时需同步调整data.max_response_length与模型配置,并关注长序列下的显存占用(可参考 docs/perf/best_practices.rst 的调优建议)。

6.4 多硬件支持

基线同时覆盖 NVIDIA GPU(FSDP / FSDP2 / Megatron 多种后端)与 AMD MI300(ROCm,环境搭建见 docker/rocm/README.md);Ascend NPU 的对应示例位于 examples/ascend_extras/ 与 tests/special_npu/。

七、结语

baseline.md的价值在于把"算法 × 模型 × 硬件"的评测矩阵沉淀为可复现的起点:数据预处理脚本(examples/data_preprocess/)保证了数据口径一致,奖励函数(verl/utils/reward_score/)保证了打分规则一致,而各 trainer 目录(examples/grpo_trainer/、examples/remax_trainer/、examples/rloo_trainer/、examples/gpg_trainer/ 等)则提供了开箱即用的启动脚本。复现时只需对齐三个关键变量——数据预处理版本、entropy_coeff等超参、以及答案提取模式,即可在 verl 上获得与官方基线一致或更优的结果。

【免费下载链接】verlverl/HybridFlow: A Flexible and Efficient RL Post-Training Framework项目地址: https://gitcode.com/GitHub_Trending/ve/verl

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询