Skip to content

Fix CI by using non-editable PyTorch installs#1490

Open
scotts wants to merge 4 commits into
pytorch:mainfrom
scotts:test_ci_2026_07_22
Open

Fix CI by using non-editable PyTorch installs#1490
scotts wants to merge 4 commits into
pytorch:mainfrom
scotts:test_ci_2026_07_22

Conversation

@scotts

@scotts scotts commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

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:

FAILED: [code=1] test_cpp_thread.o 
sccache c++ -MMD -MF test_cpp_thread.o.d -DTORCH_EXTENSION_NAME=profiler_test_cpp_thread_lib -DTORCH_API_INCLUDE_EXTENSION_H -isystem /pytorch/pytorch/torch/include -isystem /pytorch/pytorch/torch/include/torch/csrc/api/include -isystem /opt/conda/include/python3.11 -fPIC -std=c++20 -c /pytorch/pytorch/test/profiler/test_cpp_thread.cpp -o test_cpp_thread.o 
/pytorch/pytorch/test/profiler/test_cpp_thread.cpp:2:10: fatal error: torch/csrc/autograd/profiler_kineto.h: No such file or directory
    2 | #include <torch/csrc/autograd/profiler_kineto.h>  // @manual
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

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 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.

We have two fixes:

  1. Drop the -e to its a non-editable install. We shouldn't need those for tests.
  2. 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. This mirrors how PyTorch's own CI runs tests from the test/ directory rather than the repo root.

Authored with assistance from an AI agent (Claude Code).

@meta-cla meta-cla Bot added the cla signed label Jul 22, 2026
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 scotts changed the title Test CI Fix CI by using non-editable PyTorch installs Jul 22, 2026
@scotts
scotts marked this pull request as ready for review July 22, 2026 20:29
@meta-codesync

meta-codesync Bot commented Jul 22, 2026

Copy link
Copy Markdown

@scotts has imported this pull request. If you are a Meta employee, you can view this in D113305029.

scotts added 2 commits July 22, 2026 13:48
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

atalman commented Jul 22, 2026

Copy link
Copy Markdown

@scotts lets land pytorch/pytorch#190829 instead ?

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.

2 participants