The first difficult part of contributing to PyTorch is not opening a pull request. It is turning a useful observation into a small change a maintainer can understand, test, review, and safely merge. PyTorch's scale can feel intimidating, but it offers a durable method: make the problem precise, follow local conventions, validate the narrowest relevant behaviour, and leave behind evidence another person can inspect.
01 / Choose a finishable scope
Start with a problem shape that can reach a useful conclusion.
The best early contribution is usually bounded. It has observable behaviour, a plausible owner, and a way to prove the outcome. Documentation corrections, focused bug fixes, test coverage, and well-triaged regressions are all valuable starts. The PyTorch contribution page lists current good-first issues; labels also provide useful clues about the module and the team that owns it.
- Describe what happens today.Capture the current behaviour with the relevant version, platform, device, dtype, model shape, or error message.
- State the expectation.Explain the user- or developer-visible behaviour that should change before proposing a mechanism.
- Find the narrowest owner.A Python API, native operator, compiler path, distributed component, documentation page, or test helper each has a different validation and review path.
- Define the proof.A failing test, minimal reproduction, before-and-after result, or documentation rendering check is the beginning of acceptance criteria.
For a non-trivial change, find or open an issue before writing a large patch. Scope can be corrected much more cheaply there. A useful issue includes the smallest reproduction, observed and expected behaviour, environment details, and evidence that the behaviour is a regression. If a change affects an API, compatibility, or a major design, pause for maintainer direction instead of starting with a large implementation.
A good first contribution is not the smallest diff. It is the smallest change with a clear problem, an appropriate test, and a reviewable explanation.
02 / Read the tree
Let the source layout tell you what kind of change you are making.
Before changing a nearby line, find a recent change in the same subsystem, read its test, and follow the call path one or two layers outward. An operator or API change usually has implementation code, public documentation, metadata, and tests that must agree. A workflow change needs its consumer and its contract validation, not just an edited YAML file.
torch/andtorch/csrc/Python-facing implementation, C++ heavy lifting, bindings, and subsystems such as autograd and distributed.aten/andtorchgen/Core tensor and operator work, plus the machinery that generates low-level C++ and Python bindings from operator definitions.test/Python and C++ tests, expected-output fixtures, and the CI-style test entry point.torch/testing/_internal/Shared test utilities, device-type instantiation, and operator metadata helpers..github/and.ci/Workflow and CI behaviour; changes here deserve special care because they can affect a PR's own evaluation path.
The live contributing guide is the repository-specific source of truth. It documents the current layout, code-generation responsibilities, lint tools, test entry points, PR requirements, and help channels. Treat a command copied from an old issue or blog post as a lead, not a replacement for those living instructions.
03 / Set up the right environment
Build only the path your change needs, but record the context.
A local machine does not need to resemble every PyTorch CI runner. It needs a repeatable loop for the change you own, plus a clear understanding of which coverage needs CI or specialized hardware. Record your operating system, Python version, compiler or runtime, build configuration, and accelerator context before comparing results.
- Python-only behaviour.Start with an editable checkout and focused CPU validation where that represents the affected path.
- Native C++ or operator work.Use the compiler and build configuration required for the subsystem, then validate the narrowest affected test.
- Accelerator or distributed work.Be explicit about CUDA, ROCm, MPS, XPU, networking, or hardware coverage that local validation cannot establish.
- Documentation and workflows.Follow their own rendering and contract conventions; a unit test alone does not prove a workflow change is correct.
Fork the repository, branch from current main, and follow the active setup
instructions exactly. Once the checkout is ready, use maintained tooling rather than
guessing commands:
spin --help
spin quicklint
python test/run_test.py -h
The contributor guide documents the current development, lint, and code-generation paths. Use a generator only when the change requires it, and include generated output only when repository convention expects it.
04 / Understand generated tests
A CI test name may describe a concrete case, not the source method you wrote.
PyTorch tests often generate cases at import time. A single template can expand across devices, dtypes, layouts, and operators. That is why a failure can name a CUDA float32 specialization rather than the source-level test method. The generated name is useful evidence: it tells you the combination that actually failed.
TestCaseandrun_tests()Shared test behaviour fromtorch/testing/_internal/common_utils.py.@parametrizeMultiple input shapes or values without duplicating test bodies.- Device-type instantiation.
instantiate_device_type_tests()and decorators such as@dtypesgenerate device- and dtype-specific cases. - OpInfo.Operator metadata centralizes samples, supported dtypes, skips, decorators, and tolerance information for broad coverage.
test/run_test.pyThe CI-style runner provides selective execution, sharding, and specialized handlers.
Write tests at the right abstraction level. Use existing parameterization rather than near-duplicate test bodies, make numerical tolerances explicit when they are genuinely needed, and avoid hard-coding a device when the test is meant to be portable. The official test-infrastructure guide and testing wiki explain the model in detail.
05 / Validate narrowly, then widen deliberately
Run the smallest test that could disprove your hypothesis.
The exact command depends on the test and environment, but a focused loop is more useful than waiting for a broad test suite to fail. When a test is device- or dtype-instantiated, reproduce with the concrete generated name CI reported, not only the source template name.
# From the repository root, run a focused unittest-style case.
python test/test_file.py TestClass.test_name
# Or filter a test file by a useful substring.
pytest test/test_file.py -k "relevant_name" -v
# Use the CI-style runner when its selection or handlers are relevant.
python test/run_test.py test_file
- Prove the single case.Run the individual test or smallest reproduction that exercises the actual branch.
- Protect its neighbourhood.Run the containing test file or affected group when it can catch interactions the one case cannot.
- Run the relevant quality checks.Use the maintained lint and type-check paths appropriate to the changed files.
- Let CI cover the matrix.State clearly which platforms, devices, and configurations local validation cannot represent.
The test wiki notes that direct test-file execution is generally preferred for focused
iteration, while test/run_test.py adds CI-oriented selection, sharding, and
handlers. CI runs tests from the test directory, so an invocation difference
can matter; if it explains a failure, put that fact in the PR instead of calling it
unexplained flakiness.
06 / Build an evidence bundle
A pull request is a handoff, not a private notebook.
Make the PR readable in the order a maintainer needs it: explain the problem, describe the smallest appropriate approach, show how it was validated, and identify the risk. Keep unrelated formatting, refactors, and behaviour changes out of the same patch when possible; cohesion makes regression analysis and review more reliable.
- Title and problem.State the change and the failure mode or missing behaviour in a few precise sentences.
- Approach.Explain why this is the smallest fitting fix and call out material alternatives you did not choose.
- Validation.List focused tests, lint, or reproductions honestly, including relevant coverage that could not run locally.
- Risk.Call out platform, API, numerical, performance, generated-code, and workflow implications.
Link a non-trivial change to its issue, follow the live PR checklist and required labels, and complete the contributor-license-agreement step when its check directs you to do so. Automation helps reviewers, but it never replaces a clear explanation or ownership of the submitted patch.
07 / Triage CI
Turn a red check into a concrete question before changing code.
A failed CI job is not automatically a signal that the patch is wrong. First establish whether it is relevant, whether the failure reproduces, and which exact test configuration failed. Dr. CI is a useful starting point; the HUD job and its logs carry the evidence needed for a decision.
- Read the summary, then the job.Find the generated test name, device and dtype suffix, shard, revision, and first meaningful failure.
- Check the baseline.A failure that already occurs upstream may be unrelated, but only treat it that way with visible evidence.
- Reproduce the narrow case.Use the concrete generated name or focused filter locally whenever the environment permits it.
- Classify the failure.Common categories include a real regression, environment mismatch, test pollution, sharding assumptions, and numerical precision behaviour.
- Respond with evidence.Link the job, name the affected configuration, say what reproduced, and state the next action or why the job is unrelated.
Do not weaken a test simply to make a check green. Capture a flaky failure's mode and frequency. If a tolerance really needs adjustment, explain the numerical reason and keep coverage for the intended contract. If a shard is wrong, fix selection or isolation rather than rerunning indefinitely.
08 / Collaborate through review
Make it possible for the maintainer to understand the change without reading your mind.
Review is a technical conversation, not an obstacle after implementation. A strong reply either changes the code or explains, with evidence, why the existing approach is better. Keep discussion close to the relevant code and resolve a thread only after the change or agreement is visible.
The most useful review context is a minimal reproduction, subsystem details a reader cannot infer from the diff, before-and-after behaviour, a direct answer to the trade-off being raised, and a clear statement when CI has re-run on the latest commit. If the right reviewer is unclear, let the project's triage and module ownership route the work rather than randomly requesting people. Development-infrastructure office hours are available for questions about CI and the contributor experience.
Merge is the beginning of responsibility, not the end of it. Check that the change reaches the expected branch, close the related issue when appropriate, and help investigate any post-merge regression with the same evidence-first method. The goal is to leave PyTorch easier to change safely than it was before.
First-contribution checklist
Leave the next investigator a useful signal.
- Scope.I can state the current behaviour, expected behaviour, affected configuration, and why the proposed scope is bounded.
- Context.I read nearby code, tests, and recent changes before designing the patch.
- Evidence.I selected the smallest test that exercises the real behaviour and understand any generated device, dtype, or operator variant.
- Quality.I ran focused validation and the relevant lint path, and I know which coverage must be supplied by CI.
- Handoff.My PR describes problem, approach, validation, and risk honestly; I will respond to review with code or evidence.