Skip to content

[BE] Build all XPU wheels on a single runner - #195699

Closed
xuhancn wants to merge 7 commits into
pytorch:mainfrom
xuhancn:xpu-manywheel-unified-takeover
Closed

xuhancn wants to merge 7 commits into
pytorch:mainfrom
xuhancn:xpu-manywheel-unified-takeover

Conversation

@xuhancn

@xuhancn xuhancn commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Take over #188136.

Builds all Linux XPU manywheel variants in one job, reusing ABI-independent C++/SYCL artifacts across Python versions while rebuilding Python-bound artifacts per interpreter.

Before vs after

Comparing the eight XPU matrix builds from #195438 run 33729050328 with the unified build from this PR, run 34123506914:

Linux XPU build runner-minutes

Before (per-Python matrix, 8 jobs) After (1 unified job) Delta
8 x ~78m = 623m (matrix jobs) 139m (unified job) -78%

This saves approximately 484 runner-minutes per XPU manywheel build.

Per-Python build breakdown

  • First Python (cp310): ~74m from a clean build.
  • Following seven Pythons (cp311 through cp315t): ~7m each on average.
  • The unified job produced all eight XPU wheel artifacts successfully.

The first build establishes the shared XPU backend. Subsequent interpreters reuse the SYCL kernel objects and device link, rebuilding only Python-ABI-bound components.

Fix for SYCL reuse

The earlier PATH-only tool pin did not prevent scikit-build-core from selecting the importable CMake/Ninja packages in each Python environment. The final implementation explicitly sets CMAKE_EXECUTABLE and passes the shared Ninja path through CMAKE_ARGS, keeping CMake's generated SYCL depfile commands stable across the loop.

Local Python 3.10 then Python 3.11 XPU builds confirmed zero SYCL object recompilations and zero XPU device relinks on the second build.

AI-assisted drafting; CI measurements and implementation reviewed by the PR author.

cc @gujinghui @PenghuiCheng @XiaobingSuper @jianyuh @jgong5 @mingfeima @sanchitintel @ashokei @jingxu10 @min-jean-cho @yanbing-j @Guobing-Chen @Xia-Weiwen @snadampal

@xuhancn
xuhancn requested a review from a team as a code owner September 2, 2026 06:07
@xuhancn xuhancn added topic: not user facing topic category ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR labels Sep 2, 2026
@pytorch-bot

pytorch-bot Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

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

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

@xuhancn xuhancn added the module: mkldnn Related to Intel IDEEP or oneDNN (a.k.a. mkldnn) integration label Sep 2, 2026
@xuhancn
xuhancn marked this pull request as draft September 2, 2026 06:21
@xuhancn xuhancn added ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR ciflow/xpu Run XPU CI tasks and removed ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR labels Sep 3, 2026
@xuhancn xuhancn added ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR and removed ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR labels Sep 3, 2026
@chuanqi129 chuanqi129 removed the ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR label Sep 3, 2026
@EikanWang
EikanWang requested a review from chuanqi129 September 6, 2026 12:28
@EikanWang

Copy link
Copy Markdown
Collaborator

I want to let @chuanqi129 make the final decision. Before that, I would like to understand the motivation.

@chuanqi129

Copy link
Copy Markdown
Collaborator

@xuhancn Seems the xpu build job is still timeout

@xuhancn

xuhancn commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

@xuhancn Seems the xpu build job is still timeout

Still debugging it.

@xuhancn
xuhancn marked this pull request as ready for review September 8, 2026 02:56
@xuhancn
xuhancn force-pushed the xpu-manywheel-unified-takeover branch from 7e474ab to 87732cc Compare September 8, 2026 05:08
@xuhancn

xuhancn commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

xuhancn and others added 3 commits September 9, 2026 11:37
Root cause: unified manywheel reconfigures once per Python ABI, and torch-xpu-ops FindSYCL custom-script content depends on target include directories. We already removed direct Python include dirs, but Python-derived transitive includes (for example site-packages/NumPy paths) can still vary by ABI and churn the generated SYCL custom-command scripts, causing avoidable torch_xpu_ops_gen rebuilds.

Fix: filter TORCH_XPU_OPS_INCLUDE_DIRS to exclude site-packages and python-versioned include path segments before add_subdirectory(third_party/torch-xpu-ops). This keeps SYCL custom-command inputs more ABI-agnostic and increases cross-iteration reuse.

Test Plan:

```bash
lintrunner -a -m upstream/main
git diff --check
```

AI-assisted: This commit was authored with the help of an AI coding assistant.
Root cause:
In unified manywheel jobs each Python-ABI iteration reconfigures the same
build directory with that iteration's own cmake/ninja wheels (installed per
/opt/python/cp3XX env by requirements-build.txt). CMake embeds CMAKE_COMMAND's
absolute path in the cmake_transform_depfile step it synthesizes for
DEPFILE-based custom commands, which is how every torch-xpu-ops SYCL device
object is compiled. Because that path changes per iteration, Ninja sees a
changed command and recompiles all torch-xpu-ops SYCL device objects plus the
multi-minute torch_xpu_ops device link on every Python iteration, so XPU
iterations cost ~64 min each instead of CUDA's ~10 min and the 8-Python job
cannot finish within the 420-minute timeout.

Fix:
Pin one cmake/ninja (captured on the first iteration) at the front of PATH for
the rest of the loop, so every Python-ABI iteration reconfigures with an
identical CMAKE_COMMAND. SYCL custom-command commands stay byte-stable across
ABIs and Ninja reuses the previously built device objects, skipping the device
link on later iterations.

The alternative of fixing this inside torch-xpu-ops FindSYCL was rejected: the
depfile-transform step is synthesized by CMake itself and is not reachable from
the FindSYCL custom commands, so the churn can only be removed at build
orchestration level.

Verified locally by reconfiguring the same XPU build tree for Python 3.10 and
then Python 3.11: with CMAKE_COMMAND held constant, the ninja edges for all
torch-xpu-ops SYCL device objects are byte-identical (only python-bound edges
differ), confirming the churn comes from the cmake path rather than Python
include/ABI flags.

Test Plan:
```bash
bash -n .ci/manywheel/build.sh
shellcheck .ci/manywheel/build.sh
lintrunner .ci/manywheel/build.sh
git diff --check
```

CI rerun of linux-binary-manywheel manywheel-xpu-build should show Python-ABI
iterations after the first dropping from ~64 min to ~10-15 min each.

AI-assisted: This commit was authored with the help of an AI coding assistant.
scikit-build-core prefers the importable cmake and ninja packages from each Python environment, so prepending shared symlinks to PATH did not keep CMAKE_COMMAND stable. Each ABI therefore changed every SYCL depfile command and rebuilt the XPU kernels.

Set CMAKE_EXECUTABLE explicitly and pass the shared Ninja path through CMAKE_ARGS. Local Python 3.10 and 3.11 XPU builds both completed successfully; the second build performed zero SYCL object compilations and zero XPU device links.

Test Plan:

```bash
python -m pip install -e . -v --no-build-isolation
spin lint
```

AI-assisted: This commit was authored with the help of an AI coding assistant.

Co-authored-by: Copilot <[email protected]>
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased xpu-manywheel-unified-takeover onto refs/remotes/origin/main, please pull locally before adding more changes (for example, via git checkout xpu-manywheel-unified-takeover && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the xpu-manywheel-unified-takeover branch from 8991197 to b05d60f Compare September 9, 2026 11:37
@Skylion007
Skylion007 requested a review from atalman September 9, 2026 16:23
@chuanqi129

Copy link
Copy Markdown
Collaborator

I want to let @chuanqi129 make the final decision. Before that, I would like to understand the motivation.

Hi @EikanWang, the main motivation is to reduce CD costs.

@ezyang ezyang added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Sep 10, 2026
Comment thread caffe2/CMakeLists.txt Resolved
Comment thread cmake/Modules/FindMKLDNN.cmake Resolved
Comment thread cmake/Modules/FindMKLDNN.cmake Resolved
@xuhancn

xuhancn commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator Author

@LuFinch

AI-assisted analysis, reviewed by me:

Thanks for the comments. I updated the oneDNN reuse check to require its generated build include directory, since public oneDNN headers depend on generated headers such as dnnl_config.h. I also changed ExternalProject_Add to use the normalized _xpu_mkldnn_prefix.

For the Python include filtering, torch_xpu_ops is an ABI-independent computing target and currently does not consume Python, NumPy, or pybind headers. Local validation confirmed that changing an unused Python include path causes Ninja to rebuild the target, while filtering it preserves reuse across Python ABIs. Future Python bindings should use a separate ABI-specific target.

@xuhancn
xuhancn requested review from LuFinch and a lite review from Copilot and removed request for LuFinch and Copilot September 14, 2026 07:44
Keep the torch-xpu-ops compute target explicitly Python-ABI-independent and validate both source and generated oneDNN headers before reusing an existing build. Use the normalized oneDNN ExternalProject prefix consistently so the build and reuse paths agree when the caller does not provide an override.

Test Plan:

    spin lint caffe2/CMakeLists.txt cmake/Modules/FindMKLDNN.cmake
    git diff --check -- caffe2/CMakeLists.txt cmake/Modules/FindMKLDNN.cmake

AI-assisted: This commit was authored with the help of an AI coding assistant and reviewed by the author.

@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

@atalman

atalman commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

@pytorchmergebot merge -f "all looks good, lets merge"

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

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

zklaus added a commit to zklaus/pytorch that referenced this pull request Sep 16, 2026
…le-runner rebase

The pytorchmergebot rebase onto main brought in pytorch#195699, which routes the
XPU manywheel build through the unified build_all.sh job. That commit's
template change merged cleanly, but the pre-rendered generated workflow was
taken textually from main, where the script still lived at
.ci/manywheel/build_all.sh. This branch moved it to .ci/wheel/linux/, so
manywheel-xpu-build failed with "No such file or directory" and
workflow-checks/lint flagged the generated file as stale. Regenerating from
the merged template fixes exactly that one line.

The same rebase also brought in the native-aot workflow (pytorch#190899), whose
paths filter names .ci/manywheel/build.sh. That entry is repointed to the
moved script so edits to the Linux build script keep triggering the
workflow.

Test Plan:

```
uv run --no-project --python 3.10 --with jinja2 --with typing_extensions --with pyyaml python .github/scripts/generate_ci_workflows.py
git diff --stat   # only generated-linux-binary-manywheel-nightly.yml, 1 line
grep -rn '\.ci/manywheel' .github .ci   # empty
lintrunner .github/workflows/native-aot.yml .github/workflows/generated-linux-binary-manywheel-nightly.yml
```

Authored with an AI assistant.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@xuhancn
xuhancn deleted the xpu-manywheel-unified-takeover branch September 16, 2026 16:45
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/xpu Run XPU CI tasks Merged module: mkldnn Related to Intel IDEEP or oneDNN (a.k.a. mkldnn) integration open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

8 participants