Skip to content

Build PyTorch wheel via PEP 517 without poisoning the CI image - #21685

Open
shoumikhin wants to merge 3 commits into
mainfrom
reland-21562-pep517-venv
Open

Build PyTorch wheel via PEP 517 without poisoning the CI image#21685
shoumikhin wants to merge 3 commits into
mainfrom
reland-21562-pep517-venv

Conversation

@shoumikhin

@shoumikhin shoumikhin commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Forward fix for #21562.

#21562 moved the PyTorch wheel build from setup.py bdist_wheel to python -m build --wheel --no-isolation. That direction is correct and is kept here. The problem was that it installed the PEP 517 build requirements permanently into the image's conda environment, and two different things in that install changed how every later build in the image behaves. Both broke main.

1. All 17 RISC-V jobs failed

scikit-build-core ships a setuptools plugin that registers itself as the build_ext command class. Once it is present in the environment, any later pip install --no-build-isolation picks it up. The tokenizers build is exactly that, so its CMake configure started running through scikit-build-core, which turns on C++20 module dependency scanning. The image compiler cannot produce the scan output:

[299/312] Generating CXX dyndep file CMakeFiles/pytorch_tokenizers_cpp.dir/CXX.dd
FAILED: CMakeFiles/pytorch_tokenizers_cpp.dir/src/python_bindings.cpp.o
cc1plus: error: to generate dependencies you must specify either '-M' or '-MM'

2. The wheel was built without LAPACK

The same install also put a pip cmake wheel into the environment, which lands on PATH ahead of the image's own cmake. The two are the same version but not interchangeable: the pip wheel does not search the conda environment, so FindMKL stopped finding the MKL libraries that are installed there and PyTorch was configured with MKL and LAPACK off. 12 tests in extension/llm/modules/test/test_turboquant_kv_cache.py then failed with:

RuntimeError: Calling torch.geqrf on a CPU tensor requires compiling PyTorch with LAPACK.

Fix

Install the build requirements into a throwaway venv instead of into the image, and invoke the build through that venv's interpreter by absolute path. The venv is created with --system-site-packages, so PyTorch still builds against the image's numpy and toolchain and still reuses sccache. The venv is deleted once the wheel is built, so neither the scikit-build-core plugin nor the pip cmake survives into the image, and the image's own cmake stays in front.

Evidence

From the docker image build log, PyTorch's configure summary:

#21562, as merged this PR
cmake actually used .../site-packages/cmake/data/bin/cmake /opt/conda/envs/py_3.10/bin/cmake
USE_MKL OFF ON
USE_LAPACK 0 1

CI on this PR:

  • test-riscv: 17 of 17 green. On main it is 17 of 17 red.
  • test-lora-multimethod-linux: green. On main it is red.

Note on the jobs that did not finish

unittest / linux, unittest-editable / linux and test-lora-linux were all cancelled at 1 hour 31 minutes, which is the 90 minute job cap. Any PR that touches .ci/docker/ forces a full image rebuild that consumes roughly 30 minutes of that budget, so these three cannot complete on a PR of this shape. That is also why the LAPACK problem was not visible on #21562 before it merged. The USE_LAPACK line in the image build log above is the direct evidence for that half of the fix, since it is read at configure time rather than at test time.

Relationship to the revert

This branch contains two commits, a revert of #21562 followed by the corrected version. The net diff against main is a single file, .ci/docker/common/install_pytorch.sh, and squash merge collapses them into one commit.

This supersedes #21684, which is a straight revert of #21562. If this lands, #21684 should be closed without merging. Do not merge #21684 after this one, since it would restore the previous file wholesale and undo this fix.

This reverts the install_pytorch.sh change from #21562. It broke test-riscv on main, 17 of 17 jobs, on every commit since it landed.

The PEP 517 change itself is correct. The problem is that the PR installs the PEP 517 build requirements permanently into the image conda environment. scikit-build-core registers a setuptools build_ext plugin, so every later "pip install --no-build-isolation" in that image runs its cmake configure instead of the plain setuptools one. That turns on C++20 module dependency scanning, which the image GCC 14.2.0 cannot satisfy, and the tokenizers build fails with "cc1plus: error: to generate dependencies you must specify either -M or -MM".

Reverting to unblock main. Re-landing separately with the build requirements confined to a throwaway virtualenv.
…ay venv

Re-land of #21562 with the leak fixed. The PEP 517 build requirements now go into a temporary virtualenv instead of the image conda environment, so scikit-build-core stops hijacking every later setuptools build in the image.
Copilot AI lite review requested due to automatic review settings August 8, 2026 00:08
@pytorch-bot

pytorch-bot Bot commented Aug 8, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⏳ No Failures, 28 Pending

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

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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@shoumikhin shoumikhin added ciflow/trunk release notes: none Do not include this in the release notes labels Aug 8, 2026
@shoumikhin shoumikhin changed the title Build PyTorch wheel via PEP 517, with build requirements in a throwaway venv Build PyTorch wheel via PEP 517 without poisoning the CI image Aug 8, 2026
@shoumikhin

Copy link
Copy Markdown
Contributor Author

Updated this PR to be a complete forward fix for #21562, not only the RISC-V half.

#21562 had two separate effects, and both came from installing the PEP 517 build requirements into the image's conda environment:

  1. The scikit-build-core setuptools plugin hijacked the tokenizers build. That is the 17 RISC-V failures.
  2. A pip cmake wheel shadowed the image's own cmake, so MKL was no longer found and the wheel was configured with LAPACK off. That is the 12 turboquant failures on torch.geqrf.

Moving the build requirements into a throwaway venv fixes both. The image build log shows USE_LAPACK : 0 on main and USE_LAPACK : 1 here, and test-riscv is 17 of 17 green here against 17 of 17 red on main. Full evidence is in the description above.

This replaces #21684, which is a plain revert. Main has been red for about three hours, so a review here would be very welcome.

@shoumikhin

Copy link
Copy Markdown
Contributor Author

Verification is complete. unittest / linux was re-run on this PR with the image already cached, so it finished instead of hitting the 90 minute cap.

main this PR
unittest / linux 12 failed, 1957 passed, 83 skipped 1969 passed, 83 skipped
tests executed 1969 1969
mentions of geqrf in the log 20 0

Same number of tests executed and the same number skipped, so nothing was skipped away. The 12 that failed on main now run and pass. That covers both the 10 LAPACK failures in test_turboquant_kv_cache.py and the 2 numerical failures in test_quantized_sdpa.py and test_sdpa_with_kv_cache.py, which came from losing MKL.

unittest-release / linux is also green.

Full status against the 23 checks that #21562 broke:

  • test-riscv: 17 of 17 green
  • unittest / linux: green
  • unittest-release / linux: green
  • unittest-nxp-neutron: green
  • test-lora-multimethod-linux: green
  • unittest-editable / linux and test-lora-linux: not re-run, they still show cancelled from the first attempt at the 90 minute cap. They run the same suites as the two green jobs above.

This is ready. It needs one approving review and nothing else.

Copilot AI review requested due to automatic review settings August 8, 2026 05:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/cuda ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants