Skip to content

[CMake] Make build folder succeed thru CPython version changes - #181147

Closed
malfet wants to merge 1 commit into
gh/malfet/847/basefrom
gh/malfet/847/head
Closed

malfet wants to merge 1 commit into
gh/malfet/847/basefrom
gh/malfet/847/head

Conversation

@malfet

@malfet malfet commented Apr 22, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

Prep for making binary builds unified and just reuse libtorch_cpu and friends across Python builds

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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 31ed64d with merge base 9daaaa2 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #181153

pytorchmergebot pushed a commit that referenced this pull request Apr 22, 2026
pytorchmergebot pushed a commit that referenced this pull request Apr 24, 2026
Build all macOS arm64 wheels on a single runner, cutting `macos-26-xlarge` runner-minutes ~75%. Leverages the `cmake.py` Python-cache-invalidation fix from #181147 so iterations 2..N in the shared `build/` only recompile `libtorch_python` + `_C` (~7 min each), not the full ~35 min build.

## What changed

- `wheel-build` is now a single `macos-26-xlarge` job. It installs `uv` via `astral-sh/setup-uv@v6`, pre-fetches every CPython in `DESIRED_PYTHONS` in parallel, then runs `.ci/wheel/build_all_macos_wheels.sh` which loops through the versions and calls `.ci/wheel/build_wheel.sh` with the right interpreter first on PATH.
- Delocate moved to its own parallelized step (`.ci/wheel/delocate_wheels.sh`) that runs `delocate-wheel` across all wheels via `xargs -P $(sysctl -n hw.ncpu)`. `delocate-listdeps` (pure diagnostic, was ~11 min/wheel) is dropped.
- New reusable workflow `.github/workflows/_binary-test-macos.yml` chains test (macos-26) → upload (ubuntu, via the existing `_binary-upload.yml`). The main workflow invokes it from a matrix, so each matrix entry spawns an independent test→upload chain — per-Python gating comes for free: test-X failing blocks only upload-X, not the whole fan-out.
- `wheel-test-upload` uses a sparse checkout covering only `.ci/pytorch/smoke_test/` — no submodules, no wheel-unrelated sources. Checkout clocks in at **~2 seconds** per matrix instance.
- Adding a new CPython version is a one-line edit to `FULL_PYTHON_VERSIONS` in the generator; `DESIRED_PYTHONS` env + test-upload matrix regenerate automatically.

## Timings

Compared 2026-04-23 nightly on main (run 24824391896) vs. this PR (run 24861993047):

|                                  | Before (main) | After (this PR) |
|----------------------------------|--------------:|----------------:|
| `macos-26-xlarge` runner-minutes | **~427**      | **~106**        |
| `macos-26` runner-minutes        | 0             | ~9              |
| Ubuntu runner-minutes (upload)   | ~36           | ~36             |
| Wall-clock                       | ~72 min       | ~112 min        |

**~75% reduction in `macos-26-xlarge` usage**, at the cost of ~1.5× wall-clock.

Before 7 parallel `wheel-build` jobs, each running full from-scratch build on `macos-26-xlarge` took roughly an hour.

After this change,  checkout takes ~5 min, install libomp + uv setup + pre-fetch all Pythons: ~2 min, first full python-3.10 build ~35 min, incremental rebuilds for 3.11-... ~7 min each, parallel delocate of all 7 wheels: ~28 min(to be removed), wheel artifact uploads: <20 s

`wheel-test-upload` matrix (7 instances, parallel): sparse checkout ~2 s, setup-python + smoke test 1–2 min on `macos-26`, then upload 4–5 min on ubuntu via `_binary-upload.yml`.

## Dependency graph

```
wheel-build (1 × macos-26-xlarge)
  ├─► wheel-test-upload matrix × 7
  │      └─ test (macos-26) → upload (ubuntu, via _binary-upload.yml)
  └─► libtorch-extract → libtorch-upload
```

## Possible downsides

- The new `wheel-build` runs `git clean -fxd` once at the start, then preserves `build/` across iterations. If the #181147 cache-invalidation regresses, we'd silently produce per-Python wheels linked against the wrong CPython ABI. `wheel-test-upload` smoke-tests on a fresh runner are the safety net.
- If iteration N fails, subsequent iterations don't build — failure on early 3.10 kills the whole `wheel-build` job. Acceptable for nightly.
- Wall-clock ~1.5× longer per nightly. If macOS nightly wall-clock becomes a bottleneck for release cadence, the build loop can be split back into a matrix — at which point the xlarge-minute savings would disappear.

Authored with Claude.

Pull Request resolved: #181171
Approved by: https://github.com/seemethere, https://github.com/atalman
malfet added a commit that referenced this pull request May 15, 2026
Mirrors #181171 (macOS) for linux-aarch64 CPU: one `linux.arm64.r7g.12xlarge.memory` job loops over all CPython versions in `DESIRED_PYTHONS` and reuses `build/` across iterations. libtorch_cpu (Python-ABI-free) is shared; only libtorch_python + `_C` are recompiled per interpreter, leveraging the cmake.py cache-invalidation fix from #181147.

cuda-aarch64 keeps its existing per-Python matrix; test+upload stay per-Python so failure on one Python only blocks that Python's upload.

Easy to extend later to (gpu_arch_type, desired_cuda) grouping for CUDA-aarch64 and x86 by adding more partitions to the template.

Authored with Claude.


ghstack-source-id: 0c35203
Pull-Request: #183931
malfet added a commit that referenced this pull request May 15, 2026
Mirrors #181171 (macOS) for linux CPU: one job per gpu_arch_type (cpu and cpu-aarch64) loops over all CPython versions in `DESIRED_PYTHONS` and reuses `build/` across iterations. libtorch_cpu (Python-ABI-free) is shared; only libtorch_python + `_C` are recompiled per interpreter, leveraging the cmake.py cache-invalidation fix from #181147.

Template's `unified_arch_types = ['cpu', 'cpu-aarch64']` is the partition switch -- add more entries (e.g. cuda variants) to fold them into the same pattern. CUDA, ROCm, and XPU stay on the per-Python matrix; test+upload stay per-Python so failure on one Python only blocks that Python's upload.

Authored with Claude.

ghstack-source-id: 618c3dd
Pull-Request: #183931
pytorchmergebot pushed a commit that referenced this pull request May 16, 2026
Mirrors #181171 (macOS) for linux CPU: one job per gpu_arch_type (cpu and cpu-aarch64) loops over all CPython versions in `DESIRED_PYTHONS` and reuses `build/` across iterations. libtorch_cpu (Python-ABI-free) is shared; only libtorch_python + `_C` are recompiled per interpreter, leveraging the cmake.py cache-invalidation fix from #181147.

Template's `unified_arch_types = ['cpu', 'cpu-aarch64']` is the partition switch -- add more entries (e.g. cuda variants) to fold them into the same pattern. CUDA, ROCm, and XPU stay on the per-Python matrix; test+upload stay per-Python so failure on one Python only blocks that Python's upload.

Authored with Claude.

## Before vs after

Comparing nightly 2026-05-15 08:28 UTC (per-Python matrix) to PR run at 18:46 UTC (unified build):

| Workflow | Stage | Before | After | Δ |
|---|---|---:|---:|---:|
| linux-aarch64-binary-manywheel | Build runner-minutes (`linux.arm64.r7g.12xlarge.memory`) | **244** (6 × ~40m) | **104** (1 × 104m) | **−57%** |
| linux-aarch64-binary-manywheel | Build wall-clock | ~41m | ~104m | +2.5× |
| linux-binary-manywheel (x86) | Build runner-minutes (`linux.12xlarge.memory.ephemeral`) | **294** (6 × ~49m) | **111** (1 × 111m) | **−62%** |
| linux-binary-manywheel (x86) | Build wall-clock | ~49m | ~111m | +2.2× |

### TTS — full CPU pipeline (build → upload, aarch64)

| Phase | Nightly (before) | PR (after) |
|---|---|---|
| Build starts | 08:30:58 | 18:50:34 |
| Build ends | 09:12:35 (last) | 20:34:47 |
| Test starts | 10:58:31 (queue ≈ 1h46m) | 21:15:20 (queue ≈ 41m) |
| Test ends | 11:06:10 (last) | 21:24:40 |
| Upload ends | 11:08:41 (last) | 21:27:53 |
| **Total TTS** | **~2h37m** | **~2h37m** |

~57–62% runner-minute reduction on the expensive build runners (~140m aarch64 / ~183m x86 saved per nightly). Build wall-clock ~2.2–2.5× longer, but end-to-end TTS unchanged on aarch64 because test queueing dominated under the old layout. x86 test+upload data pending the in-progress PR run.

Data: aarch64 nightly [25908164878](https://github.com/pytorch/pytorch/actions/runs/25908164878), aarch64 PR [25935357837](https://github.com/pytorch/pytorch/actions/runs/25935357837), x86 nightly [25908164859](https://github.com/pytorch/pytorch/actions/runs/25908164859), x86 PR [25935357836](https://github.com/pytorch/pytorch/actions/runs/25935357836).

Pull Request resolved: #183931
Approved by: https://github.com/huydhn
@github-actions
github-actions Bot deleted the gh/malfet/847/head branch May 23, 2026 02:30
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
…ch#181147)

Prep for making binary builds unified and just reuse `libtorch_cpu` and friends across Python builds
Pull Request resolved: pytorch#181147
Approved by: https://github.com/seemethere
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
Build all macOS arm64 wheels on a single runner, cutting `macos-26-xlarge` runner-minutes ~75%. Leverages the `cmake.py` Python-cache-invalidation fix from pytorch#181147 so iterations 2..N in the shared `build/` only recompile `libtorch_python` + `_C` (~7 min each), not the full ~35 min build.

## What changed

- `wheel-build` is now a single `macos-26-xlarge` job. It installs `uv` via `astral-sh/setup-uv@v6`, pre-fetches every CPython in `DESIRED_PYTHONS` in parallel, then runs `.ci/wheel/build_all_macos_wheels.sh` which loops through the versions and calls `.ci/wheel/build_wheel.sh` with the right interpreter first on PATH.
- Delocate moved to its own parallelized step (`.ci/wheel/delocate_wheels.sh`) that runs `delocate-wheel` across all wheels via `xargs -P $(sysctl -n hw.ncpu)`. `delocate-listdeps` (pure diagnostic, was ~11 min/wheel) is dropped.
- New reusable workflow `.github/workflows/_binary-test-macos.yml` chains test (macos-26) → upload (ubuntu, via the existing `_binary-upload.yml`). The main workflow invokes it from a matrix, so each matrix entry spawns an independent test→upload chain — per-Python gating comes for free: test-X failing blocks only upload-X, not the whole fan-out.
- `wheel-test-upload` uses a sparse checkout covering only `.ci/pytorch/smoke_test/` — no submodules, no wheel-unrelated sources. Checkout clocks in at **~2 seconds** per matrix instance.
- Adding a new CPython version is a one-line edit to `FULL_PYTHON_VERSIONS` in the generator; `DESIRED_PYTHONS` env + test-upload matrix regenerate automatically.

## Timings

Compared 2026-04-23 nightly on main (run 24824391896) vs. this PR (run 24861993047):

|                                  | Before (main) | After (this PR) |
|----------------------------------|--------------:|----------------:|
| `macos-26-xlarge` runner-minutes | **~427**      | **~106**        |
| `macos-26` runner-minutes        | 0             | ~9              |
| Ubuntu runner-minutes (upload)   | ~36           | ~36             |
| Wall-clock                       | ~72 min       | ~112 min        |

**~75% reduction in `macos-26-xlarge` usage**, at the cost of ~1.5× wall-clock.

Before 7 parallel `wheel-build` jobs, each running full from-scratch build on `macos-26-xlarge` took roughly an hour.

After this change,  checkout takes ~5 min, install libomp + uv setup + pre-fetch all Pythons: ~2 min, first full python-3.10 build ~35 min, incremental rebuilds for 3.11-... ~7 min each, parallel delocate of all 7 wheels: ~28 min(to be removed), wheel artifact uploads: <20 s

`wheel-test-upload` matrix (7 instances, parallel): sparse checkout ~2 s, setup-python + smoke test 1–2 min on `macos-26`, then upload 4–5 min on ubuntu via `_binary-upload.yml`.

## Dependency graph

```
wheel-build (1 × macos-26-xlarge)
  ├─► wheel-test-upload matrix × 7
  │      └─ test (macos-26) → upload (ubuntu, via _binary-upload.yml)
  └─► libtorch-extract → libtorch-upload
```

## Possible downsides

- The new `wheel-build` runs `git clean -fxd` once at the start, then preserves `build/` across iterations. If the pytorch#181147 cache-invalidation regresses, we'd silently produce per-Python wheels linked against the wrong CPython ABI. `wheel-test-upload` smoke-tests on a fresh runner are the safety net.
- If iteration N fails, subsequent iterations don't build — failure on early 3.10 kills the whole `wheel-build` job. Acceptable for nightly.
- Wall-clock ~1.5× longer per nightly. If macOS nightly wall-clock becomes a bottleneck for release cadence, the build loop can be split back into a matrix — at which point the xlarge-minute savings would disappear.

Authored with Claude.

Pull Request resolved: pytorch#181171
Approved by: https://github.com/seemethere, https://github.com/atalman
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ch#181147)

Prep for making binary builds unified and just reuse `libtorch_cpu` and friends across Python builds
Pull Request resolved: pytorch#181147
Approved by: https://github.com/seemethere
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
Build all macOS arm64 wheels on a single runner, cutting `macos-26-xlarge` runner-minutes ~75%. Leverages the `cmake.py` Python-cache-invalidation fix from pytorch#181147 so iterations 2..N in the shared `build/` only recompile `libtorch_python` + `_C` (~7 min each), not the full ~35 min build.

## What changed

- `wheel-build` is now a single `macos-26-xlarge` job. It installs `uv` via `astral-sh/setup-uv@v6`, pre-fetches every CPython in `DESIRED_PYTHONS` in parallel, then runs `.ci/wheel/build_all_macos_wheels.sh` which loops through the versions and calls `.ci/wheel/build_wheel.sh` with the right interpreter first on PATH.
- Delocate moved to its own parallelized step (`.ci/wheel/delocate_wheels.sh`) that runs `delocate-wheel` across all wheels via `xargs -P $(sysctl -n hw.ncpu)`. `delocate-listdeps` (pure diagnostic, was ~11 min/wheel) is dropped.
- New reusable workflow `.github/workflows/_binary-test-macos.yml` chains test (macos-26) → upload (ubuntu, via the existing `_binary-upload.yml`). The main workflow invokes it from a matrix, so each matrix entry spawns an independent test→upload chain — per-Python gating comes for free: test-X failing blocks only upload-X, not the whole fan-out.
- `wheel-test-upload` uses a sparse checkout covering only `.ci/pytorch/smoke_test/` — no submodules, no wheel-unrelated sources. Checkout clocks in at **~2 seconds** per matrix instance.
- Adding a new CPython version is a one-line edit to `FULL_PYTHON_VERSIONS` in the generator; `DESIRED_PYTHONS` env + test-upload matrix regenerate automatically.

## Timings

Compared 2026-04-23 nightly on main (run 24824391896) vs. this PR (run 24861993047):

|                                  | Before (main) | After (this PR) |
|----------------------------------|--------------:|----------------:|
| `macos-26-xlarge` runner-minutes | **~427**      | **~106**        |
| `macos-26` runner-minutes        | 0             | ~9              |
| Ubuntu runner-minutes (upload)   | ~36           | ~36             |
| Wall-clock                       | ~72 min       | ~112 min        |

**~75% reduction in `macos-26-xlarge` usage**, at the cost of ~1.5× wall-clock.

Before 7 parallel `wheel-build` jobs, each running full from-scratch build on `macos-26-xlarge` took roughly an hour.

After this change,  checkout takes ~5 min, install libomp + uv setup + pre-fetch all Pythons: ~2 min, first full python-3.10 build ~35 min, incremental rebuilds for 3.11-... ~7 min each, parallel delocate of all 7 wheels: ~28 min(to be removed), wheel artifact uploads: <20 s

`wheel-test-upload` matrix (7 instances, parallel): sparse checkout ~2 s, setup-python + smoke test 1–2 min on `macos-26`, then upload 4–5 min on ubuntu via `_binary-upload.yml`.

## Dependency graph

```
wheel-build (1 × macos-26-xlarge)
  ├─► wheel-test-upload matrix × 7
  │      └─ test (macos-26) → upload (ubuntu, via _binary-upload.yml)
  └─► libtorch-extract → libtorch-upload
```

## Possible downsides

- The new `wheel-build` runs `git clean -fxd` once at the start, then preserves `build/` across iterations. If the pytorch#181147 cache-invalidation regresses, we'd silently produce per-Python wheels linked against the wrong CPython ABI. `wheel-test-upload` smoke-tests on a fresh runner are the safety net.
- If iteration N fails, subsequent iterations don't build — failure on early 3.10 kills the whole `wheel-build` job. Acceptable for nightly.
- Wall-clock ~1.5× longer per nightly. If macOS nightly wall-clock becomes a bottleneck for release cadence, the build loop can be split back into a matrix — at which point the xlarge-minute savings would disappear.

Authored with Claude.

Pull Request resolved: pytorch#181171
Approved by: https://github.com/seemethere, https://github.com/atalman
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…83931)

Mirrors pytorch#181171 (macOS) for linux CPU: one job per gpu_arch_type (cpu and cpu-aarch64) loops over all CPython versions in `DESIRED_PYTHONS` and reuses `build/` across iterations. libtorch_cpu (Python-ABI-free) is shared; only libtorch_python + `_C` are recompiled per interpreter, leveraging the cmake.py cache-invalidation fix from pytorch#181147.

Template's `unified_arch_types = ['cpu', 'cpu-aarch64']` is the partition switch -- add more entries (e.g. cuda variants) to fold them into the same pattern. CUDA, ROCm, and XPU stay on the per-Python matrix; test+upload stay per-Python so failure on one Python only blocks that Python's upload.

Authored with Claude.

## Before vs after

Comparing nightly 2026-05-15 08:28 UTC (per-Python matrix) to PR run at 18:46 UTC (unified build):

| Workflow | Stage | Before | After | Δ |
|---|---|---:|---:|---:|
| linux-aarch64-binary-manywheel | Build runner-minutes (`linux.arm64.r7g.12xlarge.memory`) | **244** (6 × ~40m) | **104** (1 × 104m) | **−57%** |
| linux-aarch64-binary-manywheel | Build wall-clock | ~41m | ~104m | +2.5× |
| linux-binary-manywheel (x86) | Build runner-minutes (`linux.12xlarge.memory.ephemeral`) | **294** (6 × ~49m) | **111** (1 × 111m) | **−62%** |
| linux-binary-manywheel (x86) | Build wall-clock | ~49m | ~111m | +2.2× |

### TTS — full CPU pipeline (build → upload, aarch64)

| Phase | Nightly (before) | PR (after) |
|---|---|---|
| Build starts | 08:30:58 | 18:50:34 |
| Build ends | 09:12:35 (last) | 20:34:47 |
| Test starts | 10:58:31 (queue ≈ 1h46m) | 21:15:20 (queue ≈ 41m) |
| Test ends | 11:06:10 (last) | 21:24:40 |
| Upload ends | 11:08:41 (last) | 21:27:53 |
| **Total TTS** | **~2h37m** | **~2h37m** |

~57–62% runner-minute reduction on the expensive build runners (~140m aarch64 / ~183m x86 saved per nightly). Build wall-clock ~2.2–2.5× longer, but end-to-end TTS unchanged on aarch64 because test queueing dominated under the old layout. x86 test+upload data pending the in-progress PR run.

Data: aarch64 nightly [25908164878](https://github.com/pytorch/pytorch/actions/runs/25908164878), aarch64 PR [25935357837](https://github.com/pytorch/pytorch/actions/runs/25935357837), x86 nightly [25908164859](https://github.com/pytorch/pytorch/actions/runs/25908164859), x86 PR [25935357836](https://github.com/pytorch/pytorch/actions/runs/25935357836).

Pull Request resolved: pytorch#183931
Approved by: https://github.com/huydhn
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ch#181147)

Prep for making binary builds unified and just reuse `libtorch_cpu` and friends across Python builds
Pull Request resolved: pytorch#181147
Approved by: https://github.com/seemethere
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
Build all macOS arm64 wheels on a single runner, cutting `macos-26-xlarge` runner-minutes ~75%. Leverages the `cmake.py` Python-cache-invalidation fix from pytorch#181147 so iterations 2..N in the shared `build/` only recompile `libtorch_python` + `_C` (~7 min each), not the full ~35 min build.

## What changed

- `wheel-build` is now a single `macos-26-xlarge` job. It installs `uv` via `astral-sh/setup-uv@v6`, pre-fetches every CPython in `DESIRED_PYTHONS` in parallel, then runs `.ci/wheel/build_all_macos_wheels.sh` which loops through the versions and calls `.ci/wheel/build_wheel.sh` with the right interpreter first on PATH.
- Delocate moved to its own parallelized step (`.ci/wheel/delocate_wheels.sh`) that runs `delocate-wheel` across all wheels via `xargs -P $(sysctl -n hw.ncpu)`. `delocate-listdeps` (pure diagnostic, was ~11 min/wheel) is dropped.
- New reusable workflow `.github/workflows/_binary-test-macos.yml` chains test (macos-26) → upload (ubuntu, via the existing `_binary-upload.yml`). The main workflow invokes it from a matrix, so each matrix entry spawns an independent test→upload chain — per-Python gating comes for free: test-X failing blocks only upload-X, not the whole fan-out.
- `wheel-test-upload` uses a sparse checkout covering only `.ci/pytorch/smoke_test/` — no submodules, no wheel-unrelated sources. Checkout clocks in at **~2 seconds** per matrix instance.
- Adding a new CPython version is a one-line edit to `FULL_PYTHON_VERSIONS` in the generator; `DESIRED_PYTHONS` env + test-upload matrix regenerate automatically.

## Timings

Compared 2026-04-23 nightly on main (run 24824391896) vs. this PR (run 24861993047):

|                                  | Before (main) | After (this PR) |
|----------------------------------|--------------:|----------------:|
| `macos-26-xlarge` runner-minutes | **~427**      | **~106**        |
| `macos-26` runner-minutes        | 0             | ~9              |
| Ubuntu runner-minutes (upload)   | ~36           | ~36             |
| Wall-clock                       | ~72 min       | ~112 min        |

**~75% reduction in `macos-26-xlarge` usage**, at the cost of ~1.5× wall-clock.

Before 7 parallel `wheel-build` jobs, each running full from-scratch build on `macos-26-xlarge` took roughly an hour.

After this change,  checkout takes ~5 min, install libomp + uv setup + pre-fetch all Pythons: ~2 min, first full python-3.10 build ~35 min, incremental rebuilds for 3.11-... ~7 min each, parallel delocate of all 7 wheels: ~28 min(to be removed), wheel artifact uploads: <20 s

`wheel-test-upload` matrix (7 instances, parallel): sparse checkout ~2 s, setup-python + smoke test 1–2 min on `macos-26`, then upload 4–5 min on ubuntu via `_binary-upload.yml`.

## Dependency graph

```
wheel-build (1 × macos-26-xlarge)
  ├─► wheel-test-upload matrix × 7
  │      └─ test (macos-26) → upload (ubuntu, via _binary-upload.yml)
  └─► libtorch-extract → libtorch-upload
```

## Possible downsides

- The new `wheel-build` runs `git clean -fxd` once at the start, then preserves `build/` across iterations. If the pytorch#181147 cache-invalidation regresses, we'd silently produce per-Python wheels linked against the wrong CPython ABI. `wheel-test-upload` smoke-tests on a fresh runner are the safety net.
- If iteration N fails, subsequent iterations don't build — failure on early 3.10 kills the whole `wheel-build` job. Acceptable for nightly.
- Wall-clock ~1.5× longer per nightly. If macOS nightly wall-clock becomes a bottleneck for release cadence, the build loop can be split back into a matrix — at which point the xlarge-minute savings would disappear.

Authored with Claude.

Pull Request resolved: pytorch#181171
Approved by: https://github.com/seemethere, https://github.com/atalman
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…83931)

Mirrors pytorch#181171 (macOS) for linux CPU: one job per gpu_arch_type (cpu and cpu-aarch64) loops over all CPython versions in `DESIRED_PYTHONS` and reuses `build/` across iterations. libtorch_cpu (Python-ABI-free) is shared; only libtorch_python + `_C` are recompiled per interpreter, leveraging the cmake.py cache-invalidation fix from pytorch#181147.

Template's `unified_arch_types = ['cpu', 'cpu-aarch64']` is the partition switch -- add more entries (e.g. cuda variants) to fold them into the same pattern. CUDA, ROCm, and XPU stay on the per-Python matrix; test+upload stay per-Python so failure on one Python only blocks that Python's upload.

Authored with Claude.

## Before vs after

Comparing nightly 2026-05-15 08:28 UTC (per-Python matrix) to PR run at 18:46 UTC (unified build):

| Workflow | Stage | Before | After | Δ |
|---|---|---:|---:|---:|
| linux-aarch64-binary-manywheel | Build runner-minutes (`linux.arm64.r7g.12xlarge.memory`) | **244** (6 × ~40m) | **104** (1 × 104m) | **−57%** |
| linux-aarch64-binary-manywheel | Build wall-clock | ~41m | ~104m | +2.5× |
| linux-binary-manywheel (x86) | Build runner-minutes (`linux.12xlarge.memory.ephemeral`) | **294** (6 × ~49m) | **111** (1 × 111m) | **−62%** |
| linux-binary-manywheel (x86) | Build wall-clock | ~49m | ~111m | +2.2× |

### TTS — full CPU pipeline (build → upload, aarch64)

| Phase | Nightly (before) | PR (after) |
|---|---|---|
| Build starts | 08:30:58 | 18:50:34 |
| Build ends | 09:12:35 (last) | 20:34:47 |
| Test starts | 10:58:31 (queue ≈ 1h46m) | 21:15:20 (queue ≈ 41m) |
| Test ends | 11:06:10 (last) | 21:24:40 |
| Upload ends | 11:08:41 (last) | 21:27:53 |
| **Total TTS** | **~2h37m** | **~2h37m** |

~57–62% runner-minute reduction on the expensive build runners (~140m aarch64 / ~183m x86 saved per nightly). Build wall-clock ~2.2–2.5× longer, but end-to-end TTS unchanged on aarch64 because test queueing dominated under the old layout. x86 test+upload data pending the in-progress PR run.

Data: aarch64 nightly [25908164878](https://github.com/pytorch/pytorch/actions/runs/25908164878), aarch64 PR [25935357837](https://github.com/pytorch/pytorch/actions/runs/25935357837), x86 nightly [25908164859](https://github.com/pytorch/pytorch/actions/runs/25908164859), x86 PR [25935357836](https://github.com/pytorch/pytorch/actions/runs/25935357836).

Pull Request resolved: pytorch#183931
Approved by: https://github.com/huydhn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants