Skip to content

[FX] Ignore incidental cuBLASLt capture checks in profiler snapshot - #203742

Closed
ngimel wants to merge 1 commit into
mainfrom
fix/fx-profiler-capture-events
Closed

ngimel wants to merge 1 commit into
mainfrom
fix/fx-profiler-capture-events

Conversation

@ngimel

@ngimel ngimel commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Fix the consistently failing cuda 13.4 test, cublas internals change the number of cudaStreamIsCapturing calls depending on the cublas version, this is not the quantity we should be testing

Test Plan

With the CUDA 13.4 source-build Python environment activated:

CUDA_VISIBLE_DEVICES=0 OMP_NUM_THREADS=8 python test/test_fx.py TestFXCUDACUDA -k profiler -v
git diff --check
lintrunner -a

The CUDA 13.4 profiler snapshot assumes that each addmm records exactly
two cudaStreamIsCapturing events. The observed trace records only one,
even though native callbacks can see queries in both cuBLASLt heuristic
selection and matmul execution. Their recorded count is not part of FX
stack-trace augmentation's contract.

Filter these incidental capture-status events and remove the
version-dependent expectation. Keep the exact ATen and kernel-launch
ordering, node names, and source-stack comparison unchanged. This
intentionally stops testing capture-query metadata/counts rather than
adding another CUDA-version-specific golden string.

Test Plan
---------
With the CUDA 13.4 source-build Python environment activated:

```sh
CUDA_VISIBLE_DEVICES=0 OMP_NUM_THREADS=8 python test/test_fx.py TestFXCUDACUDA -k profiler -v
git diff --check
lintrunner -a
```

The three CUDA profiler tests pass. Scratch assertion checks accept
zero, one, or two capture events per addmm and reject missing launches
or incorrect launch stacks. The original test also passed, without a
skip, in the CUDA 13.2 periodic job 127408856082 on run 42068588969;
no CUDA 13.2 build was run locally.

lintrunner -a was attempted, but its Python-based checks could not run:
uv failed to download their required CPython 3.11 interpreter, and no
Python 3.11 is installed locally. The lint result is not green.

Agent details
-------------
Authored and reviewed with an AI assistant.
@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Nov 6, 2026
@pytorch-bot

pytorch-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - Ready for human review:

The PR fixes a CUDA 13.4 failure in test_profiler_stack_trace_augmentation. It
drops every cudaStreamIsCapturing line before comparing the profiler snapshot,
where it used to expect a fixed per-CUDA-version count. Recommendation: Approve.
The review found no blocking issues and labels all its points non-blocking.

Findings (4):

[minor] test/test_fx.py:5528
Comment doesn't give the reason (non-blocking). "cuBLASLt's internal capture
checks need not all appear in the trace" suggests the events are only sometimes
missing. The real reason, given in the PR description, is that the number of
cudaStreamIsCapturing calls changes with the cuBLAS version, and this test
doesn't check that count. The filter also drops every cudaStreamIsCapturing
event, not only the ones from cuBLASLt. Suggested wording: "The number of
cudaStreamIsCapturing calls depends on the cuBLAS version and isn't what this
test checks; drop them before comparing."

[minor] test/test_fx.py:5529
Two filtering styles in one test (non-blocking). The HIP filter (5506-5511) uses
split('n') and a substring check, inside the torch.version.hip branch. The new
CUDA filter uses splitlines() and startswith, inside the non-Windows else:. That
branch also runs on ROCm, where the event is named hipStreamIsCapturing, so the
filter never matches there. Move it into the CUDA else: at 5514-5516, next to
kernel_event, and write it the same way as the HIP filter, so each platform's
noise filtering stays in one place. test/profiler/test_profiler_tree.py:48
already lists "cudaStreamIsCapturing": PRUNE_ALL as known noise; cite that in
the comment.

[minor] test/test_fx.py:5532
Node attribution of the dropped events is no longer checked (non-blocking). On
CUDA >= 13.4 the old expectation also required each cudaStreamIsCapturing event
to be attributed to node=addmm / addmm_1, with the self.linear1(x) /
self.linear2(x) stack trace. The prefix filter drops these lines whatever their
node=, so a regression that attached them to relu, or gave them the wrong stack
trace, would pass. Event-to-node mapping is what this test is meant to verify.
The description justifies dropping the count but not the attribution, so this is
a partly undocumented coverage reduction (REVIEW.md Rule 6). Cheap fix: when
filtering, assert that every dropped line's node is addmm or addmm_1, with zero
dropped lines still passing so older CUDA keeps working. Or say in the
description that attribution is no longer checked.

[minor] test/test_fx.py:5527
A device-independent test sits in the CUDA class (test/test_fx.py:5647-5714;
pre-existing, in scope under REVIEW.md Case 2; non-blocking).
test_graph_module_with_hop_serialization is in TestFXCUDA (hw_classification =
CUDA, only_for="cuda" at 5717). It never uses device: it traces torch.randn(5)
CPU fake tensors under FakeTensorMode and only checks that the GraphModule
serializes. Under Rule 1 it belongs in a GENERIC class such as TestFX, without
the device parameter. xfailIfNoAcceleratorTriton still covers a missing triton.
Today it never runs on CPU-only machines that have triton installed.

Reviewed commit: 133228c

Review run

🐛 Report a bad review

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/203742

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 7 Unrelated Failures

As of commit 133228c with merge base 5e46c2b (image):

🟡 GREEN LIGHT - PR requires human review:

  • Test re-baselined with no source change
    • test/test_fx.py now drops every event=cudaStreamIsCapturing line from actual_traces before assertExpectedInline
    • The diff touches no production file, so this is a weakened assertion, which Never trivial names
  • Outside every trivial class
    • Explained test changes covers only skips, expected failures, or expected-message updates; this rewrites the test's filtering code
    • The filter now applies on every non-HIP CUDA version, where the removed _get_torch_cuda_version() >= (13, 4) gate limited it to 13.4+
  • Correctness looks sound
    • Mirrors the existing hipGetDeviceProperties filter in the HIP branch; the removed _get_torch_cuda_version import has no other use in the file

reason: not_trivial
Reviewed commit: 133228c

Inference job

🐛 Report a wrong verdict

NEW FAILURE - The following job has failed:

NEW FAILURES SUPPRESSED BY AI (non-blocking) - The following jobs failed, but the AI CI Advisor judged the failures not to be evidence against this change:

  • Lint / lintrunner-clang-all / lint (gh)

    AI verdict: AI verdict: not related

    The suspect commit only edits test/test_fx.py, which the clang-tidy and clang-format linters never look at. In the suspect run, spin lint exits within about a second without writing lint.json, so no lint result is produced. The merge base (5e46c2b, Nov 3) fails in exactly the same way, and recent trunk commits pass. The failure was already present on the PR's old base and has since been fixed on trunk.

    Full reasoning on HUD →

  • Lint / lintrunner-noclang-all / lint (gh)

    AI verdict: AI verdict: not related

    The lint job fails because spin lint exits before lintrunner runs and never writes lint.json. The failure is identical at the PR's merge base (5e46c2b, Nov 3), so it was already there before the suspect. The suspect only edits test/test_fx.py, and recent trunk commits pass this job, so the base breakage has since been fixed on main.

    Full reasoning on HUD →

  • Lint / lintrunner-pyrefly-all / lint (gh)

    AI verdict: AI verdict: not related

    The pyrefly lint job fails the same way at the PR's merge base (5e46c2b), which does not contain the suspect commit: spin lint exits 1 before lintrunner writes lint.json, and no pyrefly diagnostics are reported. Recent trunk commits pass this job, so the breakage came from the stale merge base and has since been fixed on main. The suspect only edits test_fx.py, and nothing in that change can stop the lint tooling from running.

    Full reasoning on HUD →

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorchgreenlight pytorchgreenlight Bot added the GL/human GreenLight marked as needing human review label Nov 6, 2026
@pytorchbot pytorchbot added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 6, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review of 133228c: nothing blocking; ready for human review.

The PR fixes a CUDA 13.4 failure in test_profiler_stack_trace_augmentation. It drops every cudaStreamIsCapturing line before comparing the profiler snapshot, where it used to expect a fixed per-CUDA-version count. Recommendation: Approve. The review found no blocking issues and labels all its points non-blocking.

⚪ 4 non-blocking findings

# cuBLASLt's internal capture checks need not all appear in the trace.

Comment doesn't give the reason (non-blocking). "cuBLASLt's internal capture checks need not all appear in the trace" suggests the events are only sometimes missing. The real reason, given in the PR description, is that the number of cudaStreamIsCapturing calls changes with the cuBLAS version, and this test doesn't check that count. The filter also drops every cudaStreamIsCapturing event, not only the ones from cuBLASLt. Suggested wording: "The number of cudaStreamIsCapturing calls depends on the cuBLAS version and isn't what this test checks; drop them before comparing."


actual_traces = "\n".join(

Two filtering styles in one test (non-blocking). The HIP filter (5506-5511) uses split('n') and a substring check, inside the torch.version.hip branch. The new CUDA filter uses splitlines() and startswith, inside the non-Windows else:. That branch also runs on ROCm, where the event is named hipStreamIsCapturing, so the filter never matches there. Move it into the CUDA else: at 5514-5516, next to kernel_event, and write it the same way as the HIP filter, so each platform's noise filtering stays in one place. test/profiler/test_profiler_tree.py:48 already lists "cudaStreamIsCapturing": PRUNE_ALL as known noise; cite that in the comment.


if not line.startswith("event=cudaStreamIsCapturing ")

Node attribution of the dropped events is no longer checked (non-blocking). On CUDA >= 13.4 the old expectation also required each cudaStreamIsCapturing event to be attributed to node=addmm / addmm_1, with the self.linear1(x) / self.linear2(x) stack trace. The prefix filter drops these lines whatever their node=, so a regression that attached them to relu, or gave them the wrong stack trace, would pass. Event-to-node mapping is what this test is meant to verify. The description justifies dropping the count but not the attribution, so this is a partly undocumented coverage reduction (REVIEW.md Rule 6). Cheap fix: when filtering, assert that every dropped line's node is addmm or addmm_1, with zero dropped lines still passing so older CUDA keeps working. Or say in the description that attribution is no longer checked.


else:

A device-independent test sits in the CUDA class (test/test_fx.py:5647-5714; pre-existing, in scope under REVIEW.md Case 2; non-blocking). test_graph_module_with_hop_serialization is in TestFXCUDA (hw_classification = CUDA, only_for="cuda" at 5717). It never uses device: it traces torch.randn(5) CPU fake tensors under FakeTensorMode and only checks that the GraphModule serializes. Under Rule 1 it belongs in a GENERIC class such as TestFX, without the device parameter. xfailIfNoAcceleratorTriton still covers a missing triton. Today it never runs on CPU-only machines that have triton installed.

This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review

@huydhn huydhn added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 6, 2026
@ngimel

ngimel commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: trunk / linux-noble-rocm-py3.11-mi350 / test (default, 1, 8, amd-dpx-linux.rocm.gpu.gfx950.1)

Details for Dev Infra team

Raised by workflow job

@albanD

albanD commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
…ytorch#203742)

Fix the consistently failing cuda 13.4 test, cublas internals change the number of cudaStreamIsCapturing calls depending on the cublas version, this is not the quantity we should be testing

Test Plan
---------
With the CUDA 13.4 source-build Python environment activated:

```sh
CUDA_VISIBLE_DEVICES=0 OMP_NUM_THREADS=8 python test/test_fx.py TestFXCUDACUDA -k profiler -v
git diff --check
lintrunner -a
```

Pull Request resolved: pytorch#203742
Approved by: https://github.com/huydhn
jeanschmidt added a commit to pytorch/test-infra that referenced this pull request Nov 12, 2026
…r any merge-rule approver (#9417)

🏖️ nmc:

**Impact:** GreenLight's review policy
(`.claude/skills/greenlight-review/SKILL.md`) is rewritten as one linear
decision procedure with broader, generic rules, and GreenLight
eligibility widens to every approver `merge_rules.yaml` names, on any
path. Each of the 12 open GreenLight feedback reports would get the
opposite verdict (LAND). Other PRs are expected to flip to LAND along
the way.

**Risk:** High, by design: it eases review gates. The skill goes live on
merge. The eligibility change goes live in two steps. The record job and
the `@greenlight recheck` path run `greenlight` from test-infra `main`,
so they change on merge. The scheduled scan changes only with the next
greenlight-scan Lambda release. Merge first and release right after. In
between:
- a recheck of an approver's PR outside their merge-rule paths gets a
LAND approval, which the old scan's next pass dismisses;
- PRs the old scan dispatches on a base trymerge refuses end as shadow
verdicts, and Dr. CI shows them as not completed.

Neither loops. The accepted risks are listed under Notes.

## What

### The reports this flips

| Report | PR | What GreenLight objected to | Root cause in the policy |
|---|---|---|---|
| #9098 | pytorch/pytorch#200725 | Flex-attention config pruning on
sm_10x, for a Triton miscompile. Objections: "kernel config selection"
counts as numerics; a new default config; a 5th argument to the
subclassable `InductorChoices` hook; tests miss the pruned autotune
lists | Numerics covered config tuning; "moves a default" and "a caller
outside the diff" were not limited to what users rely on; no class for a
hardware-scoped workaround; tests expected for every branch |
| #9093 | pytorch/pytorch#200126 | `HIDDEN_NAMESPACE_BEGIN` on more
`torch/headeronly` headers: a linkage change, "correct but
consequential", no class fits | The "Correct but consequential" shape;
no class for applying a pattern the checkout already uses (41 headeronly
files used the macro before); linkage treated as API |
| #9140 | pytorch/pytorch#201160 | Docs toctree move: "navigation
markup, not prose"; docs owners may weigh in | Documentation meant prose
only; "a reviewer might ask" sent taste questions to humans |
| #8885 | pytorch/pytorch#198501 | Python 3.10 to 3.11 in periodic, slow
and periodic-strict. Objections: ~30 sites; a coverage shift; job-name
history moves; "confirm it is intended" | Breadth counted sites, not
unchecked sites; "removes coverage" applied to CI that gates no merge;
job names treated as parsed output; intent questions sent to humans |
| #9291 | pytorch/pytorch#202759 | Lowered a perf floor (1.5x to 1.2x)
on non-HIP GPUs: "re-baselined test"; is 1.2x enough? | The test hard
stop covered performance thresholds; the test classes were a closed
list; the "would a reviewer ask" question |
| #9230 | pytorch/pytorch#202224 | Flaky-test fix (warm up, then
reseed): not a skip, xfail or message; first-call RNG coverage | Closed
list; the "would a reviewer ask" question |
| #9259 | pytorch/pytorch#202242 | SM-count skip that also skips some
cases that would fit; "could ask for an occupancy bound" | "Wider than
its guard"; the "would a reviewer ask" question |
| #9359 | pytorch/pytorch#203688 | One new assert in a helper under
`torch/testing/_internal/`: outside `test/`; 17 tests, only 10 run
locally | The test classes stopped at `test/`; "confirm it passes in CI"
sent to a human |
| #9358 | pytorch/pytorch#203742 | Filters cuBLAS-internal profiler
events out of an expected trace: "weakened assertion"; the filter now
applies on every CUDA version | The test hard stop covered checks of
another library's internals; closed list |
| #9329, #9335 | pytorch/pytorch#203292 | Never reviewed: the author is
named only by a path-scoped merge rule (`c10/util/**`) | Eligibility
required one rule naming the author to cover every changed file |
| #9304 | pytorch/pytorch#203025 | One-line bugfix in a JIT-wrapper
cache-key marker with no test in the diff; "confirm cross-process reuse
is intended" | The bugfix class needed a test in the diff, or a change
that leaves nothing lasting (a cache key does); the author's runs did
not count; intent questions sent to humans |

### The broad changes

| # | Change | Flips (report: PR) |
|---|---|---|
| C1 | One linear decision order; only defects send a PR to a human |
Every report needs it: it removes the "would a reviewer ask" question,
its repeat in criterion 8, and "Correct but consequential" |
| C2 | What the PR's text can tell you: reported runs are facts | #9359:
#203688, #9304: #203025, #9098: #200725 |
| C3 | Test code is one class; the only stop is weakening checks of
PyTorch's own results | #9291: #202759, #9230: #202224, #9259: #202242,
#9359: #203688, #9358: #203742 |
| C4 | Bug fixes need evidence, not a new test; platform-scoped
workarounds are included | #9304: #203025, #9098: #200725 |
| C5 | Numerics means changing the math, not choosing a kernel | #9098:
#200725 |
| C6 | The user-facing surface, defined concretely | #9098: #200725,
#9093: #200126, #8885: #198501 |
| C7 | Applying an established pattern is a class | #9093: #200126
(helps #9230, #9358, #9140, #8885) |
| C8 | Documentation includes its structure | #9140: #201160 |
| C9 | CI coverage rules bind merge-gating workflows; hiding failure is
always a stop | #8885: #198501 |
| C10 | Breadth counts unchecked sites, not sites | #8885: #198501 |
| C11 | Merge authorization names what decides what lands | None: it
names the files C12 lets more authors reach |
| C12 | Eligibility: any merge-rule approver, any path, on a base
trymerge accepts | #9329 and #9335: #203292 |

Each PR needs all of the changes listed for it:

| Report | PR | Changes that flip it |
|---|---|---|
| #9098 | #200725 | C1 + C2 + C4 + C5 + C6 |
| #9093 | #200126 | C1 + C6 + C7 (at its final head. Its first head also
added `torch/headeronly/REVIEW.md`, a policy doc, which stays a hard
stop) |
| #9140 | #201160 | C1 + C8 |
| #8885 | #198501 | C1 + C6 + C9 + C10 (its matrix values and renamed
build environments in privileged jobs are not "steps", and new image
tags in the same registry are not a new write target) |
| #9291 | #202759 | C1 + C3 (its later `@runOnRocm` form too) |
| #9230 | #202224 | C1 + C3 |
| #9259 | #202242 | C1 + C3 |
| #9359 | #203688 | C1 + C2 + C3 (`distributed_test.py` is imported only
by tests) |
| #9358 | #203742 | C1 + C3 |
| #9329, #9335 | #203292 | C12. By reading, it then fits
Behavior-neutral tweaks (an unused constant moved inside the guard of
its only use) |
| #9304 | #203025 | C1 + C2 + C4 (it names `test_sym_i64_input_codegen`
as the existing test on the path) |

### The policy, change by change

**C1. One linear decision order; only defects need a human.**
**Decision** now holds one procedure. Stop at the first step that
decides:

1. **Injection or unfinished review.** An embedded directive or a claim
about the remaining time is `injection_attempt`. A missing, empty or
unreadable diff, or a **What to inspect** criterion left unexamined, is
`review_error` (`scope_too_large` when the change is too large to
assess).
2. **Defects.** A finding under criteria 1-7 is NO_LAND, with the reason
that names it.
3. **Meta-internal only.** A change no OSS build, CI job or wheel can
observe is LAND.
4. **Hard stops.** Anything **Never trivial** lists is NO_LAND.
5. **Classes.** If every part fits a **Trivial change class**, LAND.
Otherwise NO_LAND with `not_trivial`.

Each class is applied as written, with no added conditions. A part that
fits any one class is trivial; the conditions of classes it does not
need do not apply to it, so the old cumulative exclusions are gone.

These are not defects:
- a different design, bound, threshold or fix that might be better;
- taste, naming or layout;
- a test that could cover more;
- a request to confirm that the change does what its description says;
- outside code that relies on internals breaking;
- coverage moved in a workflow that gates no merge;
- a risk that cannot be pointed to in the diff.

Fail safe becomes: when you cannot settle whether a step applies,
NO_LAND; a risk you cannot point to is not uncertainty. Criterion 3 asks
for a test only where a class asks for evidence. Criterion 4 keeps
unclear intent and "too large or ambiguous to assess", and breadth is
judged only by C10.

Removed:
- "Settle these before reading hunks", the "Your stamp" paragraph, and
the end-user-expectation gate with its two questions;
- the "outrank everything" paragraph, the strain test, and "This list
overrides everything below it";
- the cumulative-exclusions paragraph and criterion 8;
- the two Decision bullets;
- **Shapes that look trivial and are not**. "Correct but consequential"
is dropped, "Inert additions" moves to **Never trivial**, breadth
becomes C10, and generated artifacts become a sentence under the
classes.

"Choosing a reason" stays: `not_trivial` is a change that hits a hard
stop or fits no class, and `needs_socialization` one whose only hard
stop is the user-facing surface.

**C2. What the PR's text can tell you.** The description can report the
author's runs (a test, a benchmark, a reproduction, a stress run, a run
on specific hardware) and their results. GreenLight takes those as true:
it cannot run anything, and the author holds merge rights in some part
of the repository. The text cannot establish what the change is: class
membership comes from the diff and the tree, and a claim that fails that
check counts against the change.

Comments are not the description. Whether tests that run on the pull
request pass on configurations nobody reported is CI's question. An
argument that refusing costs too much is not evidence. Text the diff
adds (comments, docstrings, docs) is a claim, not evidence; a test in
the diff counts through what its code does. Reported runs are evidence
for a class's conditions; they never clear a defect visible in the diff
or a hard stop the change hits.

**C3. Test changes are one class.** It covers any change confined to
test code: files under `test/`, and files under
`torch/testing/_internal/` that only test code imports. Test runners
(`test/run_test.py`, `conftest.py` files, `tools/testing/`, `run_tests`)
are CI configuration, not test code.

Typical test changes:
- adding tests or checks;
- making a flaky test deterministic by controlling state it does not
check;
- adapting a test to details outside PyTorch's control;
- skipping or limiting a test where it cannot run or where such a detail
makes it fail, even with a conservative guard;
- updating an expected message;
- setting performance or timing thresholds to what the hardware
supports.

The only test hard stop is a check of PyTorch's own results weakened
with no source change behind it: an assertion deleted, skipped where the
test can run (with no detail outside PyTorch's control, such as hardware
size or speed, a driver or toolkit version, or third-party code, behind
the skip, as the checkout or a reported run shows), or its expected
value changed. PyTorch's own results are the values and exception types
its code produces. Message wording, performance, timing and the output
of code outside PyTorch are not.

**C4. Single-cause bugfix.** The PR has one root cause, which the
description or the diff explains, and one fix that reading confirms
removes or avoids it. The fix may take effect only on the hardware,
driver, toolkit or build where the bug shows. It may avoid an outside
cause (a compiler or library bug) instead of removing it, and its
plumbing (an optional parameter, a capability check) is part of it.

Evidence is a test in the diff, an existing test on the path, or a run
the description reports. A fix that changes a cache key, a serialized
artifact, or the files written or deleted needs a test in the diff or an
existing test on the path. Not when the fix changes user-facing behavior
beyond removing the bug, turns an error into a quieter outcome the
documentation did not promise, or keys on a CI or test environment.

**C5. Numerics means changing the math.** That is formulas, precision,
dtypes, numerical tolerances (in code or tests), and an accumulation
order the algorithm specifies. Choosing among kernel configurations,
tile or block sizes, autotuning candidates or backends that implement
the same math is performance tuning, even when it changes rounding.

**C6. The user-facing surface.** One hard stop replaces three earlier
items: the end-user-expectation question, "an expectation a PyTorch user
could reasonably hold", and "Deprecating or removing anything public".
It stops on removing, deprecating or renaming something PyTorch offers
outside code, or changing its signature, a default, a limit or its
documented behavior. It also stops on changing the shape of output
something parses.

What PyTorch offers:
- the public Python API: no underscore in the import path, or listed in
a `docs/source` autodoc entry;
- the C++ extension API: what `docs/cpp` and `docs/source/accelerator`
document, `torch/headeronly`, `torch/csrc/stable`, and libtorch's
exported symbols;
- configuration users set (config modules such as
`torch._inductor.config`, and environment variables);
- formats users save.

Parsed output is output that the repository shows something matches, or
that test-infra, the HUD and Dr. CI read. A job name is parsed only
through the workflow names `merge_rules.yaml` and
`update-viablestrict.yml` list. Everything else is internal: private
modules, internal heuristics and their defaults, extension points under
a private import path, and the linkage of header-only code.

**C7. Established patterns.** A new class: applying a construct the
checkout already uses for the same purpose, the same way, at new sites
of the same kind. Those sites are the same file or module, sibling
workflows, or the code a comment or doc says the construct is for. Lines
the diff adds do not establish a pattern. The reviewer judges
faithfulness, not the pattern's merit.

**C8. Documentation includes its structure.** This covers wording,
examples, headings, toctrees and navigation, cross-links, and page moves
that keep URLs. Not when the code may be the defect, when it adds or
changes a download or install link or command, embeds raw HTML or
script, or adds or removes an autodoc entry. `docs/source/conf.py` and
policy docs stay hard stops.

**C9. CI coverage rules bind merge-gating workflows.** A workflow gates
merges when it runs on every pull request, when
`update-viablestrict.yml`'s `requires` list names it, or when such a
workflow calls it. In other workflows, version bumps, renamed jobs and
images, and added or dropped configurations are their owners' call.

**CI and build configuration** is a class with no exclusions. Everything
that used to exclude a CI change is a hard stop, so no class can reach
it:

- **CI privilege and merge gating**, a new hard stop, covers:
- OIDC roles, `pull_request_target`, and generated workflows or their
generators;
- a step added or edited in a job that holds secrets or an OIDC role, or
in an action or reusable workflow such a job uses, or in a script such a
job runs (test code and PyTorch's own source are not such scripts;
matrix values and reusable-workflow inputs are not steps);
- a change to which bucket, registry, repository, table or branch a
workflow writes to or deletes from;
- a `uses:` outside the `pytorch` org, or a step moved out of the build
container;
  - a test job added to `pull.yml` or `trunk.yml`;
  - coverage removed in a merge-gating workflow.
- **Security**, an existing hard stop, now names secrets, tokens,
permissions, runner trust boundaries, and release or publish plumbing
(the workflows that publish wheels, conda packages, docs and release
tags).
- **Hiding CI failure**, a new hard stop, catches a test or job that
still runs and fails but no longer blocks what it blocked. Examples:
`continue-on-error`, `|| true` on a test step, a name gaining
`unstable`, a workflow dropped from `requires`, or an exit status
ignored in `run_test.py`, a `conftest.py` or `run_tests`.

**Pinned third-party code**, a new hard stop: moving a submodule or a
commit pin of third-party code (such as `ci_commit_pins/`), pointing a
requirement at a commit, branch or URL instead of a released version, or
changing a pinned version of third-party code built into or published
with PyTorch's released artifacts. None of the reports is such a bump.

**C10. Breadth counts unchecked sites.** "Edits at sites you have not
checked" replaces "Breadth disguised as simplicity". A repeated edit is
one change when every site follows one mechanical rule and every site
was checked, by reading them or by searching for what is left of the old
form. The number of sites is not a reason on its own. A change to a
definition other tests are generated from (an OpInfo's or ModuleInfo's
dtypes, devices or samples, the dtypes or devices a device-type test
template is instantiated for, a shared parametrization list) is an edit
at every test that iterates it, suites that do not run on pull requests
included: the reviewer checks that each consumer handles what the change
adds, or the description reports a run that covers them.

**C11. Merge authorization.** One item names `.github/merge_rules.yaml`,
`.github/scripts/trymerge.py`, `.github/scripts/tryrebase.py`,
`.github/scripts/greenlight_*.py`, the modules those scripts import, and
anything else deciding who or what may approve or land a PR. It absorbs
the separate land-time-guard item.

**Re-landing a reverted change**, a new hard stop: the PR, or a commit
it applies again, was reverted from main, and the description does not
say what broke and what in the diff fixes it (which the reviewer
confirms by reading the diff).

**Test gates are traced.** Under criterion 1 (Correctness), for every
class: the reviewer traces what a skip, expected failure or other gate
does with its condition's value, on the platforms it names and on the
others, reading the gate's own implementation where the checkout has it
(for `unittest` or `pytest` gates, the condition's own type settles it).
A gate whose effect differs from what its condition says (wider,
narrower, or a no-op, as with a decorator that acts only on a real
`bool` handed a lazily evaluated object) is a finding.

These last three come from replaying the policy against historical
GreenLight PRs that were later reverted. An OpInfo dtype widening broke
a slow-only suite (pytorch/pytorch#198860). A version of a test-gating
change handed a lazily evaluated value to a skip decorator that only
acts on a real `bool`, so the skip did nothing (pytorch/pytorch#198689).
And the reviewer should not stamp re-lands blind. None of the 12 reports
above is affected.

**Also in the skill:**
- The opening says the author "holds merge rights in some part of the
repository".
- Only three hard stops apply on the path alone: executable docs build
configuration, pytorch's `.claude/` and `.agents/` trees and instruction
files, and merge authorization. Every other hard stop is decided by what
the change does.
- **Meta-internal only** covers code and build files only (never
documentation or instruction files), and never a file one of those three
path items names.
- pytorch's AI-assistant instruction files (`CLAUDE.md`,
`CLAUDE.local.md`, `AGENTS.md`, `.cursorrules`,
`.github/copilot-instructions.md`) join the `.claude/` hard stop, and so
does the `.agents/` tree, where pytorch's skills live.
- Established patterns: a defect at a new site is still a defect.
- The examples drop the "Socialization" topic.
- Unchanged: Type annotations, the mechanical-formatting paragraph,
Output Contract fields and reasons, Message format rules, Time budget,
and the rest of Security.

### C12. Eligibility (greenlight code)

A PR is eligible when a valid rule in pytorch/pytorch's
`.github/merge_rules.yaml` names its author in exact case, and trymerge
accepts its base (`main`, a ghstack PR, or a PR in a GitHub-native stack
on `main`), whatever files it changes. The review decides whether it
needs a human.

- `cohort.assess_rules` no longer reads files. A rule whose patterns
trymerge rejects still qualifies nobody (`MergeRule.valid`).
- The scan applies trymerge's base test from the listing's own fields,
with no extra GitHub request. `authority.Authority` becomes a pure
lookup.
- Dropped on purpose, along with the files read:
  - its failure, rate-limit and undetermined paths;
- the head deferral for a push that raced the files read, and the
deferred `--pr` recheck that came with it;
- the reasons "file listing unavailable" and "no single merge rule
naming this login covers all changed files".
- The `--pr` gate checks the author and the base on the PR it already
fetches.
- At record time, `verdict.has_eligible_author` (renamed from
`has_covering_rule`) makes one fresh read. The verdict is authoritative
only when the head is still the reviewed head, the base is accepted and
a valid rule names the author. Catch-all authors get the head and base
check too.
- A PR over 200 files is now dispatched and gets the workflow's canned
`scope_too_large` NO_LAND.
- `TRUSTED_AUTHORS.md`, `STATUS_LABELS.md`, `README.md`, `CLAUDE.md`,
`CHEATSHEET.md`, the CLI help, the workflows' comments and
`tools/torchci/greenlight_decisions/README.md` are updated.

## Why

The 12 open GreenLight feedback reports are all trivial-in-spirit PRs
that GreenLight sent to a human, or never reviewed. The policy had three
parallel decision procedures: the two triviality questions that "outrank
everything", criterion 8, which repeated them, and the Decision bullets.
Fixing one left the others refusing.

Its rules were also built from per-case exceptions, and the open
follow-up stack (#9127-#9130, #9295-#9298) continues that style: one
kind added to one class per case. By its own replays that stack still
leaves #9098, #9093, #9140 and #8885 refused, and it does not touch
#9359, #9358, #9304 or #9329/#9335.

This PR replaces that with broad rules a person can read, each simple
and linear: no rule carves an exception out of another. Easing gates is
the point. Flipping other PRs to LAND along the way is expected, and the
areas where a mistake is costly stay hard stops: security, CI privilege,
merge authorization, publishing, the reviewer's own instructions, and
hiding CI failure.

Judged by reading the policy against each report; no evals or replays
were run for this.

# Notes

- **Supersedes** #9127, #9128, #9130, #9295, #9296, #9297 and #9298.
Their generic parts are folded in: #9128's API definition, #9130's
reported runs, and #9298's defects-only idea, generalized. #9129
(performance grounding) is not needed for these flips and is left as is.
- **Follow-ups once the greenlight-scan release is live**:
- Dr. CI's GreenLight line
(`torchci/lib/greenlight/greenlightEligibility.ts`, a port of
`assess_rules`) still renders "can't be reviewed due to
`merge_rules.yaml` restrictions" for PRs outside an approver's paths. It
is left unchanged here because the HUD deploys on every push to `main`
and would advertise reviews before the scan runs them.
- Dr. CI's port also shows "waiting for review" for an approver named by
a catch-all rule on any base, so once the release is live a PR on a base
trymerge refuses would show that until the port learns the base test.
- pytorch/pytorch `CONTRIBUTING.md` ("## GreenLight") describes the old
eligibility rule.
- **Accepted risks, stated as what is no longer checked**:
- About 80 logins named only by path-scoped merge rules can now land
anywhere on a LAND: GreenLight's approval satisfies the `*` Greenlight
Review Bot rule. The hard stops still send security, CI privilege, merge
authorization, publishing and release plumbing to a human.
- The reviewed base is not bound at land time for any approver: the
"base not bound" exposure in `TRUSTED_AUTHORS.md` now covers every
approver. Binding the reviewed merge base belongs in pytorch's land-time
guard and is a separate change.
- Kernel-configuration changes, private extension points and header-only
linkage changes land without a human (C5, C6).
- Coverage can drop silently in workflows that gate no merge,
label-triggered ones included (C9).
- Runs the description reports are taken as true (C2), and
platform-scoped fixes often have no pre-merge CI on that platform (C4).
- A pattern with a flaw can be copied to new sites of the same kind
(C7).
  - Dropped conditions:
- C3 drops "production code rejects the skipped case" and "no wider than
its guard";
    - C4 drops "no value shared across configurations that differ";
    - C1 drops the cumulative class exclusions;
    - criterion 4 drops "sprawl across many subsystems";
- #9127's job-name rules and #9296's "still runs on full-size devices"
are not carried over.
- A catch-all author's PR on a base trymerge refuses has GreenLight's
approval dismissed. If it is later retargeted to `main`, it is not
re-reviewed until its fingerprint changes. A retarget between the scan
and the record can leave a review shown as not completed.
- **Pushes run the policy replay**: later pushes to this branch run
`greenlight-policy-replay.yml`, because it touches the skill.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request GL/human GreenLight marked as needing human review in progress PR is being worked on by the author, until the automated review accepts it Merged topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants