PyTorch Agent Rules

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.

Documents

├── 
├──  · symlink → CLAUDE.md
├── .claude
│   └── skills
│       └── pr-review
│           └── 
├── torch
│   └── _dynamo
│       └── 
└── 

Patterns in this file

01 / Behavioral framing

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.
need rebuilding. Any file change inside `.ci/docker/` (including the README)changes 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.
- If HEAD is detached, that is intentional (the ghstack workflow). Do NOT  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.
- **Pulling CI status.** A PR has hundreds of check-runs, so a single  `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.
# Bad - silences the rule; the check disappears under `python -O`assert isinstance(x, Foo)  # noqa: S101 # Goodif not isinstance(x, Foo):    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.
Many `.pyi` files are generated from corresponding `.pyi.in` templates. Alwaysedit the `.pyi.in` file, not the generated `.pyi`.

Ideas for your repo

  1. Name changes whose operational cost is larger than their diff suggests.
  2. Detect the repository's workflow before applying generic Git habits.
  3. Document pagination limits that can conceal verification failures.
  4. Explain runtime semantics behind lint rules instead of recommending suppression.
Sponsored byModem

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.

See how Modem works