Project Structure
This is the PyTorch Tutorials website (pytorch.org/tutorials), built with Sphinx and Sphinx Gallery.
beginner_source/,intermediate_source/,advanced_source/,recipes_source/,unstable_source/— tutorial source files (.pyand.rst)index.rst,recipes_index.rst— card listings and toctrees for the websiteconf.py— Sphinx configuration (gallery dirs, extensions, theme)_static/— images, CSS, and thumbnailsrequirements.txt— all Python dependencies (Sphinx, tutorial packages).jenkins/— CI build scripts, data download logic, post-processingMakefile— build entry points
Tutorials authored as .py files use Sphinx Gallery format: top-level docstrings become RST prose, code blocks become executable cells. These are executed during builds and converted to Jupyter notebooks and HTML. Tutorials authored as .rst are static and their code is not executed.
Build
make html-noplot— builds HTML without executing tutorial code. Fast, no GPU needed. Use this for quick validation of RST/Sphinx structure.make docs— full build that downloads data, executes all.pytutorials, and produces the final site. Requires a GPU-powered machine with CUDA.GALLERY_PATTERN="my_tutorial.py" make html— build only a single tutorial by name (regex supported).
The CI build runs inside Docker across 15 GPU-powered shards via .jenkins/build.sh.
Linting
This repo uses lintrunner. Do not use spin, flake8, or other linters directly.
lintrunner -m main— lint changes relative to the main branchlintrunner --all-files— lint all files in the repo
Lintrunner checks trailing whitespace, tabs, and newline issues only. It does not check Python formatting, RST syntax, or Sphinx directives.
Testing
There is no unit test suite. Validation is done by building tutorials:
make html-noplotis the quick sanity check for RST and Sphinx errors.Full execution of
.pytutorials runs in CI on GPU shards.To test a single tutorial:
GALLERY_PATTERN="my_tutorial.py" make html
Tutorial File Format
Interactive tutorials are
.pyfiles using Sphinx Gallery conventions. Filenames should end in_tutorial.py.Non-interactive tutorials are
.rstfiles.Data dependencies must be added via
.jenkins/download_data.py, not the Makefile. Follow the existing patterns in that file.New Python package dependencies go in
requirements.txt.
Adding a New Tutorial
Place the file in the appropriate
*_source/directory based on difficulty level.Add a
customcarditementry inindex.rst(orrecipes_index.rstfor recipes).Add the tutorial to the corresponding
toctreeinindex.rst.Add a square, high-resolution thumbnail image to
_static/img/thumbnails/cropped/.
Coding Style Guidelines
Follow these rules for all code changes in this repository:
Minimize comments; be concise; code should be self-explanatory.
Match existing code style and architectural patterns.
Tutorial prose should be written for a global audience with clear, easy to understand language. Avoid idioms.
Use active voice in tutorial instructions.
If uncertain, choose the simpler, more concise implementation.