RuleStack

Configs

Stacks

Compare

Diff

RuleStack

Configs

Stacks

Compare

Diff

Read API

RuleStack

Configs

Stacks

Compare

Diff

Read API

Configs/Copilot instructions/pytorch/pytorch

Copilot instructions

.github/copilot-instructions.md
Copilot instructions

Quality

100/100

Scores the file, not the repository.

Length

594 words

17 headings · 5 code blocks

Repository

102k

— · pushed 0 days ago

Last changed

3 days ago

First indexed 3 days ago.
pytorch/pytorch/.github/copilot-instructions.mdRawGitHub
1# PyTorch Copilot Instructions
2 
3This is the PyTorch machine learning framework codebase. These instructions help AI agents navigate and contribute effectively.
4 
5## Architecture Overview
6 
7### Core Components
8 
9- **c10/** - Core library (C++-10 compatible) for essential, binary-size-conscious functionality
10- **aten/** - ATen tensor library (C++), PyTorch's foundation without autograd
11 - `aten/src/ATen/native/` - Modern operator implementations (CPU/CUDA/MPS/sparse)
12 - `aten/src/ATen/native/native_functions.yaml` - **Critical**: Declarative operator registry
13- **torch/** - Python bindings and public API
14 - `torch/csrc/` - C++ Python bindings (hand-written and generated)
15 - `torch/csrc/autograd/` - Reverse-mode automatic differentiation
16 - `torch/csrc/jit/` - TorchScript JIT compiler
17- **torchgen/** - Code generation tooling that reads `native_functions.yaml`
18- **tools/** - Build scripts, autograd derivatives, code generation
19 
20### The Code Generation Workflow
21 
22**Most operator changes require editing `native_functions.yaml`**, not direct C++ files. This YAML file:
231. Declares operator signatures, variants (function/method), and dispatch behavior
242. Gets processed by `torchgen/` to generate C++/Python bindings
253. Produces headers in `build/aten/src/ATen/` during compilation
26 
27Example entry structure:
28```yaml
29- func: my_op(Tensor self, Scalar alpha=1) -> Tensor
30 variants: function, method
31 dispatch:
32 CPU: my_op_cpu
33 CUDA: my_op_cuda
34```
35 
36After editing `native_functions.yaml`, implement kernels in `aten/src/ATen/native/` (see `aten/src/ATen/native/README.md`).
37 
38## Development Workflows
39 
40### Building from Source
41 
42**Never run `setup.py` directly** - use pip with editable install:
43```bash
44python -m pip install --no-build-isolation -v -e .
45```
46 
47Speed up builds:
48- `DEBUG=1` - Debug symbols with `-g -O0`
49- `USE_CUDA=0` - Skip CUDA compilation
50- `BUILD_TEST=0` - Skip C++ test binaries
51- Install `ninja` (`pip install ninja`) for faster builds
52- Use `ccache` for incremental compilation caching
53 
54Rebuild specific targets: `(cd build && ninja <target>)`
55 
56### Testing
57 
58**Critical**: DO NOT run entire test suites. Run specific tests only:
59```bash
60python test/test_torch.py TestTorch.test_specific_case
61```
62 
63**Test structure**: All tests use `torch.testing._internal.common_utils`:
64```python
65from torch.testing._internal.common_utils import run_tests, TestCase
66 
67class TestFeature(TestCase):
68 def test_something(self):
69 # Use self.assertEqual for tensor comparisons
70 pass
71 
72if __name__ == "__main__":
73 run_tests()
74```
75 
76**For bug fixes**: Create a standalone reproduction script first, verify it fails, then fix and add to appropriate test file.
77 
78### Linting
79 
80Run linter (not pre-commit): `lintrunner -a` (auto-applies fixes)
81 
82## Project-Specific Conventions
83 
84### Memory and Storage
85- **Storage is never nullptr** (but `StorageImpl.data` may be nullptr for unallocated outputs)
86- CUDA device info lives in storage objects
87 
88### Python-C++ Integration (`torch/csrc/`)
89- Always include `Python.h` **first** to avoid `_XOPEN_SOURCE` redefinition errors
90- Use `pybind11::gil_scoped_acquire` before calling Python API or using `THPObjectPtr`
91- Wrap entry points with `HANDLE_TH_ERRORS` / `END_HANDLE_TH_ERRORS` for exception conversion
92 
93### Dispatch System
94- PyTorch uses operator dispatch to route calls to backend-specific kernels
95- Prefer `CompositeExplicitAutograd` dispatch when writing device-agnostic compound ops
96- See `aten/src/ATen/native/README.md` for dispatch keyword guidance
97 
98## Git Workflow (AI Agent Specific)
99 
100When preparing PRs from this environment:
101```bash
102git stash -u
103git reset --hard $(cat /tmp/orig_work.txt) # Reset to LOCAL branch
104git stash pop
105# Resolve conflicts if necessary
106```
107 
108## Common Gotchas
109 
1101. **Editing generated files** - If it's in `build/`, don't edit it. Edit the source template or `native_functions.yaml`
1112. **NVCC template compilation** - NVCC is stricter about C++ than gcc/clang; code working on Linux may fail Windows CI
1123. **Windows symbol visibility** - Use `TORCH_API` macros for exported symbols (required on Windows, optional on Linux)
1134. **No internet access** - DO NOT attempt to install dependencies during development
114 
115## Key Files Reference
116 
117- `AGENTS.md` - Instructions specific to AI coding agents
118- `CONTRIBUTING.md` - Comprehensive human contributor guide
119- `GLOSSARY.md` - Terminology (ATen, kernels, operations, JIT, TorchScript)
120- `aten/src/ATen/native/README.md` - Operator implementation guide
121- `tools/autograd/derivatives.yaml` - Gradient definitions for autograd
122 
123## Performance Debugging
124 
125Use `TORCH_SHOW_CPP_STACKTRACES=1` for C++ traces in Python errors. For profiling, prefer `py-spy` over manual instrumentation.
126 

Commands it names

  • python -m pip install --no-build-isolation -v -e .
  • python test/test_torch.py TestTorch.test_specific_case
  • git stash -u
  • git reset --hard $(cat /tmp/orig_work.txt)
  • git stash pop
  • ninja
  • pip install ninja

Sections

  • PyTorch Copilot Instructions
  • Architecture Overview
  • Core Components
  • The Code Generation Workflow
  • Development Workflows
  • Building from Source
  • Testing
  • Linting
  • Project-Specific Conventions
  • Memory and Storage
  • Python-C++ Integration (`torch/csrc/`)
  • Dispatch System
  • Git Workflow (AI Agent Specific)
  • Resolve conflicts if necessary
  • Common Gotchas
  • Key Files Reference
  • Performance Debugging

What it covers

setupbuildtestcode-stylearchitecturegit-prperformancedo-notagent-behaviour

Stack — with the evidence

python

(1.00)

pytorch

(0.70)

cpp

(0.60)

pytest

(0.60)

docker

(0.60)

github-actions

(0.60)

Format

Copilot instructions

Two layers: one always-on repo file, plus optional glob-scoped instruction files. Lives under .github/ rather than the repo root, which is the tell that it is aimed at the GitHub platform surface as much as the editor.

What the corpus says about it

Repository

Owner
pytorch
Language
—
License
—
Archived
no

All configs in this repo

Also in pytorch/pytorch

Diff this repo’s formats

One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?

The other instruction files in this repository
RepositoryFormatStackCoversScoreChanged
pytorch/pytorchCLAUDE.md · 102kCLAUDE.mdpythonpytorch+4setupbuildtestlint-format+588/1003 days ago
pytorch/pytorchtorch/_dynamo/CLAUDE.md · 102kCLAUDE.mdpythonpytorch+4buildteststylearch84/1003 days ago
Diff against CLAUDE.md Diff against torch/_dynamo/CLAUDE.md

Similar configs

Same format, overlapping stack, ranked by quality.

Same format, overlapping stack, ranked by quality
RepositoryFormatStackCoversScoreChanged
hiyouga/LlamaFactory.github/copilot-instructions.md · 74kCopilot instructionspythontransformers+4setupbuildtestlint-format+597/1002 days ago
darkmatter/nixmac.github/copilot-instructions.md · 24Copilot instructionstypescriptrust+14setupbuildtestlint-format+896/1003 days ago
iloveitaly/llm-ide-rules.github/copilot-instructions.md · 13Copilot instructionspythonpytest+2teststyledo-notagent-behaviour+192/1003 days ago
bytedance/deer-flow.github/copilot-instructions.md · 79kCopilot instructionstypescriptpython+15setupbuildtestlint-format+689/1003 days ago
tesseract-ocr/tesseract.github/copilot-instructions.md · 76kCopilot instructionscppgithub-actionssetupbuildtestlint-format+589/1003 days ago
iloveitaly/llm-ide-rules.github/instructions/python.instructions.md · 13Copilot instructionspythonpytest+2setupstyletypesdo-not88/1003 days ago
Significant-Gravitas/AutoGPT.github/copilot-instructions.md · 186kCopilot instructionspythonnode+19setupbuildtestlint-format+1088/1003 days ago
microsoft/WSL.github/copilot-instructions.md · 33kCopilot instructionscsharpcpp+2setupbuildtestlint-format+788/1003 days ago
RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack

RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack

RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack