# Package ######################################################################
[build-system]
requires = [
"numpy",
"packaging>=24.2", # required by setuptools>=77 to validate PEP 639 license expressions
"pyyaml",
# The floor usually names a minor release; this one needs the patch level
# too. CI pins the exact version we test against in
# .ci/docker/requirements-ci.txt.
"scikit-build-core>=1.1.1",
# Imported by torchgen at build time (cmake/Codegen.cmake runs
# `python -m torchgen.gen`, and torchgen/utils.py uses `Self` /
# `assert_never`). Currently also pulled in transitively through
# scikit-build-core, but list it explicitly as a direct build-time
# dep. Keep the lower bound in sync with the wheel runtime requirement.
"typing-extensions>=4.15.0",
]
build-backend = "scikit_build_core.build"
[tool.scikit-build]
# Track the build-system.requires floor so the schema and defaults are pinned
# to the version we build against.
minimum-version = "build-system.requires"
build-dir = "build"
[tool.scikit-build.env]
# MAX_JOBS is PyTorch's umbrella parallelism knob (also read by
# linters, cpp_extension JIT, nccl/MKLDNN sub-builds); alias it to the
# variable CMake natively honors for `cmake --build`. setdefault semantics:
# a user-set CMAKE_BUILD_PARALLEL_LEVEL always wins.
CMAKE_BUILD_PARALLEL_LEVEL = { env = "MAX_JOBS" }
# Listing CC/CXX here opts out of scikit-build-core's sysconfig-compiler
# injection (a documented env-table behavior), so CMake detects the compiler
# from PATH -- avoids the conda compiler_compat / stale-venv-gcc probe breaks.
# An ambient CC/CXX is still respected.
CC = { env = "CC" }
CXX = { env = "CXX" }
# cmake.build-type is deliberately not set: it defaults to Release, and
# leaving it unconfigured lets scikit-build-core honor a CMAKE_BUILD_TYPE
# set in the environment (.ci/pytorch/build.sh exports RelWithAssert for
# *-debug CI images). The overrides below map PyTorch's DEBUG and
# REL_WITH_DEB_INFO env vars to the corresponding build types; on
# multi-config generators (Visual Studio) the resolved type is passed as
# --config to cmake --build and cmake --install, ensuring they match.
[[tool.scikit-build.overrides]]
if.env.DEBUG = true
cmake.build-type = "Debug"
[[tool.scikit-build.overrides]]
if.env.REL_WITH_DEB_INFO = true
cmake.build-type = "RelWithDebInfo"
[[tool.scikit-build.overrides]]
# Force the Ninja generator on Windows. scikit-build-core otherwise defaults to
# the Visual Studio (multi-config) generator, under which the oneDNN-XPU
# ExternalProject's -DCMAKE_CXX_COMPILER=icx is ignored (VS picks the compiler by
# toolset), so oneDNN configures with MSVC and fails its -fsycl driver check.
# Generator resolution honors cmake.define.CMAKE_GENERATOR, so this lives
# here as the single source of truth
# (and covers plain non-CI editable builds too) instead of a CI-exported env var.
#
# Under Ninja, CMake does not default to MSVC: with the Intel oneAPI environment
# active (XPU builds) icx is on PATH and gets picked up as the host compiler,
# which miscompiles CPU code (icx passes sleef's __float128 cmake probe but then
# cannot compile sleefqp.c on the Windows target, ENABLEFLOAT128 gets set, the
# build fails). Pin CC/CXX=cl so the host build stays on MSVC while the XPU
# sub-projects keep using icx. env.CC/CXX setdefault semantics respect an
# explicitly set CC/CXX (e.g. clang-cl); platform-system matches sys.platform.
if.platform-system = "win32"
cmake.define.CMAKE_GENERATOR = "Ninja"
env.CC = "cl"
env.CXX = "cl"
# Other than CMAKE_GENERATOR above (win32), cmake.define is intentionally absent
# -- all BUILD_*/USE_* env vars and additional passthrough variables are
# forwarded by cmake/EnvVarForwarding.cmake so there is a single source of truth.
[[tool.dynamic-metadata]]
# Delegates to tools/generate_torch_version.py which resolves the version from
# PYTORCH_BUILD_VERSION (release/nightly), PKG-INFO (sdist), or version.txt.
provider = { path = "tools/metadata", module = "version" }
[[tool.dynamic-metadata]]
# Reads PYTORCH_EXTRA_INSTALL_REQUIREMENTS env var (pipe-separated PEP 508
# strings) to inject CUDA/ROCm/XPU pip package dependencies into the wheel.
provider = { path = "tools/metadata", module = "dependencies" }
[tool.scikit-build.sdist]
# Goal: ship exactly the git-tracked sources, minus repo/CI plumbing. The
# sdist file walk applies gitignore semantics, and several vendored trees
# commit files their own .gitignore matches (XNNPACK gen/ microkernels,
# oneDNN *.cpp via ideep, protobuf *.pb.cc, clog under deps/); PyTorch's own
# .gitignore (gen, *.pb.h) also hits tracked third-party files. The blanket
# includes below restore all of them.
#
# Mechanics governing both lists: an include match beats every exclude
# source (this exclude list, gitignore, built-ins). A !-negation inside
# include is not an exclusion -- it only withdraws include protection, and
# the file still ships unless an exclude source then catches it (built-ins
# catch .git and bytecode; .gitignore catches nccl, which is not a submodule
# but cloned into the tree at build time; the exclude list catches .github).
# That is why **/.github/** appears twice: the negation unprotects it under
# third_party/**, the exclude entry actually drops it -- there and at the
# top level. The exclude list is likewise the only mechanism dropping
# plumbing (.ci, .claude, .spin) that no include pattern covers.
#
# The flatbuffers/ittapi/NVTX entries drop unneeded language bindings, which
# also contain symlinks (#157814; NVTX's rust/ crate links to its c/ headers).
# resolve-symlinks = "error" fails the sdist
# build if a symlink is still among the included files, naming it, instead of
# silently copying its target (the "all" default) or storing a link. Every
# tracked symlink is therefore listed explicitly below (negated here, dropped
# in exclude); none of them is needed to build from the sdist, and the one
# whose content matters, docs/requirements.txt, is force-included from its
# target instead.
resolve-symlinks = "error"
include = [
"third_party/**",
"aten/src/ATen/native/quantized/cpu/qnnpack/deps/**",
# NCCL is not shipped (see !third_party/nccl/** below); the configure step
# clones it from this pin instead, so the pin must survive the .ci/** exclude.
".ci/docker/ci_commit_pins/nccl*.txt",
"!**/.git",
"!**/__pycache__/**",
"!**/*.pyc",
"!third_party/nccl/**",
"!third_party/nccl-extensions/**",
# third_party/build/ is an in-tree CMake build dir (gitignored); un-include
# it so a dirty checkout does not leak build output into the sdist. Anchored
# like the .gitignore entry, so it does not touch tracked build/ dirs deeper
# in vendored trees (e.g. cutlass docs, ideep).
"!third_party/build/**",
"!**/.github/**",
"!third_party/flatbuffers/java/**",
"!third_party/flatbuffers/kotlin/**",
"!third_party/flatbuffers/docs/source/CONTRIBUTING.md",
"!third_party/ittapi/rust/**",
"!third_party/NVTX/rust/**",
# Symlinks (see resolve-symlinks above).
"!third_party/XNNPACK/tools/xngen",
"!third_party/cudnn_frontend/.claude/**",
"!third_party/flash-attention/AGENTS.md",
"!third_party/flatbuffers/tests/ts/bazel_repository_test_dir/.npmrc",
]
exclude = [
"**/.github/**",
".agents/**",
".ci/**",
".claude/**",
".spin/**",
"third_party/flatbuffers/java/**",
"third_party/flatbuffers/kotlin/**",
"third_party/flatbuffers/docs/source/CONTRIBUTING.md",
"third_party/ittapi/rust/**",
"third_party/NVTX/rust/**",
# Symlinks (see resolve-symlinks above).
".dockerignore",
"AGENTS.md",
"docs/requirements.txt",
"torch/distributed/AGENTS.md",
"third_party/XNNPACK/tools/xngen",
"third_party/cudnn_frontend/.claude/**",
"third_party/flash-attention/AGENTS.md",
"third_party/flatbuffers/tests/ts/bazel_repository_test_dir/.npmrc",
]
[tool.scikit-build.sdist.force-include]
# docs/requirements.txt is a symlink into the excluded .ci tree; ship its target.
".ci/docker/requirements-docs.txt" = "docs/requirements.txt"
[tool.scikit-build.install]
# scikit-build-core auto-strips binaries in Release builds. PyTorch needs to
# keep symbols (e.g. for torch.utils.cpp_extension, ABI checks in CI).
strip = false
[tool.scikit-build.wheel]
# CMake install destinations (lib/, include/, share/cmake/) are relative to
# CMAKE_INSTALL_PREFIX. This setting places them under torch/ in the wheel,
# matching the existing layout (e.g., torch/lib/libtorch_cpu.so).
install-dir = "torch"
# Python packages to include in the wheel.
packages = ["torch", "torchgen", "functorch"]
# license-files is declared once under [project] (PEP 639 canonical location);
# scikit-build-core honors it directly. Do NOT also declare it here -- as of
# 0.12 that triggers an AssertionError.
# Mirror the legacy setup.py package_data allowlist as gitignore-style
# exclusions: without it, scikit-build-core's package walk plus the CMake
# install step ship ~2300 extra files (source trees, third-party static
# archives, cmake configs, dev artifacts) that the legacy setup.py omitted.
# This block is intended as a temporary filter; a follow-up will replace
# it with an install-component-based scheme that suppresses third-party
# install rules at source.
exclude = [
# Static archives never belong in a Python wheel (legacy package_data
# used a "lib/*.so*"/".dylib*"/".dll"/".lib" allowlist that excluded *.a
# implicitly). The largest single offender today is libtorch_xpu_ops.a
# at ~1.1GB.
"**/*.a",
# GNUInstallDirs places third-party cmake configs and static libs under
# lib64/ on x86_64; we don't ship any of them.
"torch/lib64/**",
# Bulk C++ source tree -- only the AOTI runtime header is consumed by
# downstream AOTInductor builds (and is staged explicitly via cmake).
"torch/csrc/**",
"!torch/csrc/inductor/aoti_runtime/model.h",
# Source-only directories the package walk picks up but setup.py excluded.
# Keep the .py modules nightly ships under torch/nativert/, and the
# libshm headers consumed at runtime (torch/lib/libshm/{*.h},
# torch/lib/libshm_windows/libshm.h).
"torch/nativert/**",
"!torch/nativert/**/*.py",
"torch/headeronly/**",
"torch/lib/libshm/**",
"!torch/lib/libshm/**/*.h",
"torch/lib/libshm_windows/**",
"!torch/lib/libshm_windows/**/*.h",
# Stray CMakeLists.txt copied in by directory installs.
"**/CMakeLists.txt",
# functorch dev artifacts (docs, notebooks, examples, op-analysis tools).
"functorch/docs/**",
"functorch/examples/**",
"functorch/benchmarks/**",
"functorch/op_analysis/**",
# torchgen autoheuristic tuning scripts (used to generate heuristics,
# not consumed at runtime).
"torchgen/_autoheuristic/**",
# Third-party cmake configs / docs that subproject installs leak in via
# GNUInstallDirs share/cmake/ destinations.
"torch/share/doc/**",
"torch/share/cmake/fbgemm/**",
"torch/share/cmake/kineto/**",
"torch/share/cmake/sleef/**",
"torch/share/cmake/XNNPACK/**",
"torch/share/cmake/ittapi/**",
"torch/share/cmake/dnnl/**",
"torch/share/cpuinfo/**",
# Windows analog of the above: third-party import libs and their CMake
# package configs / pkg-config files leak in via the subproject install()
# rules (GNUInstallDirs lib/cmake, plus *.lib), the way *.a + share/cmake/*
# do on Linux. The setuptools wheel ships none of these and downstream
# find_package(Torch) works: nothing in torch/share/cmake/ (the Torch
# config tree, shipped identically) consumes them -- MKLDNN/Protobuf resolve
# via QUIET + bundled-static fallbacks, and dnnl is statically linked into
# torch_cpu.dll. dnnl.lib alone is ~1.3GB uncompressed. Do NOT broaden to
# **/*.lib: torch's own c10/torch/torch_cpu/torch_python import libs are
# required for Windows downstream linking and must stay.
"torch/lib/dnnl.lib",
"torch/lib/kineto.lib",
"torch/lib/libprotobuf.lib",
"torch/lib/libprotobuf-lite.lib",
"torch/lib/libprotoc.lib",
"torch/lib/mimalloc-2.3/mimalloc.lib",
"torch/lib/cmake/**",
"torch/cmake/**",
"torch/lib/pkgconfig/**",
# File types that are unambiguously build inputs or dev artifacts; none
# of these appear in nightly wheels today.
"**/*.bzl",
"**/*.ipynb",
"**/*.png",
"**/*.sh",
"**/*.proto",
"**/*.pyi.in", # codegen templates -> .pyi at build time
"**/BUCK.oss", # Bazel build file
# Docs and editor / dev metadata that scikit-build-core's package walk
# picks up but legacy setup.py omitted.
"**/*.md",
"**/.gitignore",
"**/*.vim",
# Lint-tool input only (consumed by tools/linter/adapters/header_only_linter.py),
# not at runtime.
"torch/header_only_apis.txt",
# Example / benchmark sub-trees that look like Python sub-packages but
# which legacy setup.py shipped 0 files from. Keeping them in lockstep
# with the legacy wheel surface.
"torch/ao/pruning/_experimental/data_sparsifier/benchmarks/**",
"torch/ao/pruning/_experimental/data_sparsifier/lightning/tests/**",
"torch/ao/quantization/experimental/**",
"torch/distributed/benchmarks/**",
"torch/distributed/checkpoint/examples/**",
"torch/distributed/examples/**",
"torch/distributed/tensor/examples/**",
# Only the sparse/ sub-dir is leakage; legacy ships the rest of
# torch/utils/benchmark/examples/.
"torch/utils/benchmark/examples/sparse/**",
"torch/utils/_strobelight/examples/**",
# Stray license file under torch/fx/experimental/unification/ that
# legacy did not ship (the canonical vendored-code licenses we do ship
# live under torch/_vendor/).
"torch/fx/experimental/unification/LICENSE.txt",
# torchgen codegen-generator scripts (not consumed at runtime); legacy
# did not ship these either.
"torchgen/decompositions/gen_*.py",
"torchgen/fuse/gen_*.py",
"torchgen/shape_functions/gen_*.py",
# Thrift-generated C++ headers under torch/_export/serde/gen-cpp2/ and
# the ATen Declarations.yaml codegen artefact -- not in legacy wheels.
"torch/_export/serde/gen-cpp2/**",
"torch/share/ATen/Declarations.yaml",
# Convenience headers duplicated at the package root; the canonical
# copies live at torch/include/torch/*.h. legacy ships only the
# torch/include/... versions.
"torch/script.h",
"torch/library.h",
"torch/extension.h",
"torch/custom_class.h",
"torch/custom_class_detail.h",
# .py files placed under torch/include/fp16/ by the third_party/FP16
# source layout (legacy ships only the .h files from that directory);
# and protobuf .inc files legacy did not ship under torch/include/google/.
"torch/include/fp16/*.py",
"torch/include/google/protobuf/*.inc",
# Browser-side JS files loaded from a CDN URL (torch/cuda/_memory_viz.py
# references the jsdelivr URL directly) -- the local install copy is
# never consumed.
"torch/utils/viz/*.js",
"torch/distributed/tensor/debug/*.js",
]
[tool.scikit-build.editable]
# Editable installs use redirect mode: Python files come from the source tree,
# CMake-built artifacts from a persistent install tree, rebuild-dir, under
# build/. Installing straight into that tree keeps the artifacts out of the
# editable wheel, which otherwise had to be zipped and unpacked once per install
# (several GB and minutes on a debug build, #196619). The tree is keyed by wheel
# tag so editable installs for several interpreters can share one checkout.
# Auto-rebuild-on-import is left OFF: scikit-build-core's redirect finder
# otherwise re-runs cmake/ninja on every import (~7x, ~25s per `import torch`
# with no source change, plus build chatter on captured stderr). Rebuild
# explicitly instead; rebuild-on-import can be opted into per-install with
# SKBUILD_EDITABLE_REBUILD=true (or -C editable.rebuild=true), and
# `torch.__loader__.rebuild()` refreshes the tree on demand.
mode = "redirect"
rebuild = false
rebuild-dir = "build/install/{wheel_tag}"
[dependency-groups]
dev = [
# This list should be kept in sync with the requirements-build.txt
# in PyTorch root until the project fully migrates to pyproject.toml
# after which this can be removed as it is already specified in the
# [build-system] section
"scikit-build-core>=1.1.1",
"setuptools>=77.0.0,<82", # 77.0 is the first release with PEP 639 license-files support
"spin",
"cmake>=3.27",
"ninja",
"numpy",
"packaging>=24.2", # required by setuptools>=77 to validate PEP 639 license expressions
"pyyaml",
"requests",
"typing-extensions>=4.15.0",
"pip", # not technically needed, but this makes setup.py invocation work
# This list should be kept in sync with the requirements.txt in
# PyTorch root until the project fully migrates to pyproject.toml
"build[uv]", # for building sdist and wheel
"expecttest>=0.3.0",
"filelock",
"fsspec>=0.8.5",
"hypothesis",
"jinja2",
"lintrunner ; platform_machine != \"s390x\"",
"networkx>=2.5.1",
"optree>=0.13.0",
"psutil",
"spin",
"sympy>=1.13.3",
"wheel"
]
[project]
name = "torch"
description = "Tensors and Dynamic neural networks in Python with strong GPU acceleration"
readme = "README.md"
requires-python = ">=3.11"
# License info:
# - The main Pytorch project license is BSD-3-Clause.
# - Explicit license-files list; audit in test/test_license.py (issue #183434).
# - third_party/nccl/ is gitignored and populated only when USE_SYSTEM_NCCL=0;
# static-NCCL wheels therefore ship no NCCL license text.
license = "Apache-2.0 AND Apache-2.0 WITH LLVM-exception AND BSD-2-Clause AND BSD-3-Clause AND BSL-1.0 AND ISC AND MIT AND Zlib"
license-files = [
"LICENSE",
"third_party/FP16/LICENSE",
"third_party/FXdiv/LICENSE",
"third_party/NVTX/LICENSE.txt",
"third_party/VulkanMemoryAllocator/LICENSE.txt",
"third_party/XNNPACK/LICENSE",
"third_party/aiter/3rdparty/composable_kernel/LICENSE",
"third_party/aiter/LICENSE",
"third_party/composable_kernel/LICENSE",
"third_party/concurrentqueue/moodycamel/LICENSE.md",
"third_party/cpp-httplib/LICENSE",
"third_party/cpuinfo/LICENSE",
"third_party/cpuinfo/deps/clog/LICENSE",
"third_party/cudnn_frontend/LICENSE-MIT.txt",
"third_party/cudnn_frontend/LICENSE.txt",
"third_party/cudnn_frontend/python/cudnn/moe_ep/_megamoe_backend/cutedsl_src/LICENSE.Apache-2.0",
"third_party/cutlass/LICENSE.txt",
"third_party/dynolog_headers/LICENSE",
"third_party/fbgemm/LICENSE",
"third_party/fbgemm/external/asmjit/LICENSE.md",
"third_party/fbgemm/external/composable_kernel/LICENSE",
"third_party/fbgemm/external/cpuinfo/LICENSE",
"third_party/fbgemm/external/cpuinfo/deps/clog/LICENSE",
"third_party/fbgemm/external/cutlass/LICENSE.txt",
"third_party/flash-attention/LICENSE",
"third_party/flash-attention/csrc/composable_kernel/LICENSE",
"third_party/flash-attention/csrc/cutlass/LICENSE.txt",
"third_party/flash-attention/flash_attn/cute/LICENSE",
"third_party/flash-attention/third_party/aiter/3rdparty/composable_kernel/LICENSE",
"third_party/flash-attention/third_party/aiter/LICENSE",
"third_party/flatbuffers/LICENSE",
"third_party/fmt/LICENSE",
"third_party/gemmlowp/gemmlowp/LICENSE",
"third_party/gloo/LICENSE",
"third_party/gloo/gloo/transport/uv/LICENSE.uvw",
"third_party/ideep/LICENSE",
"third_party/ideep/mkl-dnn/LICENSE",
"third_party/ideep/mkl-dnn/third_party/ittnotify/LICENSE.BSD",
"third_party/ideep/mkl-dnn/third_party/opencl/LICENSE",
"third_party/llvm-openmp/LICENSE.txt",
"third_party/mimalloc/LICENSE",
"third_party/miniz-3.0.2/LICENSE",
"third_party/mslk/LICENSE",
"third_party/mslk/external/composable_kernel/LICENSE",
"third_party/mslk/external/cutlass/LICENSE.txt",
"third_party/mslk/mslk/attention/flash_attn/LICENSE",
"third_party/nccl_ep/LICENSE.txt",
"third_party/nccl_ep/ThirdPartyNotices.txt",
"third_party/nlohmann/LICENSE.MIT",
"third_party/onnx/LICENSE",
"third_party/perfetto/LICENSE",
"third_party/protobuf/LICENSE",
"third_party/psimd/LICENSE",
"third_party/pthreadpool/LICENSE",
"third_party/pybind11/LICENSE",
"third_party/pocketfft/LICENSE.md",
"third_party/sleef/LICENSE.txt",
"third_party/tensorpipe/LICENSE.txt",
"third_party/tensorpipe/third_party/libnop/LICENSE",
"third_party/tensorpipe/third_party/libuv/LICENSE",
"third_party/tensorpipe/third_party/libuv/LICENSE-extra",
"torch/csrc/profiler/kineto/LICENSE",
]
authors = [{ name = "PyTorch Team", email = "packages@pytorch.org" }]
keywords = ["pytorch", "machine learning"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
"Programming Language :: C++",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: 3.15",
]
dynamic = ["version", "dependencies"]
[project.scripts]
torchrun = "torch.distributed.run:main"
torchfrtrace = "torch.distributed.flight_recorder.fr_trace:main"
[project.entry-points."torchrun.logs_specs"]
default = "torch.distributed.elastic.multiprocessing:DefaultLogsSpecs"
[project.entry-points."torch.distributed.backends"]
mpi = "torch.distributed.distributed_c10d:_register_builtin_mpi_backend"
gloo = "torch.distributed.distributed_c10d:_register_builtin_gloo_backend"
nccl = "torch.distributed.distributed_c10d:_register_builtin_nccl_backend"
nccl2 = "torch.distributed.distributed_c10d:_register_builtin_nccl2_backend"
"nccl-lazy" = "torch.distributed.distributed_c10d:_register_builtin_nccl_lazy_backend"
ucc = "torch.distributed.distributed_c10d:_register_builtin_ucc_backend"
xccl = "torch.distributed.distributed_c10d:_register_builtin_xccl_backend"
nccl4py = "torch.distributed._nccl4py:_register_nccl4py_backend"
fake = "torch.distributed._backends.fake:_register_fake_backend"
[project.urls]
Homepage = "https://pytorch.org"
Repository = "https://github.com/pytorch/pytorch"
Documentation = "https://pytorch.org/docs"
"Issue Tracker" = "https://github.com/pytorch/pytorch/issues"
Forum = "https://discuss.pytorch.org"
[project.optional-dependencies]
optree = ["optree>=0.13.0"]
opt-einsum = ["opt-einsum>=3.3"]
pyyaml = ["pyyaml"]
# Linter tools #################################################################
[tool.isort]
src_paths = ["caffe2", "torch", "torchgen", "functorch", "test"]
extra_standard_library = ["typing_extensions"]
skip_gitignore = true
skip_glob = ["third_party/*"]
atomic = true
profile = "black"
indent = 4
line_length = 88
lines_after_imports = 2
multi_line_output = 3
include_trailing_comma = true
combine_as_imports = true
[tool.usort]
preserve_inline_comments = true
collapse_blank_lines_in_category = false
[tool.usort.known]
first_party = ["caffe2", "torch", "torchgen", "functorch", "test"]
standard_library = ["typing_extensions"]
[tool.ruff]
line-length = 88
src = ["caffe2", "torch", "torchgen", "functorch", "test"]
extend-exclude = ["third_party", "test/cpython"]
[tool.ruff.per-file-target-version]
"**/py312_intrinsics.py" = "py312"
[tool.ruff.format]
docstring-code-format = true
quote-style = "double"
[tool.ruff.lint]
# NOTE: Synchronize the ignores with .flake8
external = [
# lintrunner grep-linter codes (see .lintrunner.toml) suppressed via `# noqa:`.
"ISINSTANCE_FAKE_TENSOR",
"RVT001",
# Codes from flake8-only plugins that ruff doesn't implement.
"P201",
"P204",
"T484",
# Codes that are preview-only in ruff, so flake8 is still the enforcer.
# As ruff promotes these out of preview, move them to flake8's ignore list.
"B901",
"B909",
"E115",
"E201",
"E221",
"E225",
"E226",
"E227",
"E231",
"E241",
"E261",
"E262",
"E265",
"E266",
"E272",
"E306",
]
ignore = [
# these ignores are from flake8-bugbear; please fix!
"B007", "B008", "B017",
"B018", # Useless expression
"B023",
"B028", # No explicit `stacklevel` keyword argument found
"E402",
"C408", # C408 ignored because we like the dict keyword argument syntax
"E501", # E501 is not flexible enough, we're using B950 instead
"E741",
"EXE001",
"F405",
# these ignores are from ruff NPY; please fix!
"NPY002",
# these ignores are from ruff PERF; please fix!
"PERF203",
"PERF401",
# these ignores are from PYI; please fix!
"PYI024",
"PYI036",
"PYI041",
"PYI056",
"SIM102", "SIM103", "SIM112", # flake8-simplify code styles
"SIM105", # these ignores are from flake8-simplify. please fix or ignore with commented reason
"SIM108", # SIM108 ignored because we prefer if-else-block instead of ternary expression
"SIM110", # Checks for for loops that can be replaced with a builtin function, like any or all.
"SIM114", # Combine `if` branches using logical `or` operator
"SIM116", # Disable Use a dictionary instead of consecutive `if` statements
"SIM117",
"SIM300", # Yoda condition detected
"TC006",
# TODO: Remove Python-3.10 specific suppressions
"B905",
]
select = [
"B",
"B904", # Re-raised error without specifying the cause via the from keyword
"C4",
"G",
"E",
"EXE",
"F",
"SIM",
"W",
# Not included in flake8
"FURB",
"LOG",
"NPY",
"PERF",
"PGH004",
"PIE",
"PLC0131", # type bivariance
"PLC0132", # type param mismatch
"PLC1802", # len({expression}) used as condition without comparison
"PLC0205", # string as __slots__
"PLC3002", # unnecessary-direct-lambda-call
"PLC0414", # Import alias does not rename original package
"PLE",
"PLR0133", # constant comparison
"PLR0206", # property with params
"PLR1722", # use sys exit
"PLR1736", # unnecessary list index
"PLW0127", # Self-assignment of variable
"PLW0129", # assert on string literal
"PLW0131", # named expr without context
"PLW0133", # useless exception statement
"PLW0245", # super without brackets
"PLW0406", # import self
"PLW0711", # binary op exception
"PLW1501", # bad open mode
"PLW1507", # shallow copy os.environ
"PLW1509", # preexec_fn not safe with threads
"PLW2101", # useless lock statement
"PLW3301", # nested min max
"PT006", # TODO: enable more PT rules
"PT014", # duplicate parameterize case
"PT022",
"PT023",
"PT024",
"PT025",
"PT026",
"PYI",
"Q003", # avoidable escaped quote
"Q004", # unnecessary escaped quote
"RSE",
"RUF007", # pairwise over zip
"RUF008", # mutable dataclass default
"RUF013", # ban implicit optional
"RUF015", # access first ele in constant time
"RUF016", # type error non-integer index
"RUF017",
"RUF018", # no assignment in assert
"RUF019", # unnecessary-key-check
"RUF020", # never union
"RUF024", # from keys mutable
"RUF026", # default factory kwarg
"RUF030", # No print statement in assert
"RUF033", # default values __post_init__ dataclass
"RUF041", # simplify nested Literal
"RUF048", # properly parse `__version__`
"RUF100", # unused noqa
"RUF200", # validate pyproject.toml
"S324", # for hashlib FIPS compliance
"SLOT",
"TC",
"TRY002", # ban vanilla raise (todo fix NOQAs)
"TRY203",
"TRY401", # verbose-log-message
"UP",
"YTT",
"S101",
]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = [
"F401",
]
"*.pyi" = [
"PYI011", # typed-argument-default-in-stub
"PYI021", # docstring-in-stub
"PYI053", # string-or-bytes-too-long
]
"functorch/docs/source/tutorials/**" = [
"F401",
]
"test/export/**" = [
"PGH004",
]
"test/typing/**" = [
"PGH004"
]
"test/typing/reveal/**" = [
"F821",
]
"test/torch_np/numpy_tests/**" = [
"F821",
"NPY201",
]
"test/dynamo/test_bytecode_utils.py" = [
"F821",
]
"test/dynamo/test_debug_utils.py" = [
"UP037",
]
"test/dynamo/test_misc.py" = [
"PGH004",
]
"test/jit/**" = [
"PLR0133", # tests require this for JIT
"PYI",
"RUF015",
"UP", # We don't want to modify the jit test as they test specify syntax
]
"test/test_jit.py" = [
"PLR0133", # tests require this for JIT
"PYI",
"RUF015",
"UP", # We don't want to modify the jit test as they test specify syntax
]
"test/inductor/s429861_repro.py" = [
"PGH004",
]
"test/inductor/test_torchinductor.py" = [
"UP037",
]
# autogenerated #TODO figure out why file level noqa is ignored
"torch/_appdirs.py" = ["PGH004"]
"torch/jit/_shape_functions.py" = ["PGH004"]
"torch/_inductor/fx_passes/serialized_patterns/**" = ["F401", "F501"]
"torch/_inductor/autoheuristic/artifacts/**" = ["F401", "F501"]
"torch/_inductor/codegen/**" = [
"PGH004"
]
"torchgen/api/types/__init__.py" = [
"F401",
"F403",
]
"torch/utils/collect_env.py" = [
"UP", # collect_env.py needs to work with older versions of Python
]
"torch/_vendor/**" = [
"UP", # No need to mess with _vendor
]
"tools/linter/**" = [
"LOG015" # please fix
]
[tool.codespell]
ignore-words = "tools/linter/dictionary.txt"
[tool.spin]
package = 'torch'
[tool.spin.commands]
"Build" = [
".spin/cmds.py:develop",
".spin/cmds.py:editable",
".spin/cmds.py:install",
".spin/cmds.py:clean",
".spin/cmds.py:lint",
".spin/cmds.py:fixlint",
".spin/cmds.py:quicklint",
".spin/cmds.py:quickfix",
]
"Regenerate" = [
".spin/cmds.py:regenerate_version",
".spin/cmds.py:regenerate_type_stubs",
".spin/cmds.py:regenerate_clangtidy_files",
".spin/cmds.py:regenerate_github_workflows",
]
"Documentation" = [
".spin/cmds.py:docs",
]
"Test" = [
".spin/cmds.py:test",
]
"Type" = [
".spin/cmds.py:pyrefly",
]
[project.entry-points."torch.distributed.transports"]
nixl = "torch.distributed._transport.nixl:NIXLTransport"
mooncake = "torch.distributed._transport.mooncake:MooncakeTransport"