mcore-split-pr
nvidia/skills
将单个 Pull Request 拆分为多个 Pull Request,以此减少所需的 CODEOWNERS 审核团队数量。
...展开全部关于 mcore-split-pr
mcore-split-pr 工具可用于将庞大的 Megatron-LM pull request 拆分为多个较小的 PR,使得每个 PR 所涉及的 CODEOWNERS 审核小组数量尽可能少。它解决了具体的审核负担问题:那些同时涉及核心代码、示例、工具以及训练目录的 PR 会牵涉到众多审核小组,从而延缓合并进度;而仅针对单个目录制定的 PR 则只需该目录对应的审核人员即可完成审核。
该工具的工作流程分为三个阶段。首先,它会通过 gh CLI 获取 PR 的详细信息与差异统计数据,解析 .github/CODEOWNERS 文件以将文件类型与对应的所有者小组关联起来,并统计该 PR 当前所需的独立审核小组数量。接着,它会根据 CODEOWNERS 分组对文件进行归类,确保测试文件与它们所验证的生产代码保持在一起,标记出跨 PR 的依赖关系(例如某个 PR 中重命名的符号被另一个 PR 所引用),保证每个拆分后的 PR 均可独立合并,最后以表格形式呈现拆分方案供用户批准。只有在获得批准后,它才会执行实际操作:从正确的基分支创建分支,使用 git apply 应用针对特定文件的差异修改,完成提交后推送到用户的 fork 分支。该工具创建的 PR 始终为草稿状态,绝不会直接推送到上游仓库,在执行强制推送前会先征得用户确认;若当前操作用户并非该 PR 的原作者,还会注明原作者的贡献。
该工具的目标用户是那些需要处理庞大 PR 且希望减少每个 PR 所涉及的审核小组数量、同时确保每个拆分后的 PR 均可独立审核和合并的 Megatron-LM 贡献者及维护人员。用户可通过提供 PR 的 URL 或编号作为参数来调用该工具。
常见问题
拆分 PR 能解决什么问题?
它能减少每个 PR 所需的 CODEOWNERS 审核小组数量,从而降低审核负担。不过每个拆分后的 PR 依然需要具备独立合并和审核的能力。
它会直接推送到主仓库吗?
不会。该工具创建的 PR 始终为草稿状态,只会推送到用户的 fork 分支,绝不会直接上传到上游仓库。在执行可能缩小原 PR 范围的强制推送之前,它也会先与用户确认。
拆分过程中如何处理测试文件?
测试文件会与其所验证的生产代码一同存在。该工具不会仅仅为了减少审核小组而将测试文件拆分为单独的 PR。
如果某个拆分后的 PR 依赖于另一个 PR,会怎样?
工具会明确标出这种依赖关系,并在第一个 PR 中添加向后兼容的别名、重新导出机制或适配代码,以便后续的 PR 能够引用它们,同时还会注明正确的合并顺序。
运行该工具需要什么条件?
需要已针对该仓库完成身份认证的 gh CLI、包含上游远程仓库的本地代码副本,以及用于推送分支的用户 fork 分支。在开始拆分操作之前,它会等待用户批准。
所有文件
5 个文件SKILL.md4.4 KB查看skill.oms.sig4.4 KB查看BENCHMARK.md2.7 KB查看evals/evals.json0.0 KB查看skill-card.md2.4 KB查看
Split a large pull request into multiple smaller PRs, where each PR touchesthe fewest possible CODEOWNERS reviewer groups. The goal is to reduce reviewburden: a PR that only touches megatron/core/ needs only the core reviewers,while a PR that also touches examples/, tools/, and megatron/training/pulls in many additional groups.
Answer-First Constraints
For split-planning questions, lead with these constraints before the fullworkflow:
- Minimize CODEOWNERS reviewer groups per PR, but each resulting PR must stillbe independently mergeable and reviewable.
- Tests travel with the production code they validate; do not split tests into aseparate PR just to reduce reviewer groups.
- If PR B depends on symbols renamed in PR A, call out the dependency and putbackward-compatible aliases, re-exports, or shims in PR A when needed.
- Wait for user approval before execution.
- Execution creates draft PRs from the right base, applies file-scoped diffswith
git diff upstream/main..<source-branch> -- <paths> | git apply, pushesto the user's fork, and never pushes directly to upstream.
Workflow
1. Analyze the PR
- Fetch the PR details:
gh pr view <number> --repo NVIDIA/Megatron-LM --json title,body,headRefName,authorandgh pr diff <number> --repo NVIDIA/Megatron-LM --stat. Also determine the current GitHub user withgh api user --jq .login. - Parse
.github/CODEOWNERSto build a mapping from file path patterns to owner groups. - For each changed file in the PR, determine which CODEOWNERS groups would be required to review it.
- Build a summary table grouped by CODEOWNERS group, showing which files pull in which groups.
- Count the total number of distinct reviewer groups the PR currently requires.
2. Propose a split that minimizes reviewer groups per PR
The primary optimization goal: minimize the number of CODEOWNERS reviewer groups required for each resulting PR.
Strategy:
- Cluster files by their CODEOWNERS groups. Files owned by the same set of groups naturally belong together.
- Identify the largest cluster — this becomes the first (and usually largest) PR.
- Remaining files form one or more additional PRs, each ideally requiring only one or two reviewer groups.
- If a split creates a dependency (e.g., PR B uses symbols renamed in PR A), the dependent PR must be merged after the first. Note this explicitly.
- Each PR must be independently mergeable to main — no broken imports, no missing symbols. Backward-compatible aliases and re-export stubs in the first PR can make this possible.
Present the proposed split as a table:
- PR name/description
- Files included
- CODEOWNERS groups required
- Dependencies on other PRs (if any)
Wait for user approval before proceeding.
3. Execute the split (after user approval)
For each new PR:
- Create a new branch from the appropriate base (
main, or a dependency PR's branch). - Extract the relevant changes:
git diff upstream/main..<source-branch> -- <file paths> | git apply. - Stage, commit with a clear message, and push to the user's fork.
- Create the PR as a draft (per repo contributing guidelines).
- If the original PR needs to be narrowed in scope, confirm with the user before force-pushing.
- Report all PR URLs when done.
Important guidelines
- Always create PRs as drafts and push to the user's fork, never directly to upstream.
- Backward-compatible changes (aliases, re-exports, deprecation shims) should go in the first PR so subsequent PRs can depend on them.
- Test files should go with the production code they test, not in a separate PR.
- Prefer a single clean commit per split PR over replaying the original commit history.
- If a file is hard to categorize (e.g., it touches two groups), ask the user which PR it should go in.
- If the current GitHub user is not the author of the original PR, each new PR's description must explicitly credit the original author (e.g., "Original changes by @ in #").





首页
