# System map — pytorch/pytorch

> Canonical page: https://codevetter.com/unpack/pytorch/system-map

# System map — pytorch/pytorch

Scanned commit 5711f1a4586cb0a3dbb3d67538df814db48f94f4 (2026-09-22). Generated by codevetter codevetter 1.12.0 on 2026-09-22.

PyTorch is a layered system: the c10 core library and ATen tensor library (C++), the autograd engine in torch/csrc/autograd, and the Python frontend package `torch` bound through torch._C (torch_python). Build is PEP 517 via scikit-build-core: pyproject.toml declares the backend, CMakeLists.txt is the native build entry point, and cmake/Codegen.cmake runs torchgen over native_functions.yaml to emit ATen headers/sources plus autograd and Python binding sources. Operator dispatch crosses the Python/C++ boundary through OpOverloadPacket/OpOverload in torch/_ops.py into the C++ dispatcher. CI is a large GitHub Actions matrix of reusable _binary-build/_binary-test workflows gated by a job-filter workflow; test selection uses target determination. Packaging installs CMake artifacts under the `torch` wheel directory with an extensive exclusion list to keep the wheel lean.
- The build backend is scikit-build-core (build-backend = "scikit_build_core.build"); PEP 517 builds run CMake, and requires-python is >=3.10. — [pyproject.toml#L3-24](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/pyproject.toml#L3-L24) [pyproject.toml#L348](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/pyproject.toml#L348)
- setup.py is a deprecated shim: `install`/`develop` forward to `pip install --no-build-isolation`, all other commands fail, and the file is scheduled for removal in PyTorch 2.18. — [setup.py#L1-64](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/setup.py#L1-L64)
- CMakeLists.txt is the native build entry point driven by scikit-build-core; its header comment documents the ordered stages: EnvVarForwarding, PreBuildSteps (git submodules + pinned NCCL fetch), Dependencies.cmake, codegen via cmake/Codegen.cmake (torchgen over native_functions.yaml) and tools/setup_helpers/generate_code.py, then add_subdirectory of torch/headeronly, c10 and caffe2. — [CMakeLists.txt#L1-46](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/CMakeLists.txt#L1-L46)
- `import torch` loads native deps before Python bindings: _load_global_deps() ctypes.CDLLs libtorch_global_deps.so with RTLD_GLOBAL, inspects /proc/self/maps for libcudart, then _preload_cuda_deps preloads cublasLt/cublas/cudnn/nvrtc/cudart/cupti/nccl etc. from site-packages before `from torch._C import *`. — [torch/__init__.py#L361-505](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/torch/__init__.py#L361-L505)
- On Windows, _load_dll_libraries() adds DLL directories, preloads vcruntime/msvcp DLLs, and LoadLibraryExW-loads every *.dll under torch/lib before importing torch._C. — [torch/__init__.py#L190-320](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/torch/__init__.py#L190-L320)
- torchgen/gen.py main() is the codegen CLI invoked at build time: it parses aten/src/ATen/native/native_functions.yaml and native/tags.yaml and emits ATen headers/sources, dispatcher registrations, and the AOTInductor C shim, with flags like --rocm/--mps/--xpu/--mtia and --per-operator-headers. — [torchgen/gen.py#L2866-3025](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/torchgen/gen.py#L2866-L3025) [aten/src/ATen/native/native_functions.yaml](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/aten/src/ATen/native/native_functions.yaml)
- The wheel ships packages torch, torchgen and functorch, with CMake artifacts installed into install-dir "torch"; a long exclude list strips static archives (*.a), C++ sources, third-party cmake configs, docs and dev files from the wheel. — [pyproject.toml#L151-295](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/pyproject.toml#L151-L295)
- Version and runtime dependencies are dynamic metadata: tools/metadata version provider resolves PYTORCH_BUILD_VERSION/PKG-INFO/version.txt, and the dependencies provider injects CUDA/ROCm/XPU pip deps from PYTORCH_EXTRA_INSTALL_REQUIREMENTS. — [pyproject.toml#L85-93](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/pyproject.toml#L85-L93)
- Console scripts are torchrun (-> torch.distributed.run:main) and torchfrtrace (-> flight recorder trace); the torch.distributed.backends entry-point group registers mpi/gloo/nccl/ucc/xccl/nccl4py backend factories. — [pyproject.toml#L383-399](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/pyproject.toml#L383-L399)
- The Python op surface is assembled at import: _C._initExtension(torch_shm_manager path) runs first, then every callable in _C._VariableFunctions is copied into torch's globals (appending to __all__), followed by submodule imports (cpu, cuda, xpu, mps, mtia, distributed, nn, optim, fx-related) and _C._init_names. — [torch/__init__.py#L2600-2796](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/torch/__init__.py#L2600-L2796)
- Native dependencies are vendored as git submodules under third_party/ (pybind11, googletest, protobuf, gloo, NNPACK, pthreadpool, benchmark, and more). — [.gitmodules](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/.gitmodules)
- CI is GitHub Actions: trunk.yml runs on pushes to main/release/*/landchecks plus a nightly cron, fronted by job-filter.yml and target_determination.yml (with llm_td_retrieval) that gate which reusable _binary-build/_binary-test workflows execute; pull.yml does the same for PRs. — [.github/workflows/trunk.yml#L1-60](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/.github/workflows/trunk.yml#L1-L60) [.github/workflows/pull.yml#L1-45](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/.github/workflows/pull.yml#L1-L45)
- Editable installs use scikit-build-core redirect mode: Python files resolve from the source tree, CMake artifacts from the build tree, and rebuild-on-import is off by default (opt-in via SKBUILD_EDITABLE_REBUILD). — [pyproject.toml#L297-306](https://github.com/pytorch/pytorch/blob/5711f1a4586cb0a3dbb3d67538df814db48f94f4/pyproject.toml#L297-L306)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
