CodeVetter · Repo Unpack · Contributor handoff
pytorch/pytorch
AGENTS.md is mandatory reading and unusually specific: build ONLY via `pip install -e . -v --no-build-isolation`, test via run_tests/TestCase + instantiate_device_type_tests, lint via spin lint/fixlint plus `lintrunner -a` before commits, and never `noqa: S101` an assert (rewrite as raise AssertionError). Edit .pyi.in templates not generated .pyi; never touch .ci/docker (content-hash rebuilds); respect the ghstack workflow (detached HEAD is intentional, never push, preserve trailers). Style: minimal comments, ASCII-only in new comments, explicit state, match existing patterns. Use agent_space/ for scratch. AI_POLICY.md requires marking all AI-generated content in GitHub interactions.
- Build rule: 'All build (both codegen, C++ and python) is done via pip install -e . -v --no-build-isolation. You should NEVER run any other command to build PyTorch.'
- Test rule: tests subclass torch.testing._internal.common_utils TestCase and call run_tests(); assertEqual for tensor equality, @parametrize for input sets, instantiate_device_type_tests for device-generic numerics tests.
- Lint rule: only spin-provided commands (spin lint / spin fixlint); run `lintrunner -a` before committing and fix what it reports.
- S101 rule: never silence 'use of assert' with noqa — rewrite `assert cond, msg` as `if not cond: raise AssertionError(msg)` because python -O strips asserts; do not invert float comparisons (NaN).
- Generated-file rule: many .pyi files are generated from .pyi.in templates — always edit the .pyi.in, never the generated .pyi.
- .ci/docker/ is content-hashed for image rebuilds — any change (even README) triggers a full Docker rebuild; don't touch it unless intending to rebuild, and avoid it entirely when Docker builds are broken upstream.
- Git/ghstack rules: detached HEAD means ghstack flow (commit directly, don't branch); never amend or push ghstack commits unless asked; preserve ghstack-source-id and Pull-Request trailers; submit with ghstack (--no-stack for single commits); never push to gh/USER/N branches.
- Commit message rules: include a Test Plan section with literal fenced commands, explain root cause for bug fixes, disclose AI authorship, and don't bullet-list individual changes.
- Use agent_space/ (git-ignored, repo root) for scratch scripts and throwaway experiments; never commit from it. Check for a .venv in repo root/parent before assuming missing tools.
- Dynamo debugging kit: TORCH_LOGS=guards,graph_breaks,graph_code,+dynamo,bytecode; TORCH_TRACE=dir + tlparse for production artifacts via trace_structured; torch._dynamo.config.patch for config toggles; bytecode_debugger for generated-code segfaults.
- Style rules: minimal self-documenting code, no trivial one-use helpers, explicit class state (no dynamic setattr/getattr), match existing patterns, ASCII-only in new comments, and prefer keeping long lines readable via locals instead of ruff-driven splits (noqa: B950 on the closing quote for golden strings).
- Build configuration is env-var driven (MAX_JOBS, DEBUG, REL_WITH_DEB_INFO, USE_*/BUILD_*); cmake/EnvVarForwarding.cmake is the single source of truth for env vars — add and document new knobs there.
- For op work the first reads are aten/src/ATen/native/README.md (schema language + dispatch table conventions), native_functions.yaml, and torchgen/gen.py; for compile work read torch/_dynamo/CLAUDE.md then eval_frame.py/convert_frame.py/symbolic_convert.py.