Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/180248
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ You can merge normally! (4 Unrelated Failures), 1 Unclassified FailureAs of commit 0ff9f4d with merge base bfe58eb ( UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Ping @henryiii |
Remove the legacy setup.py and related setuptools helpers now that the build is fully driven by scikit-build-core. Retain a minimal build_libtorch.py that invokes cmake directly. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: 60bef8d Pull-Request: pytorch#180248
Remove the legacy setup.py and related setuptools helpers now that the build is fully driven by scikit-build-core. Retain a minimal build_libtorch.py that invokes cmake directly. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: 60bef8d Pull-Request: pytorch#180248
Remove the legacy setup.py and related setuptools helpers now that the build is fully driven by scikit-build-core. Retain a minimal build_libtorch.py that invokes cmake directly. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: 60bef8d Pull-Request: pytorch#180248
albanD
left a comment
There was a problem hiding this comment.
nit on the shim. But sounds great to me!
Thanks for taking the time to clean this up!
|
@pytorchmergebot merge -f "all looks good" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
scikit-build-core collects sdist contents by walking the tree with gitignore semantics rather than from git tracking. Several vendored trees commit files that their own .gitignore matches (XNNPACK's generated microkernels under gen/, all oneDNN C++ sources via ideep's "*.cpp" pattern, protobuf's checked-in *.pb.cc, clog under qnnpack's deps/), and PyTorch's top-level .gitignore patterns (bare "gen", "*.pb.h") also match tracked third-party files. The walk therefore silently dropped ~11,500 tracked files, leaving an sdist that cannot build: XNNPACK, oneDNN, cpuinfo, and NNPACK codegen all lack sources. The legacy setup.py sdist never hit this because MANIFEST.in grafts copy from disk regardless of gitignore. Fix: re-include the affected roots via [tool.scikit-build.sdist]. In scikit-build-core's collector, include matches take precedence over every exclude source (user excludes, built-ins, gitignore), so a separate sdist.exclude list cannot trim a blanket include; entries that must not ship despite the blanket include are negated inside the include list and then caught by an exclude source (see the comment in pyproject.toml for the exact mechanics). The natural alternative -- collecting the file list from git tracking -- does not exist in scikit-build-core today; worth proposing upstream, at which point this block can go away. Deliberately excluded (1323 tracked files, matching the legacy MANIFEST.in's intent): repo/CI plumbing (.github, .ci, .claude, .spin, vendored .github dirs) and unneeded vendored language bindings (flatbuffers java/kotlin, ittapi rust). The latter were pruned by MANIFEST.in (#157814) to work around invalid symlinks in those trees; under scikit-build-core the default sdist.resolve-symlinks="all" would instead silently duplicate the link targets into the sdist. With these prunes the sdist contains no symlink members at all; the handful of remaining tracked symlinks (AGENTS.md, docs/requirements.txt, ...) dereference to a few KB of duplicated content. MANIFEST.in itself is removed: scikit-build-core's native backend never reads it, so it has been inert since the backend switch and its sdist role is fully replaced by the configuration added here. ## Test plan - [x] sdist file list matches `git ls-files --recurse-submodules` exactly, up to (a) the 1323 deliberately excluded files above and (b) 4 unicode-quoting artifacts of the listing comparison itself, with zero .git pointers, bytecode, third_party/nccl content, or symlink members: ``` uv build --sdist --out-dir dist git ls-files --recurse-submodules | sort > /tmp/git-files.txt tar tzf dist/torch-*.tar.gz | sed 's|^[^/]*/||' | grep -v '/$' | sort > /tmp/sdist-files.txt comm -23 /tmp/git-files.txt /tmp/sdist-files.txt grep -cE '\.git$|\.pyc$|__pycache__|^third_party/nccl/|(^|/)\.github/|^\.ci/|^\.claude/|^\.spin/' /tmp/sdist-files.txt tar tvzf dist/torch-*.tar.gz | grep -c '^l' ``` - [x] From-sdist build works end to end (CPU-only, linux-x86_64): ``` pip wheel dist/torch-*.tar.gz --no-deps -w /tmp/wheels python -m venv /tmp/venv && /tmp/venv/bin/pip install /tmp/wheels/torch-*.whl numpy /tmp/venv/bin/python -c "import torch; a=torch.randn(64,64); print(([email protected]).shape); print(torch.compile(lambda x: x.sin()+1)(torch.randn(8)).shape)" ``` - [x] Superset of the setuptools sdist's tracked content: compared against a `python setup.py sdist` tarball built from main (7de45b6), zero tracked files are present there but missing here; the ~480 tracked files only present here are ones MANIFEST.in dropped as collateral (submodule .gitignore/.gitmodules via `global-exclude .git*`, flatbuffers test data lost to a setuptools symlink-walk quirk). - [x] include/exclude interaction verified against scikit-build-core 1.0.3's collector with a synthetic tree, including the counterfactual configs (negation-only and exclude-only both leak files; the pairing is required). - [x] No remaining consumers of MANIFEST.in: ``` grep -rln "MANIFEST.in" --exclude-dir=third_party --exclude-dir=.git . ``` Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: #190192 Approved by: https://github.com/albanD, https://github.com/atalman ghstack dependencies: #180248
scikit-build-core collects sdist contents by walking the tree with gitignore semantics rather than from git tracking. Several vendored trees commit files that their own .gitignore matches (XNNPACK's generated microkernels under gen/, all oneDNN C++ sources via ideep's "*.cpp" pattern, protobuf's checked-in *.pb.cc, clog under qnnpack's deps/), and PyTorch's top-level .gitignore patterns (bare "gen", "*.pb.h") also match tracked third-party files. The walk therefore silently dropped ~11,500 tracked files, leaving an sdist that cannot build: XNNPACK, oneDNN, cpuinfo, and NNPACK codegen all lack sources. The legacy setup.py sdist never hit this because MANIFEST.in grafts copy from disk regardless of gitignore. Fix: re-include the affected roots via [tool.scikit-build.sdist]. In scikit-build-core's collector, include matches take precedence over every exclude source (user excludes, built-ins, gitignore), so a separate sdist.exclude list cannot trim a blanket include; entries that must not ship despite the blanket include are negated inside the include list and then caught by an exclude source (see the comment in pyproject.toml for the exact mechanics). The natural alternative -- collecting the file list from git tracking -- does not exist in scikit-build-core today; worth proposing upstream, at which point this block can go away. Deliberately excluded (1323 tracked files, matching the legacy MANIFEST.in's intent): repo/CI plumbing (.github, .ci, .claude, .spin, vendored .github dirs) and unneeded vendored language bindings (flatbuffers java/kotlin, ittapi rust). The latter were pruned by MANIFEST.in (#157814) to work around invalid symlinks in those trees; under scikit-build-core the default sdist.resolve-symlinks="all" would instead silently duplicate the link targets into the sdist. With these prunes the sdist contains no symlink members at all; the handful of remaining tracked symlinks (AGENTS.md, docs/requirements.txt, ...) dereference to a few KB of duplicated content. MANIFEST.in itself is removed: scikit-build-core's native backend never reads it, so it has been inert since the backend switch and its sdist role is fully replaced by the configuration added here. ## Test plan - [x] sdist file list matches `git ls-files --recurse-submodules` exactly, up to (a) the 1323 deliberately excluded files above and (b) 4 unicode-quoting artifacts of the listing comparison itself, with zero .git pointers, bytecode, third_party/nccl content, or symlink members: ``` uv build --sdist --out-dir dist git ls-files --recurse-submodules | sort > /tmp/git-files.txt tar tzf dist/torch-*.tar.gz | sed 's|^[^/]*/||' | grep -v '/$' | sort > /tmp/sdist-files.txt comm -23 /tmp/git-files.txt /tmp/sdist-files.txt grep -cE '\.git$|\.pyc$|__pycache__|^third_party/nccl/|(^|/)\.github/|^\.ci/|^\.claude/|^\.spin/' /tmp/sdist-files.txt tar tvzf dist/torch-*.tar.gz | grep -c '^l' ``` - [x] From-sdist build works end to end (CPU-only, linux-x86_64): ``` pip wheel dist/torch-*.tar.gz --no-deps -w /tmp/wheels python -m venv /tmp/venv && /tmp/venv/bin/pip install /tmp/wheels/torch-*.whl numpy /tmp/venv/bin/python -c "import torch; a=torch.randn(64,64); print(([email protected]).shape); print(torch.compile(lambda x: x.sin()+1)(torch.randn(8)).shape)" ``` - [x] Superset of the setuptools sdist's tracked content: compared against a `python setup.py sdist` tarball built from main (7de45b6), zero tracked files are present there but missing here; the ~480 tracked files only present here are ones MANIFEST.in dropped as collateral (submodule .gitignore/.gitmodules via `global-exclude .git*`, flatbuffers test data lost to a setuptools symlink-walk quirk). - [x] include/exclude interaction verified against scikit-build-core 1.0.3's collector with a synthetic tree, including the counterfactual configs (negation-only and exclude-only both leak files; the pairing is required). - [x] No remaining consumers of MANIFEST.in: ``` grep -rln "MANIFEST.in" --exclude-dir=third_party --exclude-dir=.git . ``` Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: #190192 Approved by: https://github.com/albanD, https://github.com/atalman ghstack dependencies: #180248
scikit-build-core collects sdist contents by walking the tree with gitignore semantics rather than from git tracking. Several vendored trees commit files that their own .gitignore matches (XNNPACK's generated microkernels under gen/, all oneDNN C++ sources via ideep's "*.cpp" pattern, protobuf's checked-in *.pb.cc, clog under qnnpack's deps/), and PyTorch's top-level .gitignore patterns (bare "gen", "*.pb.h") also match tracked third-party files. The walk therefore silently dropped ~11,500 tracked files, leaving an sdist that cannot build: XNNPACK, oneDNN, cpuinfo, and NNPACK codegen all lack sources. The legacy setup.py sdist never hit this because MANIFEST.in grafts copy from disk regardless of gitignore. Fix: re-include the affected roots via [tool.scikit-build.sdist]. In scikit-build-core's collector, include matches take precedence over every exclude source (user excludes, built-ins, gitignore), so a separate sdist.exclude list cannot trim a blanket include; entries that must not ship despite the blanket include are negated inside the include list and then caught by an exclude source (see the comment in pyproject.toml for the exact mechanics). The natural alternative -- collecting the file list from git tracking -- does not exist in scikit-build-core today; worth proposing upstream, at which point this block can go away. Deliberately excluded (1323 tracked files, matching the legacy MANIFEST.in's intent): repo/CI plumbing (.github, .ci, .claude, .spin, vendored .github dirs) and unneeded vendored language bindings (flatbuffers java/kotlin, ittapi rust). The latter were pruned by MANIFEST.in (pytorch#157814) to work around invalid symlinks in those trees; under scikit-build-core the default sdist.resolve-symlinks="all" would instead silently duplicate the link targets into the sdist. With these prunes the sdist contains no symlink members at all; the handful of remaining tracked symlinks (AGENTS.md, docs/requirements.txt, ...) dereference to a few KB of duplicated content. MANIFEST.in itself is removed: scikit-build-core's native backend never reads it, so it has been inert since the backend switch and its sdist role is fully replaced by the configuration added here. ## Test plan - [x] sdist file list matches `git ls-files --recurse-submodules` exactly, up to (a) the 1323 deliberately excluded files above and (b) 4 unicode-quoting artifacts of the listing comparison itself, with zero .git pointers, bytecode, third_party/nccl content, or symlink members: ``` uv build --sdist --out-dir dist git ls-files --recurse-submodules | sort > /tmp/git-files.txt tar tzf dist/torch-*.tar.gz | sed 's|^[^/]*/||' | grep -v '/$' | sort > /tmp/sdist-files.txt comm -23 /tmp/git-files.txt /tmp/sdist-files.txt grep -cE '\.git$|\.pyc$|__pycache__|^third_party/nccl/|(^|/)\.github/|^\.ci/|^\.claude/|^\.spin/' /tmp/sdist-files.txt tar tvzf dist/torch-*.tar.gz | grep -c '^l' ``` - [x] From-sdist build works end to end (CPU-only, linux-x86_64): ``` pip wheel dist/torch-*.tar.gz --no-deps -w /tmp/wheels python -m venv /tmp/venv && /tmp/venv/bin/pip install /tmp/wheels/torch-*.whl numpy /tmp/venv/bin/python -c "import torch; a=torch.randn(64,64); print(([email protected]).shape); print(torch.compile(lambda x: x.sin()+1)(torch.randn(8)).shape)" ``` - [x] Superset of the setuptools sdist's tracked content: compared against a `python setup.py sdist` tarball built from main (7de45b6), zero tracked files are present there but missing here; the ~480 tracked files only present here are ones MANIFEST.in dropped as collateral (submodule .gitignore/.gitmodules via `global-exclude .git*`, flatbuffers test data lost to a setuptools symlink-walk quirk). - [x] include/exclude interaction verified against scikit-build-core 1.0.3's collector with a synthetic tree, including the counterfactual configs (negation-only and exclude-only both leak files; the pairing is required). - [x] No remaining consumers of MANIFEST.in: ``` grep -rln "MANIFEST.in" --exclude-dir=third_party --exclude-dir=.git . ``` Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#190192 Approved by: https://github.com/albanD, https://github.com/atalman ghstack dependencies: pytorch#180248
…0247) Switch pyproject.toml's build backend from setuptools to scikit-build-core (>= 1.0), which invokes CMake directly instead of having setup.py orchestrate it. This PR makes the backend swap plus the 1.0-native configuration it enables; the now-unused setuptools code is removed separately in pytorch#180248, so this diff stays focused and is revertible on its own. Where to look, in order of importance: - pyproject.toml: the new [build-system], the scikit-build-core config (the [tool.scikit-build.env] table, cmake defines, wheel layout, editable mode), and the dynamic-metadata hooks. This is the heart of the change. - tools/metadata/{version,dependencies}.py: the providers backing those hooks -- wheel version (from generate_torch_version) and dependencies (base + CUDA/ROCm extras). - CMakeLists.txt: project name/version now come from SKBUILD_* with fallbacks so a standalone `cmake` invocation still works. - torch/__init__.py, torch/_utils_internal.py: import-time shims that keep editable installs working under the new backend. scikit-build-core's redirect finder resolves the extension module itself (`import torch._C`); the shims only cover the places PyTorch locates native artifacts by hand, off `__file__`, which the import system never sees: the `ctypes.CDLL` preload of libtorch_global_deps, the Windows `os.add_dll_directory` for `_C`'s dependent DLLs, and the `bin/` data-file path. Redirect mode is the first layout to split the Python sources (checkout) from the compiled artifacts (install tree); in wheel and `setup.py develop` installs they sat together, so those `dirname(__file__)` lookups happened to be right. - CONTRIBUTING.md: documents the editable-install flow, including scikit-build-core's optional rebuild-on-import (SKBUILD_EDITABLE_REBUILD), which stays off by default. - tools/linter/adapters/codespell_linter.py: works around a codespell bug (it crashes reading a pyproject.toml with an array-of-tables under [tool], which our new [[tool.dynamic-metadata]] introduces) by pointing codespell at the dictionary directly instead of `--toml pyproject.toml`. Reported upstream as codespell-project/codespell#3969. The remainder is mechanical: CI scripts swap `python setup.py clean` for `python -m spin clean` and probe for pyproject.toml instead of setup.py, and the build-requirement files gain scikit-build-core. The configuration uses the scikit-build-core 1.0 feature set, which keeps several PyTorch-specific workarounds out of the tree: - MAX_JOBS -> CMAKE_BUILD_PARALLEL_LEVEL is aliased in the [tool.scikit-build.env] table (added upstream in scikit-build-core#1377 for exactly this), so no custom PEP 517 wrapper backend is needed -- the backend is plain scikit_build_core.build. - Dynamic version/dependencies use the stable [[tool.dynamic-metadata]] table (no experimental flag); the dependencies provider marks deps Dynamic in the sdist via a dynamic_wheel hook. - Build type comes from the environment: 1.0 honors CMAKE_BUILD_TYPE natively, so only the DEBUG / REL_WITH_DEB_INFO env-var overrides remain. - Per-image Linux compiler handling is CC/CXX = { env = ... } in the env table, which opts out of scikit-build-core's sysconfig-compiler injection (documented behavior since pytorch#1377) and lets CMake detect the compiler from PATH -- what green setup.py builds always did -- replacing two per-image cmake.define overrides. - The Windows Ninja generator is cmake.define.CMAKE_GENERATOR in a win32 override (1.0's generator-resolution chain honors it), so pyproject is the single source of truth and a plain editable Windows build gets Ninja too; the CI scripts no longer export CMAKE_GENERATOR. The build-system floor and requirements-build.txt are scikit-build-core >= 1.0; minimum-version pins the schema to that floor; and the CI pin (.ci/docker/requirements-ci.txt) plus the Windows build-dep installers are == 1.0.0. scikit-build-core 1.0.0 released 2026-07-06. ## Test plan Wheel content-equivalent to the setuptools build (pytorch#180243), fresh cp312 CPU artifacts: - [x] **Wheel size**: 193,274,760 B vs pytorch#180243 193,263,155 B (+0.006 %). - [x] **Manifest diff**: adds only 6 license files and removes the setuptools-specific `top_level.txt`; no layout spillage. ``` diff <(unzip -Z1 243.whl | sort) <(unzip -Z1 247.whl | sort) ``` - [x] **METADATA / version.py** identical bar `git_version` and the extra License-File entries; exactly one `_C.cpython-312.so`; aotriton payload intact (10,612 `aotriton.images/` kernels across 6 arches). - [x] **Build time**: no regression; manywheel builds faster (the gain is packaging, not compilation). Clean-build + editable import against the released scikit-build-core 1.0.0: - [x] Linux (qgpu3, CUDA op), macOS (qmac, MPS), Windows (win11 VM): fresh `pip install -e . --no-build-isolation` builds and `import torch` resolves the CMake-built native artifacts from the install location. The Windows run also confirmed the Ninja generator comes purely from pyproject (no CMAKE_GENERATOR env var; build.ninja present, no .sln). - [x] lintrunner -a clean (two pre-existing torch.bcomplex32 PYREFLY errors in torch/storage.py + torch/testing/_creation.py are on trunk, untouched). Re-validated on this PR's CI (carries ciflow/trunk): the dropped per-image Linux compiler overrides, exercised by the anaconda (conda-gcc11, compiler_compat) and aarch64 image builds -- the two cases those overrides originally fixed. Based on a patch by Henry Schreiner (scikit-build-core maintainer); the env table (scikit-build-core#1377) was added upstream specifically to let PyTorch delete its wrapper backend. Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#180247 Approved by: https://github.com/atalman, https://github.com/albanD
…ytorch#180248) With the build fully driven by scikit-build-core (pytorch#180247), the setuptools path is dead code. Remove the setuptools build helpers (build_pytorch_libs, setup_helpers.{cmake,cmake_utils,env}, test_cmake) and replace setup.py with a small shim that forwards `install` and `develop` to pip and fails with instructions for everything else. Retain a minimal build_libtorch.py -- it calls cmake directly and is still used by the libtorch build path. ## Why a phased sunset instead of outright removal? pip and `python -m build` never execute setup.py; the only way it still runs is a direct `python setup.py <cmd>` invocation. For `install` and `develop` we have redirected to pip since pytorch#152276; the shim keeps that contract intact for two more releases so existing scripts keep working while they migrate. Every other command (`build`, `bdist_wheel`, `clean`, `sdist`, ...) used to fall through into the setuptools machinery this PR deletes; emulating that interface is not worth it (setuptools itself deprecated it in 2021), so those commands now fail immediately, printing the replacement commands and the sunset schedule -- a more helpful failure mode than `can't open file 'setup.py'` while still surfacing not-yet-migrated callers. The schedule is stated in the shim header and printed on every invocation: - PyTorch 2.14-2.15: `install`/`develop` forward to pip; all other commands fail with instructions - PyTorch 2.16-2.17: all commands fail with instructions - PyTorch 2.18: setup.py is removed ## Test plan - [x] **Wheel byte-identical to parent pytorch#180247**: empty manifest diff, +10 B zip-timestamp noise. Removing the dead setuptools machinery does not change wheel content (it is never shipped, and scikit-build-core does not use it). The shim cannot change this: nothing installs the root setup.py into the wheel. ``` diff <(unzip -Z1 247.whl | sort) <(unzip -Z1 248.whl | sort) # empty ``` - [x] **Shim forwarding**: `install`/`develop` forward to pip with the exact pytorch#152276 command line, extra arguments are dropped with a warning, and pip's exit code is propagated (verified with a stub pip that prints its argv and exits 3): ``` python setup.py develop --user # pip install -v --no-build-isolation -e ., warns about dropped --user python setup.py install # pip install -v --no-build-isolation . ``` - [x] **Shim guard**: every other command fails with exit code 1, printing the replacement commands and the sunset schedule: ``` python setup.py bdist_wheel ``` - [x] **No dangling references** to the removed modules (`build_pytorch_libs`, `setup_helpers.{cmake,cmake_utils,env}`, `test_cmake`); the remaining `tools/setup_helpers` references point to surviving files (`generate_code.py`, `gen_version_header.py`, `generate_linker_script.py`). ``` grep -rE 'build_pytorch_libs|setup_helpers\.(cmake|env)' --include='*.py' . ``` - [x] **0 build failures** across the matrix -- the removed path was genuinely dead. Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#180248 Approved by: https://github.com/albanD, https://github.com/atalman
…0247) Switch pyproject.toml's build backend from setuptools to scikit-build-core (>= 1.0), which invokes CMake directly instead of having setup.py orchestrate it. This PR makes the backend swap plus the 1.0-native configuration it enables; the now-unused setuptools code is removed separately in pytorch#180248, so this diff stays focused and is revertible on its own. Where to look, in order of importance: - pyproject.toml: the new [build-system], the scikit-build-core config (the [tool.scikit-build.env] table, cmake defines, wheel layout, editable mode), and the dynamic-metadata hooks. This is the heart of the change. - tools/metadata/{version,dependencies}.py: the providers backing those hooks -- wheel version (from generate_torch_version) and dependencies (base + CUDA/ROCm extras). - CMakeLists.txt: project name/version now come from SKBUILD_* with fallbacks so a standalone `cmake` invocation still works. - torch/__init__.py, torch/_utils_internal.py: import-time shims that keep editable installs working under the new backend. scikit-build-core's redirect finder resolves the extension module itself (`import torch._C`); the shims only cover the places PyTorch locates native artifacts by hand, off `__file__`, which the import system never sees: the `ctypes.CDLL` preload of libtorch_global_deps, the Windows `os.add_dll_directory` for `_C`'s dependent DLLs, and the `bin/` data-file path. Redirect mode is the first layout to split the Python sources (checkout) from the compiled artifacts (install tree); in wheel and `setup.py develop` installs they sat together, so those `dirname(__file__)` lookups happened to be right. - CONTRIBUTING.md: documents the editable-install flow, including scikit-build-core's optional rebuild-on-import (SKBUILD_EDITABLE_REBUILD), which stays off by default. - tools/linter/adapters/codespell_linter.py: works around a codespell bug (it crashes reading a pyproject.toml with an array-of-tables under [tool], which our new [[tool.dynamic-metadata]] introduces) by pointing codespell at the dictionary directly instead of `--toml pyproject.toml`. Reported upstream as codespell-project/codespell#3969. The remainder is mechanical: CI scripts swap `python setup.py clean` for `python -m spin clean` and probe for pyproject.toml instead of setup.py, and the build-requirement files gain scikit-build-core. The configuration uses the scikit-build-core 1.0 feature set, which keeps several PyTorch-specific workarounds out of the tree: - MAX_JOBS -> CMAKE_BUILD_PARALLEL_LEVEL is aliased in the [tool.scikit-build.env] table (added upstream in scikit-build-core#1377 for exactly this), so no custom PEP 517 wrapper backend is needed -- the backend is plain scikit_build_core.build. - Dynamic version/dependencies use the stable [[tool.dynamic-metadata]] table (no experimental flag); the dependencies provider marks deps Dynamic in the sdist via a dynamic_wheel hook. - Build type comes from the environment: 1.0 honors CMAKE_BUILD_TYPE natively, so only the DEBUG / REL_WITH_DEB_INFO env-var overrides remain. - Per-image Linux compiler handling is CC/CXX = { env = ... } in the env table, which opts out of scikit-build-core's sysconfig-compiler injection (documented behavior since pytorch#1377) and lets CMake detect the compiler from PATH -- what green setup.py builds always did -- replacing two per-image cmake.define overrides. - The Windows Ninja generator is cmake.define.CMAKE_GENERATOR in a win32 override (1.0's generator-resolution chain honors it), so pyproject is the single source of truth and a plain editable Windows build gets Ninja too; the CI scripts no longer export CMAKE_GENERATOR. The build-system floor and requirements-build.txt are scikit-build-core >= 1.0; minimum-version pins the schema to that floor; and the CI pin (.ci/docker/requirements-ci.txt) plus the Windows build-dep installers are == 1.0.0. scikit-build-core 1.0.0 released 2026-07-06. ## Test plan Wheel content-equivalent to the setuptools build (pytorch#180243), fresh cp312 CPU artifacts: - [x] **Wheel size**: 193,274,760 B vs pytorch#180243 193,263,155 B (+0.006 %). - [x] **Manifest diff**: adds only 6 license files and removes the setuptools-specific `top_level.txt`; no layout spillage. ``` diff <(unzip -Z1 243.whl | sort) <(unzip -Z1 247.whl | sort) ``` - [x] **METADATA / version.py** identical bar `git_version` and the extra License-File entries; exactly one `_C.cpython-312.so`; aotriton payload intact (10,612 `aotriton.images/` kernels across 6 arches). - [x] **Build time**: no regression; manywheel builds faster (the gain is packaging, not compilation). Clean-build + editable import against the released scikit-build-core 1.0.0: - [x] Linux (qgpu3, CUDA op), macOS (qmac, MPS), Windows (win11 VM): fresh `pip install -e . --no-build-isolation` builds and `import torch` resolves the CMake-built native artifacts from the install location. The Windows run also confirmed the Ninja generator comes purely from pyproject (no CMAKE_GENERATOR env var; build.ninja present, no .sln). - [x] lintrunner -a clean (two pre-existing torch.bcomplex32 PYREFLY errors in torch/storage.py + torch/testing/_creation.py are on trunk, untouched). Re-validated on this PR's CI (carries ciflow/trunk): the dropped per-image Linux compiler overrides, exercised by the anaconda (conda-gcc11, compiler_compat) and aarch64 image builds -- the two cases those overrides originally fixed. Based on a patch by Henry Schreiner (scikit-build-core maintainer); the env table (scikit-build-core#1377) was added upstream specifically to let PyTorch delete its wrapper backend. Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#180247 Approved by: https://github.com/atalman, https://github.com/albanD
…ytorch#180248) With the build fully driven by scikit-build-core (pytorch#180247), the setuptools path is dead code. Remove the setuptools build helpers (build_pytorch_libs, setup_helpers.{cmake,cmake_utils,env}, test_cmake) and replace setup.py with a small shim that forwards `install` and `develop` to pip and fails with instructions for everything else. Retain a minimal build_libtorch.py -- it calls cmake directly and is still used by the libtorch build path. ## Why a phased sunset instead of outright removal? pip and `python -m build` never execute setup.py; the only way it still runs is a direct `python setup.py <cmd>` invocation. For `install` and `develop` we have redirected to pip since pytorch#152276; the shim keeps that contract intact for two more releases so existing scripts keep working while they migrate. Every other command (`build`, `bdist_wheel`, `clean`, `sdist`, ...) used to fall through into the setuptools machinery this PR deletes; emulating that interface is not worth it (setuptools itself deprecated it in 2021), so those commands now fail immediately, printing the replacement commands and the sunset schedule -- a more helpful failure mode than `can't open file 'setup.py'` while still surfacing not-yet-migrated callers. The schedule is stated in the shim header and printed on every invocation: - PyTorch 2.14-2.15: `install`/`develop` forward to pip; all other commands fail with instructions - PyTorch 2.16-2.17: all commands fail with instructions - PyTorch 2.18: setup.py is removed ## Test plan - [x] **Wheel byte-identical to parent pytorch#180247**: empty manifest diff, +10 B zip-timestamp noise. Removing the dead setuptools machinery does not change wheel content (it is never shipped, and scikit-build-core does not use it). The shim cannot change this: nothing installs the root setup.py into the wheel. ``` diff <(unzip -Z1 247.whl | sort) <(unzip -Z1 248.whl | sort) # empty ``` - [x] **Shim forwarding**: `install`/`develop` forward to pip with the exact pytorch#152276 command line, extra arguments are dropped with a warning, and pip's exit code is propagated (verified with a stub pip that prints its argv and exits 3): ``` python setup.py develop --user # pip install -v --no-build-isolation -e ., warns about dropped --user python setup.py install # pip install -v --no-build-isolation . ``` - [x] **Shim guard**: every other command fails with exit code 1, printing the replacement commands and the sunset schedule: ``` python setup.py bdist_wheel ``` - [x] **No dangling references** to the removed modules (`build_pytorch_libs`, `setup_helpers.{cmake,cmake_utils,env}`, `test_cmake`); the remaining `tools/setup_helpers` references point to surviving files (`generate_code.py`, `gen_version_header.py`, `generate_linker_script.py`). ``` grep -rE 'build_pytorch_libs|setup_helpers\.(cmake|env)' --include='*.py' . ``` - [x] **0 build failures** across the matrix -- the removed path was genuinely dead. Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#180248 Approved by: https://github.com/albanD, https://github.com/atalman
## Summary
Replace deprecated `distutils` usage in CI scripts and tooling, in preparation
for Python 3.12+ (where `distutils` is removed). Two patterns are handled:
- `distutils.sysconfig.get_python_lib()` → `sysconfig.get_path("purelib")` in
`.ci/pytorch/macos-test.sh`, `.ci/pytorch/test.sh`, and
`.ci/pytorch/smoke_test/check_binary_symbols.py`.
- `distutils.util.strtobool` → a small local replacement in
`tools/strtobool.py`, imported by `.github/scripts/generate_pytorch_version.py`,
`tools/generate_torch_version.py`, and `tools/alerts/create_alerts.py`.
## Suggested review order
1. `tools/strtobool.py` — the consolidated helper, semantically identical to
the removed `distutils.util.strtobool`.
2. The three Python call sites that import it. `.github/scripts/...` uses the
same `sys.path` shim already established in
`.github/scripts/close_nonexistent_disable_issues.py` for cross-importing
from `tools/`.
3. The `sysconfig` substitutions in the shell scripts and
`check_binary_symbols.py` — mechanical.
<details>
<summary>Out of scope (intentional)</summary>
- `tools/build_pytorch_libs.py` (`distutils._msvccompiler._get_vc_env`):
deferred to a follow-up — the API is private and the replacement is not a
one-liner.
- `tools/setup_helpers/cmake.py` (`from distutils.version import LooseVersion`)
and `setup.py` (`setuptools.distutils.log.warn`): both files are deleted
outright by the scikit-build-core migration (pytorch#180248); fixing them here
would just create merge conflicts.
- `test/run_test.py:135`'s `strtobool`: deliberately permissive
(`s.lower() not in {"", "0", "false", "off"}`) and never raises. Switching
to the strict distutils-style helper would change behavior for callers
passing non-canonical truthy values such as `TEST_SHOWLOCALS=yeah`.
- Other `str2bool` variants in `benchmarks/operator_benchmark/`,
`torch/utils/hipify/`, and `.ci/lumen_cli/` do not use `distutils` and are
not in this PR's scope.
</details>
Replaces pytorch#180241.
Authored with Claude.
Pull Request resolved: pytorch#182120
Approved by: https://github.com/atalman
…0247) Switch pyproject.toml's build backend from setuptools to scikit-build-core (>= 1.0), which invokes CMake directly instead of having setup.py orchestrate it. This PR makes the backend swap plus the 1.0-native configuration it enables; the now-unused setuptools code is removed separately in pytorch#180248, so this diff stays focused and is revertible on its own. Where to look, in order of importance: - pyproject.toml: the new [build-system], the scikit-build-core config (the [tool.scikit-build.env] table, cmake defines, wheel layout, editable mode), and the dynamic-metadata hooks. This is the heart of the change. - tools/metadata/{version,dependencies}.py: the providers backing those hooks -- wheel version (from generate_torch_version) and dependencies (base + CUDA/ROCm extras). - CMakeLists.txt: project name/version now come from SKBUILD_* with fallbacks so a standalone `cmake` invocation still works. - torch/__init__.py, torch/_utils_internal.py: import-time shims that keep editable installs working under the new backend. scikit-build-core's redirect finder resolves the extension module itself (`import torch._C`); the shims only cover the places PyTorch locates native artifacts by hand, off `__file__`, which the import system never sees: the `ctypes.CDLL` preload of libtorch_global_deps, the Windows `os.add_dll_directory` for `_C`'s dependent DLLs, and the `bin/` data-file path. Redirect mode is the first layout to split the Python sources (checkout) from the compiled artifacts (install tree); in wheel and `setup.py develop` installs they sat together, so those `dirname(__file__)` lookups happened to be right. - CONTRIBUTING.md: documents the editable-install flow, including scikit-build-core's optional rebuild-on-import (SKBUILD_EDITABLE_REBUILD), which stays off by default. - tools/linter/adapters/codespell_linter.py: works around a codespell bug (it crashes reading a pyproject.toml with an array-of-tables under [tool], which our new [[tool.dynamic-metadata]] introduces) by pointing codespell at the dictionary directly instead of `--toml pyproject.toml`. Reported upstream as codespell-project/codespell#3969. The remainder is mechanical: CI scripts swap `python setup.py clean` for `python -m spin clean` and probe for pyproject.toml instead of setup.py, and the build-requirement files gain scikit-build-core. The configuration uses the scikit-build-core 1.0 feature set, which keeps several PyTorch-specific workarounds out of the tree: - MAX_JOBS -> CMAKE_BUILD_PARALLEL_LEVEL is aliased in the [tool.scikit-build.env] table (added upstream in scikit-build-core#1377 for exactly this), so no custom PEP 517 wrapper backend is needed -- the backend is plain scikit_build_core.build. - Dynamic version/dependencies use the stable [[tool.dynamic-metadata]] table (no experimental flag); the dependencies provider marks deps Dynamic in the sdist via a dynamic_wheel hook. - Build type comes from the environment: 1.0 honors CMAKE_BUILD_TYPE natively, so only the DEBUG / REL_WITH_DEB_INFO env-var overrides remain. - Per-image Linux compiler handling is CC/CXX = { env = ... } in the env table, which opts out of scikit-build-core's sysconfig-compiler injection (documented behavior since pytorch#1377) and lets CMake detect the compiler from PATH -- what green setup.py builds always did -- replacing two per-image cmake.define overrides. - The Windows Ninja generator is cmake.define.CMAKE_GENERATOR in a win32 override (1.0's generator-resolution chain honors it), so pyproject is the single source of truth and a plain editable Windows build gets Ninja too; the CI scripts no longer export CMAKE_GENERATOR. The build-system floor and requirements-build.txt are scikit-build-core >= 1.0; minimum-version pins the schema to that floor; and the CI pin (.ci/docker/requirements-ci.txt) plus the Windows build-dep installers are == 1.0.0. scikit-build-core 1.0.0 released 2026-07-06. ## Test plan Wheel content-equivalent to the setuptools build (pytorch#180243), fresh cp312 CPU artifacts: - [x] **Wheel size**: 193,274,760 B vs pytorch#180243 193,263,155 B (+0.006 %). - [x] **Manifest diff**: adds only 6 license files and removes the setuptools-specific `top_level.txt`; no layout spillage. ``` diff <(unzip -Z1 243.whl | sort) <(unzip -Z1 247.whl | sort) ``` - [x] **METADATA / version.py** identical bar `git_version` and the extra License-File entries; exactly one `_C.cpython-312.so`; aotriton payload intact (10,612 `aotriton.images/` kernels across 6 arches). - [x] **Build time**: no regression; manywheel builds faster (the gain is packaging, not compilation). Clean-build + editable import against the released scikit-build-core 1.0.0: - [x] Linux (qgpu3, CUDA op), macOS (qmac, MPS), Windows (win11 VM): fresh `pip install -e . --no-build-isolation` builds and `import torch` resolves the CMake-built native artifacts from the install location. The Windows run also confirmed the Ninja generator comes purely from pyproject (no CMAKE_GENERATOR env var; build.ninja present, no .sln). - [x] lintrunner -a clean (two pre-existing torch.bcomplex32 PYREFLY errors in torch/storage.py + torch/testing/_creation.py are on trunk, untouched). Re-validated on this PR's CI (carries ciflow/trunk): the dropped per-image Linux compiler overrides, exercised by the anaconda (conda-gcc11, compiler_compat) and aarch64 image builds -- the two cases those overrides originally fixed. Based on a patch by Henry Schreiner (scikit-build-core maintainer); the env table (scikit-build-core#1377) was added upstream specifically to let PyTorch delete its wrapper backend. Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#180247 Approved by: https://github.com/atalman, https://github.com/albanD
…ytorch#180248) With the build fully driven by scikit-build-core (pytorch#180247), the setuptools path is dead code. Remove the setuptools build helpers (build_pytorch_libs, setup_helpers.{cmake,cmake_utils,env}, test_cmake) and replace setup.py with a small shim that forwards `install` and `develop` to pip and fails with instructions for everything else. Retain a minimal build_libtorch.py -- it calls cmake directly and is still used by the libtorch build path. ## Why a phased sunset instead of outright removal? pip and `python -m build` never execute setup.py; the only way it still runs is a direct `python setup.py <cmd>` invocation. For `install` and `develop` we have redirected to pip since pytorch#152276; the shim keeps that contract intact for two more releases so existing scripts keep working while they migrate. Every other command (`build`, `bdist_wheel`, `clean`, `sdist`, ...) used to fall through into the setuptools machinery this PR deletes; emulating that interface is not worth it (setuptools itself deprecated it in 2021), so those commands now fail immediately, printing the replacement commands and the sunset schedule -- a more helpful failure mode than `can't open file 'setup.py'` while still surfacing not-yet-migrated callers. The schedule is stated in the shim header and printed on every invocation: - PyTorch 2.14-2.15: `install`/`develop` forward to pip; all other commands fail with instructions - PyTorch 2.16-2.17: all commands fail with instructions - PyTorch 2.18: setup.py is removed ## Test plan - [x] **Wheel byte-identical to parent pytorch#180247**: empty manifest diff, +10 B zip-timestamp noise. Removing the dead setuptools machinery does not change wheel content (it is never shipped, and scikit-build-core does not use it). The shim cannot change this: nothing installs the root setup.py into the wheel. ``` diff <(unzip -Z1 247.whl | sort) <(unzip -Z1 248.whl | sort) # empty ``` - [x] **Shim forwarding**: `install`/`develop` forward to pip with the exact pytorch#152276 command line, extra arguments are dropped with a warning, and pip's exit code is propagated (verified with a stub pip that prints its argv and exits 3): ``` python setup.py develop --user # pip install -v --no-build-isolation -e ., warns about dropped --user python setup.py install # pip install -v --no-build-isolation . ``` - [x] **Shim guard**: every other command fails with exit code 1, printing the replacement commands and the sunset schedule: ``` python setup.py bdist_wheel ``` - [x] **No dangling references** to the removed modules (`build_pytorch_libs`, `setup_helpers.{cmake,cmake_utils,env}`, `test_cmake`); the remaining `tools/setup_helpers` references point to surviving files (`generate_code.py`, `gen_version_header.py`, `generate_linker_script.py`). ``` grep -rE 'build_pytorch_libs|setup_helpers\.(cmake|env)' --include='*.py' . ``` - [x] **0 build failures** across the matrix -- the removed path was genuinely dead. Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#180248 Approved by: https://github.com/albanD, https://github.com/atalman
scikit-build-core collects sdist contents by walking the tree with gitignore semantics rather than from git tracking. Several vendored trees commit files that their own .gitignore matches (XNNPACK's generated microkernels under gen/, all oneDNN C++ sources via ideep's "*.cpp" pattern, protobuf's checked-in *.pb.cc, clog under qnnpack's deps/), and PyTorch's top-level .gitignore patterns (bare "gen", "*.pb.h") also match tracked third-party files. The walk therefore silently dropped ~11,500 tracked files, leaving an sdist that cannot build: XNNPACK, oneDNN, cpuinfo, and NNPACK codegen all lack sources. The legacy setup.py sdist never hit this because MANIFEST.in grafts copy from disk regardless of gitignore. Fix: re-include the affected roots via [tool.scikit-build.sdist]. In scikit-build-core's collector, include matches take precedence over every exclude source (user excludes, built-ins, gitignore), so a separate sdist.exclude list cannot trim a blanket include; entries that must not ship despite the blanket include are negated inside the include list and then caught by an exclude source (see the comment in pyproject.toml for the exact mechanics). The natural alternative -- collecting the file list from git tracking -- does not exist in scikit-build-core today; worth proposing upstream, at which point this block can go away. Deliberately excluded (1323 tracked files, matching the legacy MANIFEST.in's intent): repo/CI plumbing (.github, .ci, .claude, .spin, vendored .github dirs) and unneeded vendored language bindings (flatbuffers java/kotlin, ittapi rust). The latter were pruned by MANIFEST.in (pytorch#157814) to work around invalid symlinks in those trees; under scikit-build-core the default sdist.resolve-symlinks="all" would instead silently duplicate the link targets into the sdist. With these prunes the sdist contains no symlink members at all; the handful of remaining tracked symlinks (AGENTS.md, docs/requirements.txt, ...) dereference to a few KB of duplicated content. MANIFEST.in itself is removed: scikit-build-core's native backend never reads it, so it has been inert since the backend switch and its sdist role is fully replaced by the configuration added here. ## Test plan - [x] sdist file list matches `git ls-files --recurse-submodules` exactly, up to (a) the 1323 deliberately excluded files above and (b) 4 unicode-quoting artifacts of the listing comparison itself, with zero .git pointers, bytecode, third_party/nccl content, or symlink members: ``` uv build --sdist --out-dir dist git ls-files --recurse-submodules | sort > /tmp/git-files.txt tar tzf dist/torch-*.tar.gz | sed 's|^[^/]*/||' | grep -v '/$' | sort > /tmp/sdist-files.txt comm -23 /tmp/git-files.txt /tmp/sdist-files.txt grep -cE '\.git$|\.pyc$|__pycache__|^third_party/nccl/|(^|/)\.github/|^\.ci/|^\.claude/|^\.spin/' /tmp/sdist-files.txt tar tvzf dist/torch-*.tar.gz | grep -c '^l' ``` - [x] From-sdist build works end to end (CPU-only, linux-x86_64): ``` pip wheel dist/torch-*.tar.gz --no-deps -w /tmp/wheels python -m venv /tmp/venv && /tmp/venv/bin/pip install /tmp/wheels/torch-*.whl numpy /tmp/venv/bin/python -c "import torch; a=torch.randn(64,64); print(([email protected]).shape); print(torch.compile(lambda x: x.sin()+1)(torch.randn(8)).shape)" ``` - [x] Superset of the setuptools sdist's tracked content: compared against a `python setup.py sdist` tarball built from main (7de45b6), zero tracked files are present there but missing here; the ~480 tracked files only present here are ones MANIFEST.in dropped as collateral (submodule .gitignore/.gitmodules via `global-exclude .git*`, flatbuffers test data lost to a setuptools symlink-walk quirk). - [x] include/exclude interaction verified against scikit-build-core 1.0.3's collector with a synthetic tree, including the counterfactual configs (negation-only and exclude-only both leak files; the pairing is required). - [x] No remaining consumers of MANIFEST.in: ``` grep -rln "MANIFEST.in" --exclude-dir=third_party --exclude-dir=.git . ``` Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#190192 Approved by: https://github.com/albanD, https://github.com/atalman ghstack dependencies: pytorch#180248
…0247) Switch pyproject.toml's build backend from setuptools to scikit-build-core (>= 1.0), which invokes CMake directly instead of having setup.py orchestrate it. This PR makes the backend swap plus the 1.0-native configuration it enables; the now-unused setuptools code is removed separately in pytorch#180248, so this diff stays focused and is revertible on its own. Where to look, in order of importance: - pyproject.toml: the new [build-system], the scikit-build-core config (the [tool.scikit-build.env] table, cmake defines, wheel layout, editable mode), and the dynamic-metadata hooks. This is the heart of the change. - tools/metadata/{version,dependencies}.py: the providers backing those hooks -- wheel version (from generate_torch_version) and dependencies (base + CUDA/ROCm extras). - CMakeLists.txt: project name/version now come from SKBUILD_* with fallbacks so a standalone `cmake` invocation still works. - torch/__init__.py, torch/_utils_internal.py: import-time shims that keep editable installs working under the new backend. scikit-build-core's redirect finder resolves the extension module itself (`import torch._C`); the shims only cover the places PyTorch locates native artifacts by hand, off `__file__`, which the import system never sees: the `ctypes.CDLL` preload of libtorch_global_deps, the Windows `os.add_dll_directory` for `_C`'s dependent DLLs, and the `bin/` data-file path. Redirect mode is the first layout to split the Python sources (checkout) from the compiled artifacts (install tree); in wheel and `setup.py develop` installs they sat together, so those `dirname(__file__)` lookups happened to be right. - CONTRIBUTING.md: documents the editable-install flow, including scikit-build-core's optional rebuild-on-import (SKBUILD_EDITABLE_REBUILD), which stays off by default. - tools/linter/adapters/codespell_linter.py: works around a codespell bug (it crashes reading a pyproject.toml with an array-of-tables under [tool], which our new [[tool.dynamic-metadata]] introduces) by pointing codespell at the dictionary directly instead of `--toml pyproject.toml`. Reported upstream as codespell-project/codespell#3969. The remainder is mechanical: CI scripts swap `python setup.py clean` for `python -m spin clean` and probe for pyproject.toml instead of setup.py, and the build-requirement files gain scikit-build-core. The configuration uses the scikit-build-core 1.0 feature set, which keeps several PyTorch-specific workarounds out of the tree: - MAX_JOBS -> CMAKE_BUILD_PARALLEL_LEVEL is aliased in the [tool.scikit-build.env] table (added upstream in scikit-build-core#1377 for exactly this), so no custom PEP 517 wrapper backend is needed -- the backend is plain scikit_build_core.build. - Dynamic version/dependencies use the stable [[tool.dynamic-metadata]] table (no experimental flag); the dependencies provider marks deps Dynamic in the sdist via a dynamic_wheel hook. - Build type comes from the environment: 1.0 honors CMAKE_BUILD_TYPE natively, so only the DEBUG / REL_WITH_DEB_INFO env-var overrides remain. - Per-image Linux compiler handling is CC/CXX = { env = ... } in the env table, which opts out of scikit-build-core's sysconfig-compiler injection (documented behavior since pytorch#1377) and lets CMake detect the compiler from PATH -- what green setup.py builds always did -- replacing two per-image cmake.define overrides. - The Windows Ninja generator is cmake.define.CMAKE_GENERATOR in a win32 override (1.0's generator-resolution chain honors it), so pyproject is the single source of truth and a plain editable Windows build gets Ninja too; the CI scripts no longer export CMAKE_GENERATOR. The build-system floor and requirements-build.txt are scikit-build-core >= 1.0; minimum-version pins the schema to that floor; and the CI pin (.ci/docker/requirements-ci.txt) plus the Windows build-dep installers are == 1.0.0. scikit-build-core 1.0.0 released 2026-07-06. ## Test plan Wheel content-equivalent to the setuptools build (pytorch#180243), fresh cp312 CPU artifacts: - [x] **Wheel size**: 193,274,760 B vs pytorch#180243 193,263,155 B (+0.006 %). - [x] **Manifest diff**: adds only 6 license files and removes the setuptools-specific `top_level.txt`; no layout spillage. ``` diff <(unzip -Z1 243.whl | sort) <(unzip -Z1 247.whl | sort) ``` - [x] **METADATA / version.py** identical bar `git_version` and the extra License-File entries; exactly one `_C.cpython-312.so`; aotriton payload intact (10,612 `aotriton.images/` kernels across 6 arches). - [x] **Build time**: no regression; manywheel builds faster (the gain is packaging, not compilation). Clean-build + editable import against the released scikit-build-core 1.0.0: - [x] Linux (qgpu3, CUDA op), macOS (qmac, MPS), Windows (win11 VM): fresh `pip install -e . --no-build-isolation` builds and `import torch` resolves the CMake-built native artifacts from the install location. The Windows run also confirmed the Ninja generator comes purely from pyproject (no CMAKE_GENERATOR env var; build.ninja present, no .sln). - [x] lintrunner -a clean (two pre-existing torch.bcomplex32 PYREFLY errors in torch/storage.py + torch/testing/_creation.py are on trunk, untouched). Re-validated on this PR's CI (carries ciflow/trunk): the dropped per-image Linux compiler overrides, exercised by the anaconda (conda-gcc11, compiler_compat) and aarch64 image builds -- the two cases those overrides originally fixed. Based on a patch by Henry Schreiner (scikit-build-core maintainer); the env table (scikit-build-core#1377) was added upstream specifically to let PyTorch delete its wrapper backend. Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#180247 Approved by: https://github.com/atalman, https://github.com/albanD
…ytorch#180248) With the build fully driven by scikit-build-core (pytorch#180247), the setuptools path is dead code. Remove the setuptools build helpers (build_pytorch_libs, setup_helpers.{cmake,cmake_utils,env}, test_cmake) and replace setup.py with a small shim that forwards `install` and `develop` to pip and fails with instructions for everything else. Retain a minimal build_libtorch.py -- it calls cmake directly and is still used by the libtorch build path. ## Why a phased sunset instead of outright removal? pip and `python -m build` never execute setup.py; the only way it still runs is a direct `python setup.py <cmd>` invocation. For `install` and `develop` we have redirected to pip since pytorch#152276; the shim keeps that contract intact for two more releases so existing scripts keep working while they migrate. Every other command (`build`, `bdist_wheel`, `clean`, `sdist`, ...) used to fall through into the setuptools machinery this PR deletes; emulating that interface is not worth it (setuptools itself deprecated it in 2021), so those commands now fail immediately, printing the replacement commands and the sunset schedule -- a more helpful failure mode than `can't open file 'setup.py'` while still surfacing not-yet-migrated callers. The schedule is stated in the shim header and printed on every invocation: - PyTorch 2.14-2.15: `install`/`develop` forward to pip; all other commands fail with instructions - PyTorch 2.16-2.17: all commands fail with instructions - PyTorch 2.18: setup.py is removed ## Test plan - [x] **Wheel byte-identical to parent pytorch#180247**: empty manifest diff, +10 B zip-timestamp noise. Removing the dead setuptools machinery does not change wheel content (it is never shipped, and scikit-build-core does not use it). The shim cannot change this: nothing installs the root setup.py into the wheel. ``` diff <(unzip -Z1 247.whl | sort) <(unzip -Z1 248.whl | sort) # empty ``` - [x] **Shim forwarding**: `install`/`develop` forward to pip with the exact pytorch#152276 command line, extra arguments are dropped with a warning, and pip's exit code is propagated (verified with a stub pip that prints its argv and exits 3): ``` python setup.py develop --user # pip install -v --no-build-isolation -e ., warns about dropped --user python setup.py install # pip install -v --no-build-isolation . ``` - [x] **Shim guard**: every other command fails with exit code 1, printing the replacement commands and the sunset schedule: ``` python setup.py bdist_wheel ``` - [x] **No dangling references** to the removed modules (`build_pytorch_libs`, `setup_helpers.{cmake,cmake_utils,env}`, `test_cmake`); the remaining `tools/setup_helpers` references point to surviving files (`generate_code.py`, `gen_version_header.py`, `generate_linker_script.py`). ``` grep -rE 'build_pytorch_libs|setup_helpers\.(cmake|env)' --include='*.py' . ``` - [x] **0 build failures** across the matrix -- the removed path was genuinely dead. Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#180248 Approved by: https://github.com/albanD, https://github.com/atalman
scikit-build-core collects sdist contents by walking the tree with gitignore semantics rather than from git tracking. Several vendored trees commit files that their own .gitignore matches (XNNPACK's generated microkernels under gen/, all oneDNN C++ sources via ideep's "*.cpp" pattern, protobuf's checked-in *.pb.cc, clog under qnnpack's deps/), and PyTorch's top-level .gitignore patterns (bare "gen", "*.pb.h") also match tracked third-party files. The walk therefore silently dropped ~11,500 tracked files, leaving an sdist that cannot build: XNNPACK, oneDNN, cpuinfo, and NNPACK codegen all lack sources. The legacy setup.py sdist never hit this because MANIFEST.in grafts copy from disk regardless of gitignore. Fix: re-include the affected roots via [tool.scikit-build.sdist]. In scikit-build-core's collector, include matches take precedence over every exclude source (user excludes, built-ins, gitignore), so a separate sdist.exclude list cannot trim a blanket include; entries that must not ship despite the blanket include are negated inside the include list and then caught by an exclude source (see the comment in pyproject.toml for the exact mechanics). The natural alternative -- collecting the file list from git tracking -- does not exist in scikit-build-core today; worth proposing upstream, at which point this block can go away. Deliberately excluded (1323 tracked files, matching the legacy MANIFEST.in's intent): repo/CI plumbing (.github, .ci, .claude, .spin, vendored .github dirs) and unneeded vendored language bindings (flatbuffers java/kotlin, ittapi rust). The latter were pruned by MANIFEST.in (pytorch#157814) to work around invalid symlinks in those trees; under scikit-build-core the default sdist.resolve-symlinks="all" would instead silently duplicate the link targets into the sdist. With these prunes the sdist contains no symlink members at all; the handful of remaining tracked symlinks (AGENTS.md, docs/requirements.txt, ...) dereference to a few KB of duplicated content. MANIFEST.in itself is removed: scikit-build-core's native backend never reads it, so it has been inert since the backend switch and its sdist role is fully replaced by the configuration added here. ## Test plan - [x] sdist file list matches `git ls-files --recurse-submodules` exactly, up to (a) the 1323 deliberately excluded files above and (b) 4 unicode-quoting artifacts of the listing comparison itself, with zero .git pointers, bytecode, third_party/nccl content, or symlink members: ``` uv build --sdist --out-dir dist git ls-files --recurse-submodules | sort > /tmp/git-files.txt tar tzf dist/torch-*.tar.gz | sed 's|^[^/]*/||' | grep -v '/$' | sort > /tmp/sdist-files.txt comm -23 /tmp/git-files.txt /tmp/sdist-files.txt grep -cE '\.git$|\.pyc$|__pycache__|^third_party/nccl/|(^|/)\.github/|^\.ci/|^\.claude/|^\.spin/' /tmp/sdist-files.txt tar tvzf dist/torch-*.tar.gz | grep -c '^l' ``` - [x] From-sdist build works end to end (CPU-only, linux-x86_64): ``` pip wheel dist/torch-*.tar.gz --no-deps -w /tmp/wheels python -m venv /tmp/venv && /tmp/venv/bin/pip install /tmp/wheels/torch-*.whl numpy /tmp/venv/bin/python -c "import torch; a=torch.randn(64,64); print(([email protected]).shape); print(torch.compile(lambda x: x.sin()+1)(torch.randn(8)).shape)" ``` - [x] Superset of the setuptools sdist's tracked content: compared against a `python setup.py sdist` tarball built from main (7de45b6), zero tracked files are present there but missing here; the ~480 tracked files only present here are ones MANIFEST.in dropped as collateral (submodule .gitignore/.gitmodules via `global-exclude .git*`, flatbuffers test data lost to a setuptools symlink-walk quirk). - [x] include/exclude interaction verified against scikit-build-core 1.0.3's collector with a synthetic tree, including the counterfactual configs (negation-only and exclude-only both leak files; the pairing is required). - [x] No remaining consumers of MANIFEST.in: ``` grep -rln "MANIFEST.in" --exclude-dir=third_party --exclude-dir=.git . ``` Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#190192 Approved by: https://github.com/albanD, https://github.com/atalman ghstack dependencies: pytorch#180248
…d suffix Since pytorch#180243 the torch._C extension is built by CMake via Python_add_library(_C MODULE WITH_SOABI ...). WITH_SOABI names the module using Python_SOABI, which CMake's FindPython only computes by running the interpreter when NOT cross-compiling: under CMAKE_CROSSCOMPILING the query is skipped unless CMAKE_CROSSCOMPILING_EMULATOR is set (policy CMP0190), so Python_SOABI is left empty and WITH_SOABI silently emits an untagged _C.so. That breaks cross builds: the extension is installed under a name the target interpreter will not import, so import torch._C fails. This is the conda-forge linux-aarch64 failure in pytorch-cpu-feedstock pytorch#526. (When this was first diagnosed the symptom was different: setup.py collected the extension via package_data = f"_C{sysconfig.get_config_var('EXT_SUFFIX')}", the untagged name did not match, and _C was dropped from the wheel entirely. pytorch#180248 has since removed setup.py and _C is collected by install(TARGETS _C ...) in torch/CMakeLists.txt, so it now ships under the wrong name rather than going missing. Either way the target cannot import it.) pytorch#190003 has since widened which builds hit this. It forwards CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR from the environment before project(), so a cross setup that passes them that way now genuinely enters cross-compile mode. Such a build previously stayed in native mode -- CMAKE_CROSSCOMPILING FALSE, and FindPython computed Python_SOABI normally -- and so never produced an untagged module. It now takes the empty-SOABI path as well, which makes this fix the completion of that one rather than a conda-forge-only concern. CMake's sanctioned cross path (CMP0190 + an emulator) assumes the target interpreter is run under qemu/wine. That does not fit conda-forge's crossenv, where the interpreter is a build-native binary that reports the target's config and is directly runnable -- no emulator. So when Python_SOABI is empty while cross-compiling, we query SOABI from the interpreter (which crossenv answers with the target's value) and set it once, right where FindPython resolves the Development.Module component. Every downstream WITH_SOABI consumer (_C, and the CUDA-only _nccl_ep) then gets the correct suffix, and WITH_SOABI still composes the platform-specific filename. The override deliberately only fills an *empty* Python_SOABI. A non-empty value is authoritative and left untouched: with an emulator FindPython ran the target interpreter to compute it, whereas this bare invocation would run the wrong interpreter (or fail to exec the target binary), so it must not second-guess a value FindPython already produced. The empty case is both unambiguous and the actual failure observed (an untagged _C.so). This overrides Python_SOABI centrally rather than each target's SUFFIX because FindPython recomputes Python_SOABI on every find_package(Python), so a manual value only survives if nothing re-finds Python afterwards. That holds here: the last find is in this file, the override runs right after it, and the only later use of FindPython -- cmake/public/cuda.cmake, re-included from torch/CMakeLists.txt under USE_CUDA to hash libnvrtc -- is short-circuited on that second entry by the already-computed CUDA_NVRTC_SHORTHASH. So the override is not threatened by a lingering find_package and lands independently. An alternative considered was passing -DPython_SOABI=...; FindPython unsets and recomputes the variable on each find, so a command-line value is not honored. Authored with assistance from Claude Code. Test Plan: Confirmed in a standalone FindPython project that (a) a non-empty Python_SOABI is preserved and only an empty one takes the override path, and (b) setting Python_SOABI before the Python_add_library calls (no intervening find_package) drives the suffix of every WITH_SOABI module: ``` set(Python_SOABI "cpython-312-aarch64-linux-gnu") Python_add_library(_C MODULE WITH_SOABI stub.c) # -> _C.cpython-312-aarch64-linux-gnu.so Python_add_library(_nccl_ep MODULE WITH_SOABI stub.c) # -> _nccl_ep.cpython-312-aarch64-linux-gnu.so ``` This equals f"_C{EXT_SUFFIX}" since EXT_SUFFIX == "." + SOABI + shared-module suffix on Linux/macOS targets. Native builds are unchanged (the CMAKE_CROSSCOMPILING guard is not taken; FindPython's Python_SOABI already equals EXT_SUFFIX there). The pytorch#190003 interaction was checked separately on the same standalone project (cmake 3.28.3), reproducing the empty-SOABI condition from both directions: ``` # native, no toolchain vars cmake -S . -B b1 # CROSSCOMPILING=FALSE SOABI=cpython-310-x86_64-linux-gnu # env vars WITHOUT the pytorch#190003 forwarding block (pre-pytorch#190003 behaviour) CMAKE_SYSTEM_NAME=Linux CMAKE_SYSTEM_PROCESSOR=aarch64 cmake -S . -B b4 # CROSSCOMPILING=FALSE SOABI=cpython-310-x86_64-linux-gnu # env vars WITH the forwarding block (post-pytorch#190003) CMAKE_SYSTEM_NAME=Linux CMAKE_SYSTEM_PROCESSOR=aarch64 cmake -S . -B b2 # CROSSCOMPILING=TRUE SOABI='' # -D flags (the conda-forge CMAKE_ARGS path) cmake -S . -B b3 -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=aarch64 # CROSSCOMPILING=TRUE SOABI='' ``` End-to-end validation is a conda-forge linux-aarch64 build (pytorch-cpu-feedstock pytorch#526), where import torch._C succeeds.
Stack from ghstack (oldest at bottom):
With the build fully driven by scikit-build-core (#180247), the
setuptools path is dead code. Remove the setuptools build helpers
(build_pytorch_libs, setup_helpers.{cmake,cmake_utils,env}, test_cmake)
and replace setup.py with a small shim that forwards
installanddevelopto pip and fails with instructions for everything else.Retain a minimal build_libtorch.py -- it calls cmake directly and is
still used by the libtorch build path.
Why a phased sunset instead of outright removal?
pip and
python -m buildnever execute setup.py; the only way it stillruns is a direct
python setup.py <cmd>invocation. Forinstallanddevelopwe have redirected to pip since #152276; the shim keeps thatcontract intact for two more releases so existing scripts keep working
while they migrate. Every other command (
build,bdist_wheel,clean,sdist, ...) used to fall through into the setuptoolsmachinery this PR deletes; emulating that interface is not worth it
(setuptools itself deprecated it in 2021), so those commands now fail
immediately, printing the replacement commands and the sunset schedule
-- a more helpful failure mode than
can't open file 'setup.py'whilestill surfacing not-yet-migrated callers.
The schedule is stated in the shim header and printed on every
invocation:
install/developforward to pip; all othercommands fail with instructions
Test plan
+10 B zip-timestamp noise. Removing the dead setuptools machinery does
not change wheel content (it is never shipped, and scikit-build-core
does not use it). The shim cannot change this: nothing installs the
root setup.py into the wheel.
install/developforward to pip with theexact
setup.py developcommand is disappearing soon fromsetuptools#152276 command line, extra arguments are dropped with awarning, and pip's exit code is propagated (verified with a stub pip
that prints its argv and exits 3):
printing the replacement commands and the sunset schedule:
(
build_pytorch_libs,setup_helpers.{cmake,cmake_utils,env},test_cmake); the remainingtools/setup_helpersreferences point tosurviving files (
generate_code.py,gen_version_header.py,generate_linker_script.py).genuinely dead.
Co-Generated with Claude Code
cc @albanD