执行摘要
- 一句话:文档补充 MTP 全重计算需 Megatron #3457
- 推荐动作:值得快速浏览(尤其是 MTP + Megatron 用户):它把一个不易察觉的配置组合崩溃讲清楚了。值得借鉴的是两点决策——(1) 遇到上游 API 不兼容时先文档化约束而非打 shim;(2) 纯文档改动也要用可核查的方式(ast 解析 + commit 历史 bisect)验证事实,而不是 grep 了事。若团队后续要支持 recompute_granularity=full 的开箱即用,可考虑在新 dev commit 验证后 Bump pin 并简化该 bullet。
功能与动机
PR body 明确说明这是 #7326 的 follow-up:'the review outcome was that verl should document the required Megatron fix rather than carry a compatibility shim'。原文档把 Megatron dev 固定在 2025-12-09 的 23e092f41,而 #3457('Roll input IDs for MTP labels',2026-06-03)才是把 padding_mask 穿过 MultiTokenPredictionLayer._checkpointed_forward 的 commit,两者相差约半年。按原文档使用固定 commit 并开启 recompute_granularity=full 时,forward 会向未声明该参数的 _checkpointed_forward 传入 padding_mask,训练第一轮即抛 TypeError,因此需要在文档中把这一约束写明,而不是在 verl 侧打兼容补丁。
实现拆解
- 变更入口:仅修改 docs/advance/mtp.md,文件标题区 Last updated 由 02/15/2026 更新为 08/11/2026。
- 核心内容:在 §1 'Scope of Support' 的 megatron bullet 后追加条件约束——若额外开启 recompute_granularity=full,应使用包含 #3457 的 dev commit(ffd66a3e6,2026-06-03),并解释原因:缺少该 commit 时 MultiTokenPredictionLayer.forward 会把 padding_mask 传给未声明该参数的 _checkpointed_forward,导致首步 TypeError;同时提醒已发布的 megatron-core 0.18.0 与 0.18.2 均未包含修复,上游跟踪为 #4933。
- 设计取舍:刻意不移动既有 pin。作者在 body 中说明尚未在更新的 dev commit 上验证 MTP + CP,因此选择追加约束而不是静默替换他人已验证的 pin;如果社区有可信的新 dev commit,Bump pin 可以让 bullet 更简洁。
- 验证与配套:纯文档变更,无源码、测试或 CI 改动。作者用 ast 解析(而非 grep)逐个核查候选 ref 的 _checkpointed_forward 签名,并通过 gh api 对该文件提交历史做 bisect,确认 ffd66a3e6 是首个包含 padding_mask 参数的 commit;本地通过 check_docs_time_info.py 与 check_pr_title.py,两个新增链接均返回 HTTP 200。pre-commit 因环境限制未运行,作者指出 main 上存在来自 #7300 的无关失败。
关键文件:
docs/advance/mtp.md(模块 文档指南;类别 docs;类型 documentation): 唯一变更文件。在 §1 'Scope of Support' 的 megatron bullet 中追加 recompute_granularity=full 的版本约束(需包含上游 #3457),并更新 Last updated 日期;是本次文档修复的全部内容。
关键符号:未识别
评论区精华
本 PR 没有任何 inline review 评论,唯一审核是 wuxibin89 的空正文 APPROVED。核心讨论沉淀在 PR body 中:
- 方案取舍:#7326 的 review 结论是 verl 应把所需 Megatron 修复写进文档('document the required Megatron fix rather than carry a compatibility shim'),本 PR 即落实该结论,未新增任何兼容代码。
- pin 是否移动:作者明确 'I deliberately did not move the pin itself... I have not validated MTP + CP on a newer dev commit, and I would rather add the constraint than silently replace a pin someone else verified.',保留原 pin、只加约束。
- 核查方法:作者强调 grep 会误导(签名下方几行的调用点也含 padding_mask 字符串),因此用 ast 解析签名并做 commit 历史 bisect,表格列出 6 个候选 ref 的签名情况。
-
另注:pre-commit 3.12 在 main 上因 tests/trainer/ppo/test_reinforce_pp_multiturn_on_cpu.py(#7300 引入的 ruff-format diff)失败,与本 PR 无关。
-
是否移动 Megatron dev pin 还是仅追加约束说明 (design): 保持 pin 不动,仅在 recompute_granularity=full 分支追加需包含 #3457 的约束;wuxibin89 空正文 APPROVED 后合入。
- 文档事实核查方法:ast 解析而非 grep (other): 核查结论形成表格写入 PR body,确认固定 commit 与 0.18.0/0.18.2 均缺该参数,文档描述准确。
风险与影响
- 风险:
- 文档事实过时风险:pin 与说明依赖具体 commit(23e092f41、ffd66a3e6)及日期,Megatron-LM 上游持续演进,后续 dev 版本若再有签名变化,本说明需同步复核;目前是人工维护,无自动化校验。
- 误导风险:文档首行仍固定在不含 #3457 的 commit,用户若只读 pin 行而未注意追加约束,配合 recompute_granularity=full 仍会首步崩溃;追加约束在同一 bullet 内,可缓解但无法完全避免。
- 上游依赖风险:megatron-core 0.18.0 与 0.18.2 未携带修复(#4933 未关闭),用发行版的用户即使按文档也无法安全开启该配置,只能等待上游。
- 无代码回归风险:+2/-2 纯文档,不影响任何运行时路径或测试。
- 影响:影响范围较窄:仅涉及在 Megatron 上使用 MTP + CP 且开启 recompute_granularity=full 的用户,文档现在能明确告知可用版本与崩溃原因,避免首步 TypeError。对 verl 代码库无运行时影响、无 API 变化、无测试影响。对团队而言,该 PR 落实了 #7326 的'文档化而非 shim'决策,长期降低了 verl 侧维护兼容补丁的成本;同时为后续 MTP 文档维护立下一个需要人工同步上游 commit 的节点。
- 风险标记:纯文档变更, 依赖上游修复缺失, pin 易过时, 无自动化校验
关联脉络
- PR #7326 #7326(PR body 引用,材料中未提供标题): 本 PR 是其 follow-up:该 PR 的 review 结论确定以文档说明替代兼容 shim,docs/advance/mtp.md 中该 bullet 的约束即由此而来。
- PR #3457 Roll input IDs for MTP labels(上游 NVIDIA/Megatron-LM): 文档要求 recompute_granularity=full 时使用包含该 commit 的 dev 版本;它首次让 _checkpointed_forward 声明 padding_mask 参数,是本次文档约束的事实依据。
参与讨论