This tree is produced by codegen/generate.py from the documentation in this
repository (_sources/**, llms-full.txt, _coverage/**). It mirrors the
documented PyTorch C++ API as a buildable codebase.
Provenance: this repository is auto-generated from
pytorch/pytorchdocs/cpp/source. Doc content changes belong upstream; only the generator and generated layout are maintained here.
include/— API-surface stub headers mirroring the real LibTorch header paths recorded under_coverage/(169 stubs generated).include/torch/**/*.hpp— header-only template stubs (nn::Module,data::Dataset,OrderedDict).src/— non-template reference implementations compiled into thegenerated_stubsstatic library.examples/<module>/— one runnable example per documentation page (52 examples). Each example has a singlemain()and doubles as a compile-test / smoke test.coverage_report.md— diff of the generatedinclude/tree against the 166 documented headers in_coverage/.
| Extension | Role |
|---|---|
.h |
Public API surface stubs, umbrella headers, stable-ABI / C-compatible interface |
.hpp |
Template-heavy, header-only implementations (nn/data templates, options) |
.cpp |
Non-template implementations and every compilable example program |
.cu |
CUDA-only kernels/examples, built only when a CUDA compiler is found |
.c and .hh files are deliberately not generated: neither extension is
used anywhere in the documented PyTorch C++ API.
./validate.sh /path/to/libtorch # or: cmake -S . -B build -DCMAKE_PREFIX_PATH=...
cmake --build build -j$(nproc)The build follows the documented LibTorch CMake pattern
(find_package(Torch REQUIRED), ${TORCH_CXX_FLAGS}, C++20, MSVC DLL copy).
CUDA .cu targets are only configured when check_language(CUDA) finds NVCC.
Every example is registered with CTest and runs as a smoke test once the tree is built against LibTorch:
./validate.sh /path/to/libtorch
ctest --test-dir build --output-on-failure -j$(nproc)Examples that exercise APIs missing from the installed LibTorch are skipped at
configure time via feature checks: stable/* needs torch::stable ops
(PyTorch ≥ 2.8), cuda/* needs CUDA-enabled headers, and xpu/* needs
XPU-enabled headers. The CI matrix uses the LibTorch 2.7.1 wheels, where those
three groups are skipped.
Generator unit tests (stdlib unittest, no LibTorch needed):
python3 -m unittest codegen.test_generate -v # from the repo rootpython3 ../codegen/generate.pyCurated examples (hand-written, doc-derived) are preserved on re-run; the generator only fills gaps for pages without a curated example. The generator is idempotent: re-running it never changes the checked-in tree, a property the CI workflows verify.
.github/workflows/ci.yml— codegen unit tests, a regeneration idempotency check, a skeleton configure without LibTorch, LibTorch builds of every example on Linux/Windows/macOS followed by the CTest smoke suite, and end-to-end runs of the curatedexamples/minimalandexamples/mnisttutorial apps..github/workflows/release.yml— tag pushes (v*) rerun the full build + test matrix and publish a GitHub release with the packaged generated tree and per-platform example binaries.