Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/180249
Note: Links to docs will display an error until the docs builds have been completed. ❌ 6 New Failures, 31 Unclassified FailuresAs of commit 06d1df4 with merge base 3043bfb ( NEW FAILURES - The following jobs have failed:
UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
Add compatibility patches to torch/__init__.py and _utils_internal.py so that editable installs (redirect mode) can locate CMake-built artifacts alongside source-tree Python files. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: 07bd4ef Pull-Request: pytorch#180249
Add compatibility patches to torch/__init__.py and _utils_internal.py so that editable installs (redirect mode) can locate CMake-built artifacts alongside source-tree Python files. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: 07bd4ef Pull-Request: pytorch#180249
Add compatibility patches to torch/__init__.py and _utils_internal.py so that editable installs (redirect mode) can locate CMake-built artifacts alongside source-tree Python files. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: 07bd4ef Pull-Request: pytorch#180249
| # rebuild-on-import here no longer re-runs cmake/ninja on every import. | ||
| mode = "redirect" | ||
| rebuild = false | ||
| rebuild = true |
There was a problem hiding this comment.
How widely adopted is this flag for users of scikit-build-core?
There was a problem hiding this comment.
@henryiii, could you shed some light on this?
There was a problem hiding this comment.
It's been problematic in the past. I think it's better now in the (unreleased) 1.0, though if you don't set a rebuild-dir (new setting in 1.0), then it's still on the package to ensure no absolute paths are referenced, those break because you need a reconfigure (which we don't provide), the dir gets moved after building it in editable installs.
(also new in 1.0 will be <pkg>.__loader__.rebuild(), manual rebuilds)
There was a problem hiding this comment.
Also, since mid last year I can't process all the pyproject.toml's on PyPI anymore, the project I was using was abandoned (site is now a spam site). So I can't track usage like I used to be able to.
There was a problem hiding this comment.
Ok, let's go with disabled by default for now and properly document how to enable this in our CONTRIBUTING.md
There was a problem hiding this comment.
Sounds good -- that's where the stack landed. As of the latest push, editable.rebuild = false is the default, so a plain editable install does no rebuild-on-import. I've documented how to opt in in CONTRIBUTING.md: SKBUILD_EDITABLE_REBUILD=true spin develop (or -C editable.rebuild=true with a raw pip install), plus the SKBUILD_EDITABLE_VERBOSE knob. Thanks both!
Add compatibility patches to torch/__init__.py and _utils_internal.py so that editable installs (redirect mode) can locate CMake-built artifacts alongside source-tree Python files. Rebuild-on-import stays off by default (`editable.rebuild = false` in #180247); the rebuild-once guard here only makes that path sane for developers who opt in (`SKBUILD_EDITABLE_REBUILD=true`). ## Rebuild-on-import log (opt-in `editable.rebuild = true`) When rebuild-on-import is opted in (`SKBUILD_EDITABLE_REBUILD=true`), the redirect finder runs `cmake --build & --install` on the first `import torch` in a process, so edits are picked up without an explicit reinstall. Captured on a CUDA box (scikit-build-core 0.12.x, CUDA 12.9). **Steady state (no source change):** a near no-op -- only version-file/compile-commands regen, no compilation. ``` $ SKBUILD_EDITABLE_VERBOSE=1 python -c "import torch; print(torch.__version__)" [0/2] Re-checking globbed directories... [1/3] Merging compile_commands.json... [2/3] Regenerating version file... -- Install configuration: "Release" Running cmake --build & --install in /path/to/pytorch/build 2.14.0a0+git2a4e636 ``` **After editing one source file (`c10/core/AllocatorConfig.cpp`):** the finder recompiles the changed TU and relinks the dependent libraries before import proceeds. ``` $ SKBUILD_EDITABLE_VERBOSE=1 python -c "import torch; print(torch.__version__)" [0/2] Re-checking globbed directories... [1/15] Building CXX object c10/CMakeFiles/c10.dir/core/AllocatorConfig.cpp.o [2/15] Merging compile_commands.json... [3/15] Linking CXX shared library lib/libc10.so [4/15] Regenerating version file... [5/15] Linking CXX shared library lib/libc10_cuda.so [6/15] Linking CXX shared library lib/libtorch_cpu.so [7/15] Linking CXX shared library lib/libshm.so [8/15] Linking CXX executable bin/torch_shm_manager [9/15] Linking CXX shared library lib/libtorch_cuda.so [10/15] Linking CXX shared library lib/libtorch.so [11/15] Linking CXX shared library lib/libtorch_cuda_linalg.so [12/15] Linking CXX shared library lib/libtorch_python.so [13/15] Linking C shared module torch/_C.cpython-310-x86_64-linux-gnu.so [14/15] Linking CXX shared library lib/libnnapi_backend.so -- Install configuration: "Release" -- Set non-toolchain portion of runtime path of ".../torch/lib/libc10.so" to "$ORIGIN" (... rpath fixups for each installed library ...) Running cmake --build & --install in /path/to/pytorch/build 2.14.0a0+git2a4e636 ``` (Linker `Unused direct dependencies` warnings elided for brevity.) ## Test plan - [x] **No-op for wheel installs**: the four redirect-mode shims (rebuild patch, `_load_global_deps` fallback, `__path__` extension, `_utils_internal` fallback) are guarded on the `ScikitBuildRedirectingFinder` meta-path type and on the source-tree paths being absent, so they short-circuit in non-editable installs. Confirmed by green wheel CI. - [ ] **Editable smoke test** (redirect mode): `pip install -e . -v --no-build-isolation` then `import torch` resolves native-lib + `torch._C` + `bin/`. With rebuild-on-import opted in (`SKBUILD_EDITABLE_REBUILD=true`), touching a cmake-generated file's source and re-importing triggers a single rebuild with no `pytest --capture=sys` stderr crash. Exercised by the macOS test job (`ciflow/mps`) or locally -- not part of default PR CI. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: 0e51d64 Pull-Request: #180249
Add compatibility patches to torch/__init__.py and _utils_internal.py so that editable installs (redirect mode) can locate CMake-built artifacts alongside source-tree Python files. Rebuild-on-import stays off by default (`editable.rebuild = false` in #180247); the rebuild-once guard here only makes that path sane for developers who opt in (`SKBUILD_EDITABLE_REBUILD=true`). ## Rebuild-on-import log (opt-in `editable.rebuild = true`) When rebuild-on-import is opted in (`SKBUILD_EDITABLE_REBUILD=true`), the redirect finder runs `cmake --build & --install` on the first `import torch` in a process, so edits are picked up without an explicit reinstall. Captured on a CUDA box (scikit-build-core 0.12.x, CUDA 12.9). **Steady state (no source change):** a near no-op -- only version-file/compile-commands regen, no compilation. ``` $ SKBUILD_EDITABLE_VERBOSE=1 python -c "import torch; print(torch.__version__)" [0/2] Re-checking globbed directories... [1/3] Merging compile_commands.json... [2/3] Regenerating version file... -- Install configuration: "Release" Running cmake --build & --install in /path/to/pytorch/build 2.14.0a0+git2a4e636 ``` **After editing one source file (`c10/core/AllocatorConfig.cpp`):** the finder recompiles the changed TU and relinks the dependent libraries before import proceeds. ``` $ SKBUILD_EDITABLE_VERBOSE=1 python -c "import torch; print(torch.__version__)" [0/2] Re-checking globbed directories... [1/15] Building CXX object c10/CMakeFiles/c10.dir/core/AllocatorConfig.cpp.o [2/15] Merging compile_commands.json... [3/15] Linking CXX shared library lib/libc10.so [4/15] Regenerating version file... [5/15] Linking CXX shared library lib/libc10_cuda.so [6/15] Linking CXX shared library lib/libtorch_cpu.so [7/15] Linking CXX shared library lib/libshm.so [8/15] Linking CXX executable bin/torch_shm_manager [9/15] Linking CXX shared library lib/libtorch_cuda.so [10/15] Linking CXX shared library lib/libtorch.so [11/15] Linking CXX shared library lib/libtorch_cuda_linalg.so [12/15] Linking CXX shared library lib/libtorch_python.so [13/15] Linking C shared module torch/_C.cpython-310-x86_64-linux-gnu.so [14/15] Linking CXX shared library lib/libnnapi_backend.so -- Install configuration: "Release" -- Set non-toolchain portion of runtime path of ".../torch/lib/libc10.so" to "$ORIGIN" (... rpath fixups for each installed library ...) Running cmake --build & --install in /path/to/pytorch/build 2.14.0a0+git2a4e636 ``` (Linker `Unused direct dependencies` warnings elided for brevity.) ## Test plan - [x] **No-op for wheel installs**: the four redirect-mode shims (rebuild patch, `_load_global_deps` fallback, `__path__` extension, `_utils_internal` fallback) are guarded on the `ScikitBuildRedirectingFinder` meta-path type and on the source-tree paths being absent, so they short-circuit in non-editable installs. Confirmed by green wheel CI. - [ ] **Editable smoke test** (redirect mode): `pip install -e . -v --no-build-isolation` then `import torch` resolves native-lib + `torch._C` + `bin/`. With rebuild-on-import opted in (`SKBUILD_EDITABLE_REBUILD=true`), touching a cmake-generated file's source and re-importing triggers a single rebuild with no `pytest --capture=sys` stderr crash. Exercised by the macOS test job (`ciflow/mps`) or locally -- not part of default PR CI. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: 9340421 Pull-Request: #180249
scikit-build-core's editable install can optionally rebuild the project on the first `import torch` in a process, so source edits are picked up without an explicit reinstall. It is off by default (`editable.rebuild = false`, set in #180247); developers opt in with `SKBUILD_EDITABLE_REBUILD=true`. `_patch_skbuild_editable_rebuild()` makes that opt-in path usable. It wraps the `ScikitBuildRedirectingFinder`'s `rebuild()` to: (1) restore the real stderr so a `pytest --capture=sys` run does not crash the `subprocess.run(stdout=sys.stderr)` call; (2) propagate `SKBUILD_EDITABLE_SKIP` into the current process so subsequent wheel-file imports do not each trigger a fresh rebuild cascade; and (3) alias `MAX_JOBS` to `CMAKE_BUILD_PARALLEL_LEVEL` so the import-time rebuild honors PyTorch's build-parallelism knob. The editable artifact-location shims that make a plain (non-rebuilding) editable install importable live in the base migration commit (#180247); this commit only adds the opt-in rebuild-on-import convenience on top. ## Rebuild-on-import log (opt-in `editable.rebuild = true`) When rebuild-on-import is opted in (`SKBUILD_EDITABLE_REBUILD=true`), the redirect finder runs `cmake --build & --install` on the first `import torch` in a process, so edits are picked up without an explicit reinstall. Captured on a CUDA box (scikit-build-core 0.12.x, CUDA 12.9). **Steady state (no source change):** a near no-op -- only version-file/compile-commands regen, no compilation. ``` $ SKBUILD_EDITABLE_VERBOSE=1 python -c "import torch; print(torch.__version__)" [0/2] Re-checking globbed directories... [1/3] Merging compile_commands.json... [2/3] Regenerating version file... -- Install configuration: "Release" Running cmake --build & --install in /path/to/pytorch/build 2.14.0a0+git2a4e636 ``` **After editing one source file (`c10/core/AllocatorConfig.cpp`):** the finder recompiles the changed TU and relinks the dependent libraries before import proceeds. ``` $ SKBUILD_EDITABLE_VERBOSE=1 python -c "import torch; print(torch.__version__)" [0/2] Re-checking globbed directories... [1/15] Building CXX object c10/CMakeFiles/c10.dir/core/AllocatorConfig.cpp.o [2/15] Merging compile_commands.json... [3/15] Linking CXX shared library lib/libc10.so [4/15] Regenerating version file... [5/15] Linking CXX shared library lib/libc10_cuda.so [6/15] Linking CXX shared library lib/libtorch_cpu.so [7/15] Linking CXX shared library lib/libshm.so [8/15] Linking CXX executable bin/torch_shm_manager [9/15] Linking CXX shared library lib/libtorch_cuda.so [10/15] Linking CXX shared library lib/libtorch.so [11/15] Linking CXX shared library lib/libtorch_cuda_linalg.so [12/15] Linking CXX shared library lib/libtorch_python.so [13/15] Linking C shared module torch/_C.cpython-310-x86_64-linux-gnu.so [14/15] Linking CXX shared library lib/libnnapi_backend.so -- Install configuration: "Release" -- Set non-toolchain portion of runtime path of ".../torch/lib/libc10.so" to "$ORIGIN" (... rpath fixups for each installed library ...) Running cmake --build & --install in /path/to/pytorch/build 2.14.0a0+git2a4e636 ``` (Linker `Unused direct dependencies` warnings elided for brevity.) ## Test plan - [x] **No-op unless opted in**: `_patch_skbuild_editable_rebuild()` only acts when a `ScikitBuildRedirectingFinder` is on `sys.meta_path` (an editable install) that exposes a `rebuild`; a wheel install or a non-rebuild editable install is unaffected. Confirmed by green wheel CI. - [ ] **Editable rebuild smoke test** (opt-in): install with `SKBUILD_EDITABLE_REBUILD=true`, then edit a cmake-generated file's source and re-import `torch` -- exactly one rebuild runs, with no `pytest --capture=sys` stderr crash. Exercised locally / by the macOS job (`ciflow/mps`); not part of default PR CI. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: dc7c2c1 Pull-Request: #180249
|
With scikit-build-core-1.0.0 this is now obsolete, so closing in favor of the single migration in #180247. |
Stack from ghstack (oldest at bottom):
scikit-build-core's editable install can optionally rebuild the project
on the first
import torchin a process, so source edits are picked upwithout an explicit reinstall. It is off by default (
editable.rebuild = false, set in #180247); developers opt in withSKBUILD_EDITABLE_REBUILD=true._patch_skbuild_editable_rebuild()makes that opt-in path usable. Itwraps the
ScikitBuildRedirectingFinder'srebuild()to: (1) restorethe real stderr so a
pytest --capture=sysrun does not crash thesubprocess.run(stdout=sys.stderr)call; (2) propagateSKBUILD_EDITABLE_SKIPinto the current process so subsequent wheel-fileimports do not each trigger a fresh rebuild cascade; and (3) alias
MAX_JOBStoCMAKE_BUILD_PARALLEL_LEVELso the import-time rebuildhonors PyTorch's build-parallelism knob.
The editable artifact-location shims that make a plain (non-rebuilding)
editable install importable live in the base migration commit (#180247);
this commit only adds the opt-in rebuild-on-import convenience on top.
Rebuild-on-import log (opt-in
editable.rebuild = true)When rebuild-on-import is opted in (
SKBUILD_EDITABLE_REBUILD=true), theredirect finder runs
cmake --build & --installon the firstimport torchin a process, so edits are picked up without an explicitreinstall. Captured on a CUDA box (scikit-build-core 0.12.x, CUDA 12.9).
Steady state (no source change): a near no-op -- only
version-file/compile-commands regen, no compilation.
After editing one source file (
c10/core/AllocatorConfig.cpp): thefinder recompiles the changed TU and relinks the dependent libraries
before import proceeds.
(Linker
Unused direct dependencieswarnings elided for brevity.)Test plan
_patch_skbuild_editable_rebuild()onlyacts when a
ScikitBuildRedirectingFinderis onsys.meta_path(aneditable install) that exposes a
rebuild; a wheel install or anon-rebuild editable install is unaffected. Confirmed by green wheel CI.
SKBUILD_EDITABLE_REBUILD=true, then edit a cmake-generated file'ssource and re-import
torch-- exactly one rebuild runs, with nopytest --capture=sysstderr crash. Exercised locally / by the macOSjob (
ciflow/mps); not part of default PR CI.Co-Generated with Claude Code