Skip to content

Fix cpp_extension header/library paths for editable installs - #190829

Closed
scotts wants to merge 1 commit into
pytorch:mainfrom
scotts:fix-cpp-extension-editable-torch-path
Closed

scotts wants to merge 1 commit into
pytorch:mainfrom
scotts:fix-cpp-extension-editable-torch-path

Conversation

@scotts

@scotts scotts commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Problem

Building a C++ or CUDA extension against a PyTorch installed in editable mode (pip install -e .) fails to find any installed torch header. The compile aborts on the first include, e.g.:

  fatal error: torch/csrc/autograd/profiler_kineto.h: No such file or directory

The recent migration to scikit-build-core changed editable installs so that compiled artifacts (the installed headers, libraries, and binaries) live in the installed package directory instead of the source tree. The C++ extension helper still looked for them under the source tree, which an editable install never populates, so extension builds lose their header and library search paths. Regular wheel installs are unaffected because their package directory and their import location are the same.

Fix

The scikit-build-core migration (#180247) already added _compute_torch_parent so get_file_path resolves to the installed package directory for editable installs, but torch.utils.cpp_extension still computed its own root from dirname(dirname(__file__)). Resolve _TORCH_PATH with get_file_path("torch") instead, so cpp_extension reuses that same editable-aware logic. _TORCH_PATH feeds every include, library, precompiled-header, and hipify path in the module, so this single change fixes all of them; non-editable installs resolve exactly as before.

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

**Problem**

Building a C++ or CUDA extension against a PyTorch installed in editable
mode (pip install -e .) fails to find any installed torch header. The
compile aborts on the first include, e.g.:

  fatal error: torch/csrc/autograd/profiler_kineto.h: No such file or directory

The recent migration to scikit-build-core changed editable installs so that
compiled artifacts -- the installed headers, libraries, and binaries -- live
in the installed package directory instead of the source tree. The C++
extension helper still looked for them under the source tree, which an
editable install never populates, so extension builds lose their header and
library search paths. Regular wheel installs are unaffected because their
package directory and their import location are the same.

**Fix**

The scikit-build-core migration (pytorch#180247) already added _compute_torch_parent
so get_file_path resolves to the installed package directory for editable
installs, but torch.utils.cpp_extension still computed its own root from
dirname(dirname(__file__)). Resolve _TORCH_PATH with get_file_path("torch")
instead, so cpp_extension reuses that same editable-aware logic. _TORCH_PATH
feeds every include, library, precompiled-header, and hipify path in the
module, so this single change fixes all of them; non-editable installs
resolve exactly as before.

**Test Plan**

Verified torch/utils/cpp_extension.py compiles (python -m py_compile). The
runtime path was not exercised here (no torch build in this environment);
validate against a fresh editable install with:

```
pip install --no-build-isolation -e .
python -c "import os, torch.utils.cpp_extension as e; print(os.path.exists(os.path.join(e._TORCH_PATH, 'include', 'torch', 'csrc', 'autograd', 'profiler_kineto.h')))"
# expect: True
python -m pytest test/profiler/test_cpp_thread.py
```

Authored with assistance from an AI agent (Claude Code).
@pytorch-bot

pytorch-bot Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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 b96a5b9 with merge base 0dff903 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@scotts scotts added the topic: not user facing topic category label Jul 22, 2026
@atalman
atalman marked this pull request as ready for review July 22, 2026 21:43
@atalman
atalman requested review from ezyang, fmassa and malfet as code owners July 22, 2026 21:43

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

Thanks!

@atalman

atalman commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

@pytorchmergebot merge -i

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 23, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 0 checks:

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

youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
…#190829)

**Problem**

Building a C++ or CUDA extension against a PyTorch installed in editable mode (`pip install -e .`) fails to find any installed torch header. The compile aborts on the first include, e.g.:
```
  fatal error: torch/csrc/autograd/profiler_kineto.h: No such file or directory
```
The recent migration to scikit-build-core changed editable installs so that compiled artifacts (the installed headers, libraries, and binaries) live in the installed package directory instead of the source tree. The C++ extension helper still looked for them under the source tree, which an editable install never populates, so extension builds lose their header and library search paths. Regular wheel installs are unaffected because their package directory and their import location are the same.

**Fix**

The scikit-build-core migration (pytorch#180247) already added `_compute_torch_parent` so `get_file_path` resolves to the installed package directory for editable installs, but `torch.utils.cpp_extension` still computed its own root from `dirname(dirname(__file__))`. Resolve `_TORCH_PATH` with `get_file_path("torch")` instead, so `cpp_extension` reuses that same editable-aware logic. `_TORCH_PATH` feeds every include, library, precompiled-header, and hipify path in the module, so this single change fixes all of them; non-editable installs resolve exactly as before.

Authored with assistance from an AI agent (Claude Code).
Pull Request resolved: pytorch#190829
Approved by: https://github.com/atalman, https://github.com/albanD
youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
…#190829)

**Problem**

Building a C++ or CUDA extension against a PyTorch installed in editable mode (`pip install -e .`) fails to find any installed torch header. The compile aborts on the first include, e.g.:
```
  fatal error: torch/csrc/autograd/profiler_kineto.h: No such file or directory
```
The recent migration to scikit-build-core changed editable installs so that compiled artifacts (the installed headers, libraries, and binaries) live in the installed package directory instead of the source tree. The C++ extension helper still looked for them under the source tree, which an editable install never populates, so extension builds lose their header and library search paths. Regular wheel installs are unaffected because their package directory and their import location are the same.

**Fix**

The scikit-build-core migration (pytorch#180247) already added `_compute_torch_parent` so `get_file_path` resolves to the installed package directory for editable installs, but `torch.utils.cpp_extension` still computed its own root from `dirname(dirname(__file__))`. Resolve `_TORCH_PATH` with `get_file_path("torch")` instead, so `cpp_extension` reuses that same editable-aware logic. `_TORCH_PATH` feeds every include, library, precompiled-header, and hipify path in the module, so this single change fixes all of them; non-editable installs resolve exactly as before.

Authored with assistance from an AI agent (Claude Code).
Pull Request resolved: pytorch#190829
Approved by: https://github.com/atalman, https://github.com/albanD
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…#190829)

**Problem**

Building a C++ or CUDA extension against a PyTorch installed in editable mode (`pip install -e .`) fails to find any installed torch header. The compile aborts on the first include, e.g.:
```
  fatal error: torch/csrc/autograd/profiler_kineto.h: No such file or directory
```
The recent migration to scikit-build-core changed editable installs so that compiled artifacts (the installed headers, libraries, and binaries) live in the installed package directory instead of the source tree. The C++ extension helper still looked for them under the source tree, which an editable install never populates, so extension builds lose their header and library search paths. Regular wheel installs are unaffected because their package directory and their import location are the same.

**Fix**

The scikit-build-core migration (pytorch#180247) already added `_compute_torch_parent` so `get_file_path` resolves to the installed package directory for editable installs, but `torch.utils.cpp_extension` still computed its own root from `dirname(dirname(__file__))`. Resolve `_TORCH_PATH` with `get_file_path("torch")` instead, so `cpp_extension` reuses that same editable-aware logic. `_TORCH_PATH` feeds every include, library, precompiled-header, and hipify path in the module, so this single change fixes all of them; non-editable installs resolve exactly as before.

Authored with assistance from an AI agent (Claude Code).
Pull Request resolved: pytorch#190829
Approved by: https://github.com/atalman, https://github.com/albanD
MelindaTan pushed a commit to MelindaTan/pytorch that referenced this pull request Jul 31, 2026
…#190829)

**Problem**

Building a C++ or CUDA extension against a PyTorch installed in editable mode (`pip install -e .`) fails to find any installed torch header. The compile aborts on the first include, e.g.:
```
  fatal error: torch/csrc/autograd/profiler_kineto.h: No such file or directory
```
The recent migration to scikit-build-core changed editable installs so that compiled artifacts (the installed headers, libraries, and binaries) live in the installed package directory instead of the source tree. The C++ extension helper still looked for them under the source tree, which an editable install never populates, so extension builds lose their header and library search paths. Regular wheel installs are unaffected because their package directory and their import location are the same.

**Fix**

The scikit-build-core migration (pytorch#180247) already added `_compute_torch_parent` so `get_file_path` resolves to the installed package directory for editable installs, but `torch.utils.cpp_extension` still computed its own root from `dirname(dirname(__file__))`. Resolve `_TORCH_PATH` with `get_file_path("torch")` instead, so `cpp_extension` reuses that same editable-aware logic. `_TORCH_PATH` feeds every include, library, precompiled-header, and hipify path in the module, so this single change fixes all of them; non-editable installs resolve exactly as before.

Authored with assistance from an AI agent (Claude Code).
Pull Request resolved: pytorch#190829
Approved by: https://github.com/atalman, https://github.com/albanD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants