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 (2): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/204804
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit b68854f with merge base afdb716 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Automated review of 27e0db0: nothing blocking; ready for human review.
The PR changes NvshmemLibFinder.find_device_library to find torch's lib/libtorch_nvshmem.so with torch._utils_internal.get_file_path("torch") instead of os.path.dirname(torch.file), so the RPATH search step also runs under a redirect-mode editable install. Recommendation: Approve. Nothing blocks the change, and the two points raised are optional, non-blocking cleanups.
⚪ 2 non-blocking findings
Non-blocking: the function-local from torch._utils_internal import get_file_path is wrapped in try: ... except ImportError: pass (lines 65-66, 90-91), but that import cannot fail here. torch/__init__.py:69-75 imports get_file_path from torch._utils_internal at module level, and this module's own import torch.distributed (line 7) loads it too, through distributed_c10d.py:75. The old import torch was dead code in the same way, so the PR did not introduce this. But the PR rewrites that exact line, so this is a cheap moment to clean it up. Move the import to the top of the module, as distributed_c10d.py and launcher/api.py do. There is no circular-import reason to keep it local, and moving it also removes an outer try that exists only to wrap the inner one.
Non-blocking: two other places that switched to get_file_path for the same editable-install reason carry a short comment explaining why __file__ is wrong: torch/__init__.py:421-422 and torch/utils/cpp_extension.py:44-48. Add a similar one-line comment here. Without it, a later cleanup could easily "simplify" this back to os.path.dirname(torch.__file__) and quietly bring the bug back.
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 Fixes pytorch#195890 ## BC-breaking? No ## Summary (human written only) This PR replaces the legacy `__file__` based lookup of the RPATH source `libtorch_nvshmem.so` with a modern importlib based version via our `get_file_path` helper, which is necessary for editable installs in redirect mode. ## Agent details (if applicable) `NvshmemLibFinder.find_device_library` builds a list of directories to search for the NVSHMEM device library. Its last step reads the RPATH of torch's own `libtorch_nvshmem.so` and adds those directories, which is how an NVSHMEM that lives outside site-packages and the system directories is found. It located that library through `os.path.dirname(torch.__file__)`. Under a redirect-mode editable install that is the source checkout, where there is no `lib/libtorch_nvshmem.so`, so the step was silently skipped. The lookup now starts from `torch._utils_internal.get_file_path("torch")`, which is anchored on the import system (pytorch#195587). The change only restores that last step: the `NVSHMEM_LIB_DIR` override, the NVSHMEM wheel directory and the system directories are searched as before and in the same order, so the question raised in the issue, whether falling through to a system NVSHMEM is intended, is not affected. `get_file_path` is called with the single component `"torch"`, as in `torch/utils/cpp_extension.py`, and the rest is joined with `os.path`. Tracked in pytorch#195887. ### Test Plan Editable install on Linux x86_64, Python 3.12, CUDA 12.9, built with `NVSHMEM_HOME` pointing at an NVSHMEM 3.7.2 tree outside site-packages. `libtorch_nvshmem.so` is in the install tree only, and its RPATH contains the NVSHMEM `lib` directory. ``` python -c "from torch.distributed._symmetric_memory._nvshmem_triton import NvshmemLibFinder; NvshmemLibFinder.find_device_library()" ``` Before the change the directories searched are the wheel directory and the three system directories. After the change the list also contains the RPATH entries of `libtorch_nvshmem.so`, including the NVSHMEM `lib` directory. The call still ends in "NVSHMEM device library not found" on this setup, for an unrelated reason: it looks for `libnvshmem_device.bc`, and the NVSHMEM 3.7.2 wheel ships per-architecture files (`libnvshmem_device_sm_NN.bc`) instead. No GPU test was run; the function only inspects files. ``` lintrunner -a --take PYFMT,RUFF,FLAKE8 torch/distributed/_symmetric_memory/_nvshmem_triton.py ``` Authored with the help of an AI assistant (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
|
Successfully rebased |
27e0db0 to
b68854f
Compare
Merge failedReason: This PR needs a If not, please add the To add a label, you can comment to pytorchbot, for example For more information, see 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
Fixes #195890
BC-breaking?
No
Summary (human written only)
This PR replaces the legacy
__file__based lookup of the RPATH sourcelibtorch_nvshmem.sowith a modern importlib based version via ourget_file_pathhelper, which is necessary for editable installs in redirect mode.Agent details (if applicable)
NvshmemLibFinder.find_device_librarybuilds a list of directories to search for the NVSHMEM device library. Its last step reads the RPATH of torch's ownlibtorch_nvshmem.soand adds those directories, which is how an NVSHMEM that lives outside site-packages and the system directories is found. It located that library throughos.path.dirname(torch.__file__). Under a redirect-mode editable install that is the source checkout, where there is nolib/libtorch_nvshmem.so, so the step was silently skipped.The lookup now starts from
torch._utils_internal.get_file_path("torch"), which is anchored on the import system (#195587). The change only restores that last step: theNVSHMEM_LIB_DIRoverride, the NVSHMEM wheel directory and the system directories are searched as before and in the same order, so the question raised in the issue, whether falling through to a system NVSHMEM is intended, is not affected.get_file_pathis called with the single component"torch", as intorch/utils/cpp_extension.py, and the rest is joined withos.path.Tracked in #195887.
Test Plan
Editable install on Linux x86_64, Python 3.12, CUDA 12.9, built with
NVSHMEM_HOMEpointing at an NVSHMEM 3.7.2 tree outside site-packages.libtorch_nvshmem.sois in the install tree only, and its RPATH contains the NVSHMEMlibdirectory.Before the change the directories searched are the wheel directory and the three system directories. After the change the list also contains the RPATH entries of
libtorch_nvshmem.so, including the NVSHMEMlibdirectory.The call still ends in "NVSHMEM device library not found" on this setup, for an unrelated reason: it looks for
libnvshmem_device.bc, and the NVSHMEM 3.7.2 wheel ships per-architecture files (libnvshmem_device_sm_NN.bc) instead. No GPU test was run; the function only inspects files.Authored with the help of an AI assistant (Claude Code).
🤖 Generated with Claude Code