Skip to content

Install libaotriton_v2.so via cmake install for wheel packaging - #180242

Closed
zklaus wants to merge 35 commits into
gh/zklaus/48/basefrom
gh/zklaus/48/head
Closed

zklaus wants to merge 35 commits into
gh/zklaus/48/basefrom
gh/zklaus/48/head

Conversation

@zklaus

@zklaus zklaus commented Apr 13, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

aotriton's ExternalProject puts the library directly in the source tree
(torch/lib/) without a cmake install() rule, so it is absent from the
installed wheel. Add an install rule so it ends up in torch/lib/ in the
wheel.

Test plan

This PR is forward-compatibility insurance for the
scikit-build-core migration. Under the current setuptools backend,
aotriton's ExternalProject already drops libaotriton_v2.so into
${PROJECT_SOURCE_DIR}/torch/lib/ and setuptools collects the
torch/ package tree automatically, so the .so is in the wheel
without any cmake install() rule. The new rule resolves to a
cp torch/lib/foo torch/lib/foo no-op here. It only does work once
#180247 switches the backend to scikit-build-core, which does not
auto-collect arbitrary files -- the install rule becomes the only
mechanism that puts the .so in the wheel.

The verification at this PR's CI position is therefore "no regression
vs parent"; the functional payload is exercised at #180247's position.

  • No regression in wheel size vs parent ([BE] Add macOS OpenMP embedding to PostBuildSteps #180239) across
    every manywheel/libtorch artifact. Variance is sub-0.001 % to
    0.015 %, consistent across artifacts this PR cannot affect (xpu,
    cpu, cuda, libtorch-cpu), confirming the deltas are environmental
    (embedded git-sha / metadata) and not driven by this PR:

    artifact parent ([BE] Add macOS OpenMP embedding to PostBuildSteps #180239) this PR (Install libaotriton_v2.so via cmake install for wheel packaging #180242) delta
    manywheel-py3_12-rocm7_2 6,153,281,045 6,153,280,701 -344 (-0.000%)
    manywheel-py3_12-rocm7_1 5,788,503,094 5,788,503,789 +695 (+0.000%)
    manywheel-py3_12-cuda12_6 841,794,650 841,797,521 +2,871 (+0.000%)
    manywheel-py3_12-cuda13_2 624,122,109 624,213,880 +91,771 (+0.015%)
    manywheel-py3_12-cpu 189,246,486 189,248,452 +1,966 (+0.001%)
    manywheel-py3_12-xpu 778,714,838 778,712,445 -2,393 (-0.000%)
    libtorch-rocm7_2-shared-with-deps-release 12,117,315,533 12,117,315,856 +323 (+0.000%)
    libtorch-cpu-shared-with-deps-release 257,632,083 257,626,615 -5,468 (-0.002%)
  • Setuptools-era baseline content -- the ROCm wheel produced
    by this PR's CI ships:

    torch/lib/libaotriton_v2.so          17,907,145 bytes  (17.1 MB)
    torch/lib/libaotriton_v2.so.0.11.2   17,907,145 bytes  (17.1 MB)
    torch/lib/aotriton.images/           9,334 files       (870.9 MB total)
    

    That is what this PR is preserving across the scikit-build-core
    migration.

  • Full wheel-content equivalence vs parent
    (manywheel-py3_12-rocm7_2): both wheels contain 26,779 entries;
    the filename diff is empty and the per-file size diff is empty.
    Strongest no-regression evidence short of per-file SHA comparison.

Scope

  • ROCm wheels are Linux-only by build matrix
    (.github/scripts/generate_binary_build_matrix.py:130-135,
    supported_platforms=["Linux"]). Windows / macOS ROCm are out
    of scope.
  • No public torch header pulls in aotriton: aotriton_adapter.h is
    included only from .cu / .hip / .cpp files compiled into
    libtorch_hip.so. Ecosystem repos (pytorch/ao, pytorch/vision,
    pytorch/audio) have zero aotriton references, so aotriton
    headers are intentionally not shipped.

Co-Generated with Claude Code

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Apr 13, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/180242

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit e6dbd18 with merge base da74fec (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

zklaus added a commit to zklaus/pytorch that referenced this pull request Apr 13, 2026
aotriton's ExternalProject puts the library directly in the source tree
(torch/lib/) without a cmake install() rule, so it is absent from the
installed wheel. Add an install rule so it ends up in torch/lib/ in the
wheel.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: 3cd5bf7
Pull-Request: pytorch#180242
@zklaus
zklaus marked this pull request as ready for review April 14, 2026 18:31
@zklaus zklaus added ciflow/binaries Trigger all binary build and upload jobs on the PR release notes: releng release notes category labels Apr 14, 2026
zklaus added a commit to zklaus/pytorch that referenced this pull request Apr 15, 2026
aotriton's ExternalProject puts the library directly in the source tree
(torch/lib/) without a cmake install() rule, so it is absent from the
installed wheel. Add an install rule so it ends up in torch/lib/ in the
wheel.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: 3cd5bf7
Pull-Request: pytorch#180242
zklaus added a commit to zklaus/pytorch that referenced this pull request Apr 17, 2026
aotriton's ExternalProject puts the library directly in the source tree
(torch/lib/) without a cmake install() rule, so it is absent from the
installed wheel. Add an install rule so it ends up in torch/lib/ in the
wheel.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: 3cd5bf7
Pull-Request: pytorch#180242
zklaus added 3 commits April 20, 2026 13:41
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
zklaus added 5 commits May 11, 2026 12:03
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
zklaus added a commit to zklaus/pytorch that referenced this pull request May 12, 2026
aotriton's ExternalProject puts the library directly in the source tree
(torch/lib/) without a cmake install() rule, so it is absent from the
installed wheel. Add an install rule so it ends up in torch/lib/ in the
wheel.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: 88776a9
Pull-Request: pytorch#180242
[ghstack-poisoned]
zklaus added a commit to zklaus/pytorch that referenced this pull request May 13, 2026
aotriton's ExternalProject puts the library directly in the source tree
(torch/lib/) without a cmake install() rule, so it is absent from the
installed wheel. Add an install rule so it ends up in torch/lib/ in the
wheel.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: 4e2a672
Pull-Request: pytorch#180242
[ghstack-poisoned]
zklaus added 4 commits May 14, 2026 13:38
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]

@atalman atalman left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. But please provide test plan for these changes.

@zklaus zklaus added the ciflow/trunk Trigger trunk jobs on your pull request label May 19, 2026
@zklaus

zklaus commented May 20, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

pytorchmergebot pushed a commit to weishi-deng/pytorch that referenced this pull request May 21, 2026
…rch#180242)

aotriton's ExternalProject puts the library directly in the source tree
(torch/lib/) without a cmake install() rule, so it is absent from the
installed wheel. Add an install rule so it ends up in torch/lib/ in the
wheel.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180242
Approved by: https://github.com/atalman
ghstack dependencies: pytorch#180239
pytorchmergebot pushed a commit that referenced this pull request Jun 4, 2026
Move the build of the `torch._C` Python extension and the install of
`torch/version.py` from `setup.py` into `torch/CMakeLists.txt`, so
both the existing setuptools backend and the upcoming
scikit-build-core backend (#180247) go through the same code path.
The new `Python_add_library(_C MODULE WITH_SOABI ...)` target builds
the same `torch/csrc/stub.c` and installs at the wheel root (mapped to
`torch/` by `wheel.install-dir`); `setup.py`'s `Extension("torch._C",
...)` block and its companion `extra_compile_args` /
`extra_link_args` / `make_relative_rpath_args` plumbing are removed.
`version.py` is gitignored, so it is installed explicitly via
`install(FILES ... DESTINATION ".")` rather than relying on Python
package collection.

Adds a `BinaryDistribution` class in `setup.py` that forces
`has_ext_modules=True` so `bdist_wheel` uses the binary layout
(package_data + data_files only) instead of the purelib layout, which
would otherwise dump CMake's `build/lib/` tree -- including test
artifacts -- into the wheel root. `package_data` collects the
CMake-built extension via the interpreter's exact module name
(`f"_C{sysconfig.get_config_var('EXT_SUFFIX')}"`) rather than a `_C*`
glob, so a `build/` dir reused across Python versions cannot leak
other ABIs' `_C` modules into the wheel.

Windows handling: the manual `setup.py` copy of `_C.lib` from
`build_temp` to `build_lib` is replaced by the `_C` target's
`ARCHIVE DESTINATION "lib"`. For MSVC, the linker is told where to
find `pythonXX.lib` via `/LIBPATH` (Python headers use `#pragma
comment(lib, "pythonXX")` which expects a bare-name lookup); for
Windows venvs, FindPython's library search path is extended with
`sys.base_prefix/libs` since the import library lives in the base
install, not the venv. `nnapi_backend` gains
`TORCH_PYTHON_LINK_FLAGS` so it picks up the same MSVC linker
options as `torch_python`.

## Test plan

Verification is via artifact-content comparison against the parent
(#180242). Expectation: the wheel must be content-equivalent modulo
the one file the PR rebuilds (`torch/_C.cpython-*.so`), which must
remain functionally identical (same exports, same imports, same
rpath).

- [x] **No regression in artifact sizes** across every manywheel /
  libtorch artifact (sub-0.001 % to 0.001 % delta, zip-timestamp
  noise consistent across artifacts this PR can't directly affect):

  | artifact | parent (#180242) | this PR (#180243) | delta |
  | --- | ---: | ---: | ---: |
  | manywheel-py3_12-rocm7_2 | 6,153,280,701 | 6,153,275,144 | -5,557 (-0.000%) |
  | manywheel-py3_12-rocm7_1 | 5,788,503,789 | 5,788,499,957 | -3,832 (-0.000%) |
  | manywheel-py3_12-cuda12_6 | 841,797,521 | 841,797,813 | +292 (+0.000%) |
  | manywheel-py3_12-cuda13_2 | 624,213,880 | 624,212,127 | -1,753 (-0.000%) |
  | manywheel-py3_12-cpu | 189,248,452 | 189,248,117 | -335 (-0.000%) |
  | manywheel-py3_12-xpu | 778,712,445 | 778,711,285 | -1,160 (-0.000%) |
  | libtorch-rocm7_2-shared-with-deps-release | 12,117,315,856 | 12,117,314,539 | -1,317 (-0.000%) |
  | libtorch-cpu-shared-with-deps-release | 257,626,615 | 257,624,612 | -2,003 (-0.001%) |

- [x] **Wheel manifest equivalence vs parent**
  (`manywheel-py3_12-rocm7_2`): both wheels contain **26,779 entries**;
  filename diff is empty -- no files added or removed. Confirms the
  `BinaryDistribution` layout fix worked (no `build/lib/` spillage
  into the wheel root).

- [x] **Per-file size diff: exactly one file changed.**
  ```
  torch/_C.cpython-312-x86_64-linux-gnu.so   22,960  ->  15,720   (-7,240)
  ```
  Every other one of 26,778 files is byte-identical in size. That is
  precisely the file the PR rebuilds via CMake.

- [x] **`torch._C` is functionally equivalent** between parent and PR.
  Extracted both `.so` files and compared:
  - **Defined symbols**: zero-line diff.
  - **Undefined symbols** (imports from `libtorch_python`): zero-line
    diff.
  - **RPATH**: identical (`$ORIGIN:$ORIGIN/lib`).
  - **NEEDED**: 180242's `.so` includes a redundant
    `libpthread.so.0` (merged into `libc.so.6` since glibc 2.34); the
    CMake build drops it. The size shrinkage matches the cleaner
    NEEDED + tighter section layout from the CMake toolchain.

- [x] **`torch/version.py`** is present in both wheels at 339 bytes,
  byte-identical except for the expected `git_version` SHA (each
  commit has its own). `__version__`, `debug`, `cuda`, `hip`, `rocm`,
  `xpu` fields all match -- the CMake-driven generation produces the
  same output as the setuptools path.

- [x] **Exactly one `_C` ABI per wheel.** On a fresh multi-ABI
  `manywheel-cpu-build` (build_all.sh builds all CPython ABIs in one
  checkout), each wheel ships only its own `torch/_C.cpython-XY.so`.
  An earlier greedy `_C*.so` `package_data` glob leaked stale per-ABI
  stubs (a cp312 wheel carried cp310/cp311/cp312); pinning to the
  exact `EXT_SUFFIX` fixes it.
  ```
  unzip -l manywheel-py3_13-cpu.whl | grep 'torch/_C\.cpython'
  # -> only torch/_C.cpython-313-x86_64-linux-gnu.so
  ```

### Coverage notes

- **NNAPI MSVC link-flag fix** and **Windows venv `pythonXX.lib`
  discovery fix** are not exercised by the ROCm-Linux artifacts
  above. They are exercised by the Windows pull-CI (where NNAPI
  builds run and venv-based discovery is relevant); the green Windows
  CI is the evidence for those.
- ROCm wheels are Linux-only by build matrix
  (`.github/scripts/generate_binary_build_matrix.py:130-135`,
  `supported_platforms=["Linux"]`).

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: #180243
Approved by: https://github.com/malfet
@github-actions
github-actions Bot deleted the gh/zklaus/48/head branch June 20, 2026 02:28
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…rch#180242)

aotriton's ExternalProject puts the library directly in the source tree
(torch/lib/) without a cmake install() rule, so it is absent from the
installed wheel. Add an install rule so it ends up in torch/lib/ in the
wheel.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180242
Approved by: https://github.com/atalman
ghstack dependencies: pytorch#180239
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
)

Move the build of the `torch._C` Python extension and the install of
`torch/version.py` from `setup.py` into `torch/CMakeLists.txt`, so
both the existing setuptools backend and the upcoming
scikit-build-core backend (pytorch#180247) go through the same code path.
The new `Python_add_library(_C MODULE WITH_SOABI ...)` target builds
the same `torch/csrc/stub.c` and installs at the wheel root (mapped to
`torch/` by `wheel.install-dir`); `setup.py`'s `Extension("torch._C",
...)` block and its companion `extra_compile_args` /
`extra_link_args` / `make_relative_rpath_args` plumbing are removed.
`version.py` is gitignored, so it is installed explicitly via
`install(FILES ... DESTINATION ".")` rather than relying on Python
package collection.

Adds a `BinaryDistribution` class in `setup.py` that forces
`has_ext_modules=True` so `bdist_wheel` uses the binary layout
(package_data + data_files only) instead of the purelib layout, which
would otherwise dump CMake's `build/lib/` tree -- including test
artifacts -- into the wheel root. `package_data` collects the
CMake-built extension via the interpreter's exact module name
(`f"_C{sysconfig.get_config_var('EXT_SUFFIX')}"`) rather than a `_C*`
glob, so a `build/` dir reused across Python versions cannot leak
other ABIs' `_C` modules into the wheel.

Windows handling: the manual `setup.py` copy of `_C.lib` from
`build_temp` to `build_lib` is replaced by the `_C` target's
`ARCHIVE DESTINATION "lib"`. For MSVC, the linker is told where to
find `pythonXX.lib` via `/LIBPATH` (Python headers use `#pragma
comment(lib, "pythonXX")` which expects a bare-name lookup); for
Windows venvs, FindPython's library search path is extended with
`sys.base_prefix/libs` since the import library lives in the base
install, not the venv. `nnapi_backend` gains
`TORCH_PYTHON_LINK_FLAGS` so it picks up the same MSVC linker
options as `torch_python`.

## Test plan

Verification is via artifact-content comparison against the parent
(pytorch#180242). Expectation: the wheel must be content-equivalent modulo
the one file the PR rebuilds (`torch/_C.cpython-*.so`), which must
remain functionally identical (same exports, same imports, same
rpath).

- [x] **No regression in artifact sizes** across every manywheel /
  libtorch artifact (sub-0.001 % to 0.001 % delta, zip-timestamp
  noise consistent across artifacts this PR can't directly affect):

  | artifact | parent (pytorch#180242) | this PR (pytorch#180243) | delta |
  | --- | ---: | ---: | ---: |
  | manywheel-py3_12-rocm7_2 | 6,153,280,701 | 6,153,275,144 | -5,557 (-0.000%) |
  | manywheel-py3_12-rocm7_1 | 5,788,503,789 | 5,788,499,957 | -3,832 (-0.000%) |
  | manywheel-py3_12-cuda12_6 | 841,797,521 | 841,797,813 | +292 (+0.000%) |
  | manywheel-py3_12-cuda13_2 | 624,213,880 | 624,212,127 | -1,753 (-0.000%) |
  | manywheel-py3_12-cpu | 189,248,452 | 189,248,117 | -335 (-0.000%) |
  | manywheel-py3_12-xpu | 778,712,445 | 778,711,285 | -1,160 (-0.000%) |
  | libtorch-rocm7_2-shared-with-deps-release | 12,117,315,856 | 12,117,314,539 | -1,317 (-0.000%) |
  | libtorch-cpu-shared-with-deps-release | 257,626,615 | 257,624,612 | -2,003 (-0.001%) |

- [x] **Wheel manifest equivalence vs parent**
  (`manywheel-py3_12-rocm7_2`): both wheels contain **26,779 entries**;
  filename diff is empty -- no files added or removed. Confirms the
  `BinaryDistribution` layout fix worked (no `build/lib/` spillage
  into the wheel root).

- [x] **Per-file size diff: exactly one file changed.**
  ```
  torch/_C.cpython-312-x86_64-linux-gnu.so   22,960  ->  15,720   (-7,240)
  ```
  Every other one of 26,778 files is byte-identical in size. That is
  precisely the file the PR rebuilds via CMake.

- [x] **`torch._C` is functionally equivalent** between parent and PR.
  Extracted both `.so` files and compared:
  - **Defined symbols**: zero-line diff.
  - **Undefined symbols** (imports from `libtorch_python`): zero-line
    diff.
  - **RPATH**: identical (`$ORIGIN:$ORIGIN/lib`).
  - **NEEDED**: 180242's `.so` includes a redundant
    `libpthread.so.0` (merged into `libc.so.6` since glibc 2.34); the
    CMake build drops it. The size shrinkage matches the cleaner
    NEEDED + tighter section layout from the CMake toolchain.

- [x] **`torch/version.py`** is present in both wheels at 339 bytes,
  byte-identical except for the expected `git_version` SHA (each
  commit has its own). `__version__`, `debug`, `cuda`, `hip`, `rocm`,
  `xpu` fields all match -- the CMake-driven generation produces the
  same output as the setuptools path.

- [x] **Exactly one `_C` ABI per wheel.** On a fresh multi-ABI
  `manywheel-cpu-build` (build_all.sh builds all CPython ABIs in one
  checkout), each wheel ships only its own `torch/_C.cpython-XY.so`.
  An earlier greedy `_C*.so` `package_data` glob leaked stale per-ABI
  stubs (a cp312 wheel carried cp310/cp311/cp312); pinning to the
  exact `EXT_SUFFIX` fixes it.
  ```
  unzip -l manywheel-py3_13-cpu.whl | grep 'torch/_C\.cpython'
  # -> only torch/_C.cpython-313-x86_64-linux-gnu.so
  ```

### Coverage notes

- **NNAPI MSVC link-flag fix** and **Windows venv `pythonXX.lib`
  discovery fix** are not exercised by the ROCm-Linux artifacts
  above. They are exercised by the Windows pull-CI (where NNAPI
  builds run and venv-based discovery is relevant); the green Windows
  CI is the evidence for those.
- ROCm wheels are Linux-only by build matrix
  (`.github/scripts/generate_binary_build_matrix.py:130-135`,
  `supported_platforms=["Linux"]`).

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180243
Approved by: https://github.com/malfet
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…rch#180242)

aotriton's ExternalProject puts the library directly in the source tree
(torch/lib/) without a cmake install() rule, so it is absent from the
installed wheel. Add an install rule so it ends up in torch/lib/ in the
wheel.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180242
Approved by: https://github.com/atalman
ghstack dependencies: pytorch#180239
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
)

Move the build of the `torch._C` Python extension and the install of
`torch/version.py` from `setup.py` into `torch/CMakeLists.txt`, so
both the existing setuptools backend and the upcoming
scikit-build-core backend (pytorch#180247) go through the same code path.
The new `Python_add_library(_C MODULE WITH_SOABI ...)` target builds
the same `torch/csrc/stub.c` and installs at the wheel root (mapped to
`torch/` by `wheel.install-dir`); `setup.py`'s `Extension("torch._C",
...)` block and its companion `extra_compile_args` /
`extra_link_args` / `make_relative_rpath_args` plumbing are removed.
`version.py` is gitignored, so it is installed explicitly via
`install(FILES ... DESTINATION ".")` rather than relying on Python
package collection.

Adds a `BinaryDistribution` class in `setup.py` that forces
`has_ext_modules=True` so `bdist_wheel` uses the binary layout
(package_data + data_files only) instead of the purelib layout, which
would otherwise dump CMake's `build/lib/` tree -- including test
artifacts -- into the wheel root. `package_data` collects the
CMake-built extension via the interpreter's exact module name
(`f"_C{sysconfig.get_config_var('EXT_SUFFIX')}"`) rather than a `_C*`
glob, so a `build/` dir reused across Python versions cannot leak
other ABIs' `_C` modules into the wheel.

Windows handling: the manual `setup.py` copy of `_C.lib` from
`build_temp` to `build_lib` is replaced by the `_C` target's
`ARCHIVE DESTINATION "lib"`. For MSVC, the linker is told where to
find `pythonXX.lib` via `/LIBPATH` (Python headers use `#pragma
comment(lib, "pythonXX")` which expects a bare-name lookup); for
Windows venvs, FindPython's library search path is extended with
`sys.base_prefix/libs` since the import library lives in the base
install, not the venv. `nnapi_backend` gains
`TORCH_PYTHON_LINK_FLAGS` so it picks up the same MSVC linker
options as `torch_python`.

## Test plan

Verification is via artifact-content comparison against the parent
(pytorch#180242). Expectation: the wheel must be content-equivalent modulo
the one file the PR rebuilds (`torch/_C.cpython-*.so`), which must
remain functionally identical (same exports, same imports, same
rpath).

- [x] **No regression in artifact sizes** across every manywheel /
  libtorch artifact (sub-0.001 % to 0.001 % delta, zip-timestamp
  noise consistent across artifacts this PR can't directly affect):

  | artifact | parent (pytorch#180242) | this PR (pytorch#180243) | delta |
  | --- | ---: | ---: | ---: |
  | manywheel-py3_12-rocm7_2 | 6,153,280,701 | 6,153,275,144 | -5,557 (-0.000%) |
  | manywheel-py3_12-rocm7_1 | 5,788,503,789 | 5,788,499,957 | -3,832 (-0.000%) |
  | manywheel-py3_12-cuda12_6 | 841,797,521 | 841,797,813 | +292 (+0.000%) |
  | manywheel-py3_12-cuda13_2 | 624,213,880 | 624,212,127 | -1,753 (-0.000%) |
  | manywheel-py3_12-cpu | 189,248,452 | 189,248,117 | -335 (-0.000%) |
  | manywheel-py3_12-xpu | 778,712,445 | 778,711,285 | -1,160 (-0.000%) |
  | libtorch-rocm7_2-shared-with-deps-release | 12,117,315,856 | 12,117,314,539 | -1,317 (-0.000%) |
  | libtorch-cpu-shared-with-deps-release | 257,626,615 | 257,624,612 | -2,003 (-0.001%) |

- [x] **Wheel manifest equivalence vs parent**
  (`manywheel-py3_12-rocm7_2`): both wheels contain **26,779 entries**;
  filename diff is empty -- no files added or removed. Confirms the
  `BinaryDistribution` layout fix worked (no `build/lib/` spillage
  into the wheel root).

- [x] **Per-file size diff: exactly one file changed.**
  ```
  torch/_C.cpython-312-x86_64-linux-gnu.so   22,960  ->  15,720   (-7,240)
  ```
  Every other one of 26,778 files is byte-identical in size. That is
  precisely the file the PR rebuilds via CMake.

- [x] **`torch._C` is functionally equivalent** between parent and PR.
  Extracted both `.so` files and compared:
  - **Defined symbols**: zero-line diff.
  - **Undefined symbols** (imports from `libtorch_python`): zero-line
    diff.
  - **RPATH**: identical (`$ORIGIN:$ORIGIN/lib`).
  - **NEEDED**: 180242's `.so` includes a redundant
    `libpthread.so.0` (merged into `libc.so.6` since glibc 2.34); the
    CMake build drops it. The size shrinkage matches the cleaner
    NEEDED + tighter section layout from the CMake toolchain.

- [x] **`torch/version.py`** is present in both wheels at 339 bytes,
  byte-identical except for the expected `git_version` SHA (each
  commit has its own). `__version__`, `debug`, `cuda`, `hip`, `rocm`,
  `xpu` fields all match -- the CMake-driven generation produces the
  same output as the setuptools path.

- [x] **Exactly one `_C` ABI per wheel.** On a fresh multi-ABI
  `manywheel-cpu-build` (build_all.sh builds all CPython ABIs in one
  checkout), each wheel ships only its own `torch/_C.cpython-XY.so`.
  An earlier greedy `_C*.so` `package_data` glob leaked stale per-ABI
  stubs (a cp312 wheel carried cp310/cp311/cp312); pinning to the
  exact `EXT_SUFFIX` fixes it.
  ```
  unzip -l manywheel-py3_13-cpu.whl | grep 'torch/_C\.cpython'
  # -> only torch/_C.cpython-313-x86_64-linux-gnu.so
  ```

### Coverage notes

- **NNAPI MSVC link-flag fix** and **Windows venv `pythonXX.lib`
  discovery fix** are not exercised by the ROCm-Linux artifacts
  above. They are exercised by the Windows pull-CI (where NNAPI
  builds run and venv-based discovery is relevant); the green Windows
  CI is the evidence for those.
- ROCm wheels are Linux-only by build matrix
  (`.github/scripts/generate_binary_build_matrix.py:130-135`,
  `supported_platforms=["Linux"]`).

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180243
Approved by: https://github.com/malfet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/trunk Trigger trunk jobs on your pull request Merged open source release notes: releng release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants