npx skills add https://github.com/pytorch/pytorch --skill pr-review审查 PyTorch 拉取请求,重点关注 CI 无法检查的内容:代码质量、测试覆盖充分性、安全漏洞和向后兼容性。代码检查、格式化、类型检查和导入排序由 CI 处理。
如果用户调用 /pr-review 时不带参数,不要执行审查。而是询问用户想要审查什么:
您希望我审查什么?
- PR 编号或 URL(例如
/pr-review 12345)- 本地分支(例如
/pr-review branch)
用户提供 PR 编号或 URL:
/pr-review 12345
/pr-review https://github.com/pytorch/pytorch/pull/12345
要进行包含逐行具体注释的详细审查:
/pr-review 12345 detailed
使用 gh CLI 获取 PR 数据:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
# 获取 PR 详情
gh pr view <PR_NUMBER> --json title,body,author,baseRefName,headRefName,files,additions,deletions,commits
# 获取差异
gh pr diff <PR_NUMBER>
# 获取 PR 评论
gh pr view <PR_NUMBER> --json comments,reviews
审查当前分支中不在 main 分支中的更改:
/pr-review branch
/pr-review branch detailed
使用 git 命令获取分支更改:
# 获取当前分支名称
git branch --show-current
# 获取与 main 分支相比的更改文件列表
git diff --name-only main...HEAD
# 获取与 main 分支相比的完整差异
git diff main...HEAD
# 获取分支的提交日志
git log main..HEAD --oneline
# 获取差异统计(更改的文件、插入、删除)
git diff --stat main...HEAD
对于本地分支审查:
当通过 GitHub PR 上的 @claude /pr-review 调用时,操作会预取 PR 元数据并将其注入到提示中。通过提示中是否存在 <formatted_context>、<pr_or_issue_body> 和 <comments> 标签来检测此模式。
提示中已包含:
使用 git 命令获取差异和提交历史。基础分支名称在提示上下文中(查找 PR Branch: <head> -> <base> 或 baseBranch 字段)。
# 获取与基础分支的完整差异
git diff origin/<baseBranch>...HEAD
# 获取差异统计
git diff --stat origin/<baseBranch>...HEAD
# 获取此 PR 的提交历史
git log origin/<baseBranch>..HEAD --oneline
# 如果基础分支引用不可用,请先获取它
git fetch origin <baseBranch> --depth=1
在此模式下不要使用 gh CLI 命令——仅使用 git 命令。所有 PR 元数据、评论和审查都已存在于提示上下文中;只需通过 git 获取差异和提交日志。
一行代码可能具有深远的交叉影响:缺少设备防护会导致多 GPU 上的静默数据损坏,缺少 Composite 调度键会破坏每个树外后端,手动 dtype 检查而不是使用 TensorIterator 会静默跳过类型提升。将每一行都视为可能承载重要功能。
不要略读。不要总结差异后就继续。阅读每一行更改并思考:这是否与作者可能不了解的现有 PyTorch 基础设施交互? 当不确定时,进行调查——生成子代理来阅读周围代码、PR 应使用的基础设施或应存在的测试。假阴性(遗漏真正问题)的成本远高于调查的成本。
本地 CLI 模式:使用 gh 命令获取 PR 元数据、更改的文件、完整差异、现有评论/审查以及相关的问题信息。
本地分支模式:使用针对 main 分支的 git diff 和 git log,如上文本地分支模式部分所示。
GitHub Actions 模式:PR 元数据、评论和审查已存在于提示中。使用 git diff origin/<baseBranch>...HEAD 获取完整差异,使用 git log origin/<baseBranch>..HEAD --oneline 获取提交日志。
在审查之前,建立对 PR 涉及内容和原因的理解:
这是审查的核心。遍历差异中的每一行更改,并根据 review-checklist.md 中的审查清单进行评估。
审查期间如何使用子代理:
清单很大。您无法在脑海中记住每个基础设施系统的完整上下文。相反,当遇到涉及清单区域的更改行时,生成一个子代理来调查清单项目是否适用。例如:
为独立的调查领域并行生成子代理。中等 PR 的典型审查应生成 3-8 个子代理。涉及多个子系统的大型 PR 可能需要更多。
清单区域(完整详情见 review-checklist.md):
评估向后兼容性影响。参见 bc-guidelines.md 了解:
对于非平凡的向后兼容性问题(例如,“更改此默认值是否会破坏下游用户?”),生成子代理来搜索修改 API 的现有调用者。
构建您的审查,按类别组织可操作的反馈。每个发现都应可追溯到差异中的特定行和特定的清单项目。
| 领域 | 重点 | 参考 |
|---|---|---|
| 代码质量 | 抽象、模式、复杂性 | review-checklist.md |
| API 设计 | 新模式、基于标志的访问、更广泛的影响 | review-checklist.md |
| C++ 内核 | TensorIterator、DispatchStub、AT_DISPATCH、结构化内核、设备防护、内存格式 | review-checklist.md |
| CUDA/设备 | C10_CUDA_CHECK、流/事件防护、recordStream、CUDA 图、AcceleratorHooks | review-checklist.md |
| 运算符注册 | native_functions.yaml、Composite 回退、元/伪实现、标签、模式注解 | review-checklist.md |
| 自动求导 | derivatives.yaml、autograd.Function 模式、gradcheck、前向模式 AD、vmap | review-checklist.md |
| Python 实用程序 | torch_function 、pytree、日志记录、弃用、后端上下文 | review-checklist.md |
| nn 模块 | ModuleList/Dict、nn.init、parametrize、state_dict 版本控制、LazyModule | review-checklist.md |
| Dynamo/Inductor | @register_lowering、分解、CustomGraphPass、config.patch、图中断 | review-checklist.md |
| FX/导出 | PassBase、PassManager、Interpreter、子图重写器、ShapeProp、make_fx | review-checklist.md |
| 类型提升 | elementwise_dtypes、TensorIterator dtype 处理、result_type、promoteTypes | review-checklist.md |
| 序列化 | weights_only、safe_globals、skip_data | review-checklist.md |
| 分布式 | DeviceMesh、使用 MultiThreadedPG 的分布式测试 | review-checklist.md |
| 张量子类 | _make_wrapper_subclass、tensor_flatten /unflatten | review-checklist.md |
| 测试 | OpInfo、ModuleInfo、设备通用、@dtypes、@parametrize、make_tensor | review-checklist.md |
| 安全 | 注入、凭据、输入处理 | review-checklist.md |
| 性能 | 回归、设备处理、内存、性能分析、基准测试 | review-checklist.md |
| 线程安全 | 数据竞争、GIL 假设、NoGIL、CPython C API | review-checklist.md |
| 向后兼容性 | 破坏性更改、弃用 | bc-guidelines.md |
按以下结构组织您的审查。对于没有发现的章节,请省略——不要为每个空章节写“无问题”。仅包含有实际观察结果的章节。
## PR 审查: #<number>
<!-- 或对于本地分支审查: -->
## 分支审查: <branch-name> (相对于 main)
### 摘要
对更改的简要整体评估(1-2 句)。
### 代码质量
[问题和建议]
### 基础设施
[标记适用的 PyTorch 基础设施部分的任何清单项目。
引用 PR 应使用的特定基础设施。]
### 测试
[测试充分性发现——缺少 OpInfo 使用、非设备通用测试等。]
### API 设计
[标记新模式、内部访问标志或任何更广泛的影响。]
### 安全
[如有问题]
### 线程安全
[如有线程问题]
### 向后兼容性
[如有向后兼容性问题]
### 性能
[如有性能问题]
### 建议
**批准** / **请求更改** / **需要讨论**
[建议的简要理由]
仅当用户请求“详细”或“深入”审查时才包含此部分。
不要重复已在其他章节中提出的观察结果。 此部分用于不适合上述分类章节的额外文件特定反馈。
当请求时,添加带有行引用的文件特定反馈:
### 具体评论
- `src/module.py:42` - 考虑将此逻辑提取到命名函数中以提高清晰度
- `test/test_feature.py:100-105` - 缺少输入为 None 时的错误情况测试
- `torch/nn/modules/linear.py:78` - 此分配可以移到循环外
C10_CUDA_KERNEL_LAUNCH_CHECK()、单个 weights_only=False、单个缺失的 Composite 调度键——每个都是影响真实用户的真实错误。不要跳过行。审查时,请查阅这些项目文件以获取上下文。生成子代理来阅读这些文件,而不是依赖记忆——这些文件经常更改:
CLAUDE.md - 编码风格理念和测试模式CONTRIBUTING.md - PR 要求和审查流程torch/testing/_internal/common_utils.py - 测试模式和实用程序torch/testing/_internal/opinfo/core.py - OpInfo 测试框架aten/src/ATen/native/native_functions.yaml - 运算符声明(用于检查标签、调度键、结构化内核)tools/autograd/derivatives.yaml - 反向公式(用于检查操作是否应在此注册)aten/src/ATen/native/tags.yaml - 运算符语义标签每周安装次数
175
仓库
GitHub 星标数
98.5K
首次出现
2026年2月12日
安全审计
安装于
codex171
opencode171
gemini-cli170
github-copilot169
amp169
kimi-cli169
Review PyTorch pull requests focusing on what CI cannot check: code quality, test coverage adequacy, security vulnerabilities, and backward compatibility. Linting, formatting, type checking, and import ordering are handled by CI.
If the user invokes /pr-review with no arguments, do not perform a review. Instead, ask the user what they would like to review:
What would you like me to review?
- A PR number or URL (e.g.,
/pr-review 12345)- A local branch (e.g.,
/pr-review branch)
The user provides a PR number or URL:
/pr-review 12345
/pr-review https://github.com/pytorch/pytorch/pull/12345
For a detailed review with line-by-line specific comments:
/pr-review 12345 detailed
Use gh CLI to fetch PR data:
# Get PR details
gh pr view <PR_NUMBER> --json title,body,author,baseRefName,headRefName,files,additions,deletions,commits
# Get the diff
gh pr diff <PR_NUMBER>
# Get PR comments
gh pr view <PR_NUMBER> --json comments,reviews
Review changes in the current branch that are not in main:
/pr-review branch
/pr-review branch detailed
Use git commands to get branch changes:
# Get current branch name
git branch --show-current
# Get list of changed files compared to main
git diff --name-only main...HEAD
# Get full diff compared to main
git diff main...HEAD
# Get commit log for the branch
git log main..HEAD --oneline
# Get diff stats (files changed, insertions, deletions)
git diff --stat main...HEAD
For local branch reviews:
When invoked via @claude /pr-review on a GitHub PR, the action pre-fetches PR metadata and injects it into the prompt. Detect this mode by the presence of <formatted_context>, <pr_or_issue_body>, and <comments> tags in the prompt.
The prompt already contains:
Use git commands to get the diff and commit history. The base branch name is in the prompt context (look for PR Branch: <head> -> <base> or the baseBranch field).
# Get the full diff against the base branch
git diff origin/<baseBranch>...HEAD
# Get diff stats
git diff --stat origin/<baseBranch>...HEAD
# Get commit history for this PR
git log origin/<baseBranch>..HEAD --oneline
# If the base branch ref is not available, fetch it first
git fetch origin <baseBranch> --depth=1
Do NOT use gh CLI commands in this mode -- only git commands are available. All PR metadata, comments, and reviews are already in the prompt context; only the diff and commit log need to be fetched via git.
A single line of code can have deep cross-cutting implications: a missing device guard causes silent data corruption on multi-GPU, a missing Composite dispatch key breaks every out-of-tree backend, a manual dtype check instead of TensorIterator silently skips type promotion. Treat every line as potentially load-bearing.
Do not skim. Do not summarize the diff and move on. Read every changed line and ask: does this interact with existing PyTorch infrastructure that the author may not know about? When uncertain, investigate — spawn a sub-agent to read the surrounding code, the infrastructure the PR should be using, or the tests that should exist. The cost of a false negative (missing a real issue) is much higher than the cost of investigation.
Local CLI mode : Use gh commands to get PR metadata, changed files, full diff, existing comments/reviews, and associated issue information.
Local Branch mode : Use git diff and git log against main as shown in the Local Branch Mode section above.
GitHub Actions mode : PR metadata, comments, and reviews are already in the prompt. Use git diff origin/<baseBranch>...HEAD for the full diff and git log origin/<baseBranch>..HEAD --oneline for the commit log.
Before reviewing, build understanding of what the PR touches and why:
This is the core of the review. Go through every changed line in the diff and evaluate it against the review checklist in review-checklist.md.
How to use sub-agents during review:
The checklist is large. You cannot hold the full context of every infrastructure system in your head. Instead, when you encounter a changed line that touches a checklist area, spawn a sub-agent to investigate whether the checklist item applies. For example:
Spawn sub-agents in parallel for independent investigation areas. A typical review of a medium PR should spawn 3-8 sub-agents. Large PRs touching multiple subsystems may need more.
Checklist areas (see review-checklist.md for full details):
Evaluate BC implications. See bc-guidelines.md for:
For non-trivial BC questions (e.g., "does changing this default break downstream users?"), spawn a sub-agent to search for existing callers of the modified API.
Structure your review with actionable feedback organized by category. Every finding should be traceable to a specific line in the diff and a specific checklist item.
| Area | Focus | Reference |
|---|---|---|
| Code Quality | Abstractions, patterns, complexity | review-checklist.md |
| API Design | New patterns, flag-based access, broader implications | review-checklist.md |
| C++ Kernels | TensorIterator, DispatchStub, AT_DISPATCH, structured kernels, device guards, memory format | review-checklist.md |
| CUDA/Device | C10_CUDA_CHECK, stream/event guards, recordStream, CUDA graphs, AcceleratorHooks | review-checklist.md |
| Op Registration | native_functions.yaml, Composite fallback, meta/fake impls, tags, schema annotations | review-checklist.md |
| Autograd |
Structure your review as follows. Omit sections where you have no findings — don't write "No concerns" for every empty section. Only include sections with actual observations.
## PR Review: #<number>
<!-- Or for local branch reviews: -->
## Branch Review: <branch-name> (vs main)
### Summary
Brief overall assessment of the changes (1-2 sentences).
### Code Quality
[Issues and suggestions]
### Infrastructure
[Flag any checklist items from the PyTorch Infrastructure section that apply.
Reference the specific infrastructure the PR should be using.]
### Testing
[Testing adequacy findings — missing OpInfo usage, non-device-generic tests, etc.]
### API Design
[Flag new patterns, internal-access flags, or broader implications if any.]
### Security
[Issues if any]
### Thread Safety
[Threading concerns if any]
### Backward Compatibility
[BC concerns if any]
### Performance
[Performance concerns if any]
### Recommendation
**Approve** / **Request Changes** / **Needs Discussion**
[Brief justification for recommendation]
Only include this section if the user requests a "detailed" or "in depth" review.
Do not repeat observations already made in other sections. This section is for additional file-specific feedback that doesn't fit into the categorized sections above.
When requested, add file-specific feedback with line references:
### Specific Comments
- `src/module.py:42` - Consider extracting this logic into a named function for clarity
- `test/test_feature.py:100-105` - Missing test for error case when input is None
- `torch/nn/modules/linear.py:78` - This allocation could be moved outside the loop
C10_CUDA_KERNEL_LAUNCH_CHECK(), a single weights_only=False, a single missing Composite dispatch key — each of these is a real bug that affects real users. Do not skip lines.When reviewing, consult these project files for context. Spawn sub-agents to read these rather than relying on memory — the files change frequently:
CLAUDE.md - Coding style philosophy and testing patternsCONTRIBUTING.md - PR requirements and review processtorch/testing/_internal/common_utils.py - Test patterns and utilitiestorch/testing/_internal/opinfo/core.py - OpInfo test frameworkaten/src/ATen/native/native_functions.yaml - Operator declarations (for checking tags, dispatch keys, structured kernels)tools/autograd/derivatives.yaml - Backward formulas (for checking if an op should register here)aten/src/ATen/native/tags.yaml - Operator semantic tagsWeekly Installs
175
Repository
GitHub Stars
98.5K
First Seen
Feb 12, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
codex171
opencode171
gemini-cli170
github-copilot169
amp169
kimi-cli169
AI 代码实施计划编写技能 | 自动化开发任务分解与 TDD 流程规划工具
49,800 周安装
RevealJS演示文稿生成技能 - 一键创建专业幻灯片,支持技术演讲和宣传稿
83 周安装
Prompt Analyzer 提示词分析器 - AI提示词分析对比与元素洞察工具
83 周安装
FastAPI 后端模板 | Python FastAPI + PostgreSQL + SQLAlchemy 2.0 异步开发框架
83 周安装
Breadboarding 原型设计技能 - 快速电路原型开发与验证工具
83 周安装
fetch-tweet:无需身份验证,使用fxtwitter API轻松获取结构化推文JSON数据
83 周安装
AI行为模式优化 - 自适应头脑风暴、实施、调试、审查、教学、发布模式指南
83 周安装
| derivatives.yaml, autograd.Function patterns, gradcheck, forward-mode AD, vmap |
| review-checklist.md |
| Python Utils | torch_function , pytree, logging, deprecation, backends context | review-checklist.md |
| nn Modules | ModuleList/Dict, nn.init, parametrize, state_dict versioning, LazyModule | review-checklist.md |
| Dynamo/Inductor | @register_lowering, decompositions, CustomGraphPass, config.patch, graph breaks | review-checklist.md |
| FX/Export | PassBase, PassManager, Interpreter, subgraph rewriter, ShapeProp, make_fx | review-checklist.md |
| Type Promotion | elementwise_dtypes, TensorIterator dtype handling, result_type, promoteTypes | review-checklist.md |
| Serialization | weights_only, safe_globals, skip_data | review-checklist.md |
| Distributed | DeviceMesh, distributed testing with MultiThreadedPG | review-checklist.md |
| Tensor Subclasses | _make_wrapper_subclass, tensor_flatten /unflatten | review-checklist.md |
| Testing | OpInfo, ModuleInfo, device-generic, @dtypes, @parametrize, make_tensor | review-checklist.md |
| Security | Injection, credentials, input handling | review-checklist.md |
| Performance | Regressions, device handling, memory, profiling, benchmarking | review-checklist.md |
| Thread Safety | Data races, GIL assumptions, NoGIL, CPython C API | review-checklist.md |
| BC | Breaking changes, deprecation | bc-guidelines.md |