Repository navigation
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:
Findings (1): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/204789
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit c0f6a45 with merge base afdb716 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| os.path.dirname(torch.__file__), | ||
| "include", | ||
| extend_aoti_c_shim_include, | ||
| get_file_path("torch"), "include", extend_aoti_c_shim_include |
There was a problem hiding this comment.
Slight nit but we should add an overload that lets you take in the module symbol to reduce import overhead. Like if torch is already imported just pass the torch module object.
There was a problem hiding this comment.
Thanks for taking a look!
Which overhead do you have in mind? get_file_path does not look anything up by name: it is os.path.join(torch_parent, *path_components), with torch_parent computed once during import torch. The "torch" here is a path component, not a module name, so no import or spec lookup happens per call, and torch._utils_internal is already loaded by import torch.
Given that, I would rather not add a module overload in this PR. It would not save anything, and the function is replaced by an internal implementation at Meta, so a signature change needs to be coordinated on both sides. If you see value in a module-accepting form for other reasons, I am happy to take that up separately.
There was a problem hiding this comment.
Automated review of e46f733: nothing blocking; ready for human review.
The PR routes three inductor lookups of installed assets (bin/ptxas, the extended c_shim header, the vec-ISA lib dir) and two tests through torch._utils_internal.get_file_path("torch") instead of file, so they resolve correctly under redirect-mode editable installs. Recommendation: Approve; only one non-blocking test point remains.
⚪ 1 non-blocking finding
pytorch/test/inductor/test_codecache.py
Line 6183 in e46f733
Non-blocking: circular check. test_build_probe_env_prepends_torch_lib_dir_to_loader_path builds its expected value with os.path.join(get_file_path("torch"), "lib"), the same expression VecISA._build_probe_env uses at torch/_inductor/cpu_vec_isa.py:139. If torch_parent ever resolved into the source checkout again under a redirect-mode editable install, both sides would move together and the test would still pass. The PR description criticises the old file-based version for exactly this. Suggested fix: derive the expectation independently, e.g. c_file = getattr(torch._C, "file", None) (skip when None), then compare os.path.realpath(value.split(os.pathsep)[0]) with os.path.realpath(os.path.join(os.path.dirname(c_file), "lib")). On a redirect install torch._C resolves to the installed tree, so its file does not depend on the loader.paths logic in _installed_torch_dir. Alternatively assert the first entry contains libc10.so, but that is Linux-only and would need a Linux-only skip.
This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review
|
@pytorchbot merge -r |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
## Linked issue or supporting maintainer Part of pytorch#195889 ## BC-breaking? No ## Summary (human written only) This PR replaces resource lookups in inductor and inductor tests that are based on the legacy `__file__` mechanism with the modern importlib based lookup via `torch._utils_internal.get_file_path`. This is necessary to make things work with editable installs in redirect mode that came in with our move to scikit-build-core. ## Agent details (if applicable) Under a redirect-mode editable install, `torch.__file__` points into the source checkout while `bin/`, `include/` and `lib/` are installed beside the compiled extension. Three inductor lookups derived those directories from `__file__` and so pointed into the checkout: - `runtime/compile_tasks.py`: the bundled `bin/ptxas` was not found, so `TRITON_PTXAS_PATH` stayed unset and Triton fell back to its own ptxas. - `codegen/cpp_wrapper_cpu.py`: an out-of-tree backend's extended `c_shim_<device>.h` was not found and silently not included. - `cpu_vec_isa.py`: the `lib` directory prepended to `LD_LIBRARY_PATH` for the vec-ISA probe did not exist, so the probe always took the slower `import torch` retry. All three now start from `torch._utils_internal.get_file_path("torch")`, which is anchored on the import system (pytorch#195587). Two tests in `test_codecache.py` that pinned the old `lib` path move with it. `get_file_path` is called with the single component `"torch"` and the rest is joined with `os.path`, the form `torch/utils/cpp_extension.py` and `codegen/mps.py` already use. Two of the three files looked up are optional, and a build system that replaces `get_file_path` may raise for a resource it does not ship (see `_resolve_cmake_prefix_path` in `torch/utils/__init__.py`); the single-component form keeps the existing `exists()` checks in charge of that case. The alternative was the multi-component form wrapped in `try/except` at each site. The fourth site named in the issue, the `include` lookup through `_TORCH_PATH` in `cpp_builder.py`, is not changed. It is only used by `build_fbcode_re`, the remote-build path, which an editable install does not reach, and `_TORCH_PATH` also feeds the linker script path and the code hash, where the source tree is the right answer. Tracked in pytorch#195887. ### Test Plan Applied on top of an editable install on Linux x86_64, Python 3.12, CPU-only, in a checkout with no leftovers of earlier in-tree builds (no libraries in `torch/lib`). The changes are pure Python, so no rebuild was needed. ``` cd test python -m pytest inductor/test_codecache.py -q -rs -k TestVecISACheckBuild python -m pytest inductor/test_aot_inductor.py -q -k "AOTInductorTestABICompatibleCpu and (test_simple or test_add)" ``` `TestVecISACheckBuild` before the change: 3 passed, 1 skipped ("libc10.so not found in torch lib dir"), and the first `LD_LIBRARY_PATH` entry of `VecISA._build_probe_env()` is `torch/lib` in the checkout, which holds no libraries. `test_build_probe_env_prepends_torch_lib_dir_to_loader_path` passes there only because it asserted the same `__file__`-derived path as the code. After the change: 4 passed, and the entry is `torch/lib` of the install tree. AOT inductor selection after the change: 8 passed. A `torch.compile` call with `cpp_wrapper=True` runs. Not exercised: the ptxas lookup (needs a CUDA build with `BUILD_BUNDLE_PTXAS=1`) and the extended shim header (needs an out-of-tree backend). ``` lintrunner -a --take PYFMT,RUFF,FLAKE8 test/inductor/test_codecache.py torch/_inductor/codegen/cpp_wrapper_cpu.py torch/_inductor/cpu_vec_isa.py torch/_inductor/runtime/compile_tasks.py ``` Authored with the help of an AI assistant (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
|
Successfully rebased |
e46f733 to
c0f6a45
Compare
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: Could not find commit that was pushed before comment 7317403769 Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Linked issue or supporting maintainer
Part of #195889
BC-breaking?
No
Summary (human written only)
This PR replaces resource lookups in inductor and inductor tests that are based on the legacy
__file__mechanism with the modern importlib based lookup viatorch._utils_internal.get_file_path. This is necessary to make things work with editable installs in redirect mode that came in with our move to scikit-build-core.Agent details (if applicable)
Under a redirect-mode editable install,
torch.__file__points into the source checkout whilebin/,include/andlib/are installed beside the compiled extension. Three inductor lookups derived those directories from__file__and so pointed into the checkout:runtime/compile_tasks.py: the bundledbin/ptxaswas not found, soTRITON_PTXAS_PATHstayed unset and Triton fell back to its own ptxas.codegen/cpp_wrapper_cpu.py: an out-of-tree backend's extendedc_shim_<device>.hwas not found and silently not included.cpu_vec_isa.py: thelibdirectory prepended toLD_LIBRARY_PATHfor the vec-ISA probe did not exist, so the probe always took the slowerimport torchretry.All three now start from
torch._utils_internal.get_file_path("torch"), which is anchored on the import system (#195587). Two tests intest_codecache.pythat pinned the oldlibpath move with it.get_file_pathis called with the single component"torch"and the rest is joined withos.path, the formtorch/utils/cpp_extension.pyandcodegen/mps.pyalready use. Two of the three files looked up are optional, and a build system that replacesget_file_pathmay raise for a resource it does not ship (see_resolve_cmake_prefix_pathintorch/utils/__init__.py); the single-component form keeps the existingexists()checks in charge of that case. The alternative was the multi-component form wrapped intry/exceptat each site.The fourth site named in the issue, the
includelookup through_TORCH_PATHincpp_builder.py, is not changed. It is only used bybuild_fbcode_re, the remote-build path, which an editable install does not reach, and_TORCH_PATHalso feeds the linker script path and the code hash, where the source tree is the right answer.Tracked in #195887.
Test Plan
Applied on top of an editable install on Linux x86_64, Python 3.12, CPU-only, in a checkout with no leftovers of earlier in-tree builds (no libraries in
torch/lib). The changes are pure Python, so no rebuild was needed.TestVecISACheckBuildbefore the change: 3 passed, 1 skipped ("libc10.so not found in torch lib dir"), and the firstLD_LIBRARY_PATHentry ofVecISA._build_probe_env()istorch/libin the checkout, which holds no libraries.test_build_probe_env_prepends_torch_lib_dir_to_loader_pathpasses there only because it asserted the same__file__-derived path as the code. After the change: 4 passed, and the entry istorch/libof the install tree.AOT inductor selection after the change: 8 passed. A
torch.compilecall withcpp_wrapper=Trueruns.Not exercised: the ptxas lookup (needs a CUDA build with
BUILD_BUNDLE_PTXAS=1) and the extended shim header (needs an out-of-tree backend).Authored with the help of an AI assistant (Claude Code).
🤖 Generated with Claude Code
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo