Fix CI by using non-editable PyTorch installs#1490
Open
scotts wants to merge 4 commits into
Open
Conversation
Summary: The profiler CI job builds PyTorch from source, then runs test/profiler/. Collecting test_cpp_thread.py JIT-compiles a C++ extension and failed with: fatal error: torch/csrc/autograd/profiler_kineto.h: No such file or directory PyTorch migrated its build from setuptools to scikit-build-core (pytorch/pytorch#180247). Editable installs (pip install -e .) now use redirect mode: Python modules resolve from the source tree while the CMake-installed C++ headers under torch/include stay in the build tree. torch.utils.cpp_extension derives its header search path from the source tree's torch/include, which the editable install never populates, so no installed torch header is found. The failure is not specific to profiler_kineto.h; it is simply the first include in the test. Drop -e so PyTorch installs as a normal wheel, which stages torch/include into site-packages where cpp_extension finds it. CI builds once and never edits the tree, so editable mode bought us nothing here. Test Plan: Re-run linux-cpu-pytorch-build-and-test; test/profiler/ collection now compiles test_cpp_thread.cpp instead of failing on the missing header. Authored with assistance from an AI agent (Claude Code).
scotts
marked this pull request as ready for review
July 22, 2026 20:29
|
@scotts has imported this pull request. If you are a Meta employee, you can view this in D113305029. |
Summary: Installing PyTorch non-editable fixed the missing cpp_extension headers, but the profiler tests run from the PyTorch source checkout and python -m pytest prepends the current directory to sys.path. import torch then loaded the uncompiled source torch/ package instead of the wheel just installed, so every test errored at collection with: ImportError: Failed to load PyTorch C extensions Set PYTHONSAFEPATH=1 on the pytest invocation. On Python 3.11+ this stops the interpreter from prepending the current directory, so import torch resolves to the installed wheel, which has both the compiled _C extension and the headers. pytest still adds test/ and test/profiler/ to sys.path, neither of which shadows torch, and the deselect arguments keep working because the working directory is unchanged. This mirrors how PyTorch's own CI runs tests from the test/ directory rather than the repo root. Test Plan: Re-run linux-cpu-pytorch-build-and-test; test/profiler/ collection now imports torch from the installed wheel instead of failing to load the C extensions. Authored with assistance from an AI agent (Claude Code).
atalman
approved these changes
Jul 22, 2026
|
@scotts lets land pytorch/pytorch#190829 instead ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We started getting CI failures when building PyTorch from source and running the tests, https://github.com/pytorch/kineto/actions/runs/29939146658/job/89015057521?pr=1489:
PyTorch migrated its build from setuptools to scikit-build-core (pytorch/pytorch#180247). Up until now, our tests used editable install (
pip install -e) which now use redirect mode: Python modules resolve from the source tree while the CMake-installed C++ headers undertorch/includestay in the build tree.torch.utils.cpp_extensionderives its header search path from the source tree'storch/include, which the editable install never populates, so no installed torch header is found.We have two fixes:
-eto its a non-editable install. We shouldn't need those for tests.PYTHONSAFEPATH=1on the pytest invocation. On Python 3.11+ this stops the interpreter from prepending the current directory, so import torch resolves to the installed wheel, which has both the compiled_Cextension and the headers. This mirrors how PyTorch's own CI runs tests from thetest/directory rather than the repo root.Authored with assistance from an AI agent (Claude Code).