A tensor and machine-learning framework with Python APIs and native CPU and GPU implementations.
On this page
Overview
PyTorch's AGENTS.md points to CLAUDE.md for contribution policy, native builds, tests, CUDA, and ghstack. Many rules name a failure that normal Python or Git habits can cause, then give the repository-specific command instead.
Expose the cost hidden behind a documentation edit
The Docker directory is content-hashed as a whole, so even its README participates in rebuild decisions. The guide warns against touching that directory during an upstream build outage unless a rebuild is intended.
Source excerpt starting at line 38.
38need rebuilding. Any file change inside `.ci/docker/` (including the README)39changes the hash and triggers a full Docker image rebuild. Do not make changes
02 / Scope layering
Distinguish intentional detached HEAD from a missing branch
The Git section treats detached HEAD as part of ghstack, while ordinary branch work should branch first. The subsequent workflow preserves metadata trailers and routes submission through ghstack.
Source excerpt starting at line 111.
111- If HEAD is detached, that is intentional (the ghstack workflow). Do NOT112 create a new branch; commit directly onto the current detached HEAD.
03 / Behavioral framing
Name a verification result that can be falsely green
A PR can have more check runs than one API page returns. The file replaces a fixed-size check-runs request with gh pr checks so omitted results are not interpreted as success.
Source excerpt starting at line 115.
115- **Pulling CI status.** A PR has hundreds of check-runs, so a single116 `check-runs?per_page=100` call silently truncates and makes red look green.
04 / Good and bad pairs
Reject a lint suppression that removes a runtime check
The S101 guidance explains that Python optimization strips assert statements. It shows an explicit conditional and AssertionError replacement, then preserves the original message and NaN-sensitive comparison semantics.
Source excerpt starting at line 90.
90# Bad - silences the rule; the check disappears under `python -O`91assert isinstance(x, Foo) # noqa: S1019293# Good94if not isinstance(x, Foo):95 raise AssertionError(f"expected Foo, got {type(x)}")
05 / Generated file guards
Edit type-stub templates rather than their products
The type-stub section names .pyi.in as the editable source for generated .pyi files. The distinction is stated directly so a type fix survives regeneration.
Source excerpt starting at line 70.
70Many `.pyi` files are generated from corresponding `.pyi.in` templates. Always71edit the `.pyi.in` file, not the generated `.pyi`.
Ideas for your repo
01Name changes whose operational cost is larger than their diff suggests.
02Detect the repository's workflow before applying generic Git habits.
03Document pagination limits that can conceal verification failures.
04Explain runtime semantics behind lint rules instead of recommending suppression.
Sponsored by
Give your agents the whole story.
These instructions explain how to work in PyTorch. Modem shows your agents what customers said, who is affected, and what changed.