Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/189704
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (4 Unrelated Failures)As of commit fdf6272 with merge base b0eccff ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Verified on a real macOS host (26.4.1) with a synthetic clang-built libomp/libtorch_cpu pair, exercising the script before and after the fix:
One precision on the failure mode: on this host, a direct test transcript |
|
cc @malfet I'm the user in question. A review would be appreciated, this is preventing me from building/debugging locally without patching this file. |
|
@malfet Reminder. I have to keep this diff in a stash to do local development. |
|
@claude How come we have to delete as opposed to merge |
|
Claude finished @ezyang's task in 47s —— View job Why delete rather than mergeShort answer: deleting is the merge. The desired end state is the set union of the rpaths, which is Some detail on why there's no other option:
One caveat worth stating, since it's the only behavioural difference between rename and delete: the rename preserves the position of the build-time entry in the search order, whereas delete leaves resolution to the pre-existing Nit, unrelated to the question
|
|
@claude How come we delete rpath instead of do nothing? |
|
Claude finished @ezyang's task in 1m 20s —— View job Why delete rather than leave it alone"Do nothing" would fix the duplicate — but it would also silently abandon what the script exists to do. Per its docstring, the goal is that the bundled
So the minimal change that fixes the duplicate and preserves intent is to drop the entry rather than rewrite it into a copy of one that's already there. One caveat worth stating (pre-existing, not introduced here)The rpath being removed is |
|
@claude If this change is buggy, what is the potential blast radius. It clearly affects build from source, how about wheels? |
|
Claude finished @ezyang's task in 9m 45s —— View job Blast radiusShort version: wheels do execute this code path, and probably even the exact branch that changed — but the change is provably a no-op on the resulting dyld search set, so the realistic blast radius is "loud build failure," not "silently broken wheel." The larger risk here is a coverage gap: the macOS wheel job doesn't run on this PR without a ciflow tag. Full analysis1. What can reach the code at all
The only file ever mutated is 2. Do wheels hit the changed branch?Yes, most likely. The wheel build ( So the wheel's 3. Why the semantic risk is near zeroThe two branches converge on the same rpath set. Concretely, for The surviving The one pre-existing hazard the change inherits rather than introduces: the removed rpath is 4. If it is buggy, how does it manifest?
5. The actual risk: test coverage on this PR
Recommend tagging before merge: If both are green, the wheel exposure is covered by the strongest available signal: an 6. Unrelated nit, still open from my earlier comment
|
|
@pytorchbot merge |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
Root cause: tools/embed_libomp_macos.py (from pytorch#180239) handles the conda-style layout by renaming the rpath that points at the build-time libomp directory to @loader_path. Every torch library already carries @loader_path via CMAKE_INSTALL_RPATH (cmake/Dependencies.cmake), so the rename writes a second, identical LC_RPATH into libtorch_cpu.dylib. dyld on macOS 15.4+ refuses to load an image with duplicate LC_RPATH entries, so a from-source build in a conda/pixi environment (whose toolchain links with -Wl,-rpath,$PREFIX/lib, giving the script its rename target) builds fine but fails at `import torch` with Library not loaded: @rpath/libtorch_cpu.dylib ... 'torch/lib/libtorch_cpu.dylib' (duplicate LC_RPATH '@loader_path') The CD wheels never showed this because delocate normalizes rpaths afterwards, and older dyld tolerated the duplicate silently. Fix: in the rename branch, when @loader_path is already among the rpaths, delete the build-time rpath instead of renaming it. The rename is kept for the (hypothetical) layout without a preexisting @loader_path, and the add_rpath branch was already guarded. Workaround for already-built trees, until a rebuild picks this up: install_name_tool -delete_rpath @loader_path torch/lib/libtorch_cpu.dylib ## Test plan All four decision branches exercised with parse_otool/install_name_tool mocked (conda-style dup case: original script provably issues the rename, fixed script issues -delete_rpath; env-rpath-only rename preserved; homebrew load-command rewrite untouched; unlinked no-op): ``` python3 rpath_mock_test.py # inline in the PR discussion; ALL CASES PASS ``` Real-dylib verification script (clang synthetic libomp/libtorch_cpu pair, before/after otool -l LC_RPATH counts) prepared for a macOS host; the remote mac test box was unreachable, and the reporting user's failing pixi environment (macOS 15.4+, conda clang) reproduces the exact scenario for confirmation. ``` lintrunner tools/embed_libomp_macos.py # clean (two pre-existing trunk # PYREFLY bcomplex32 errors only) ``` Authored with assistance from Claude Code.
|
Successfully rebased |
5b2ff80 to
fdf6272
Compare
|
@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 |
Merge failedReason: 1 jobs have failed, first few of them are: trunk / linux-jammy-rocm-py3.10-mi350 / test (default, 5, 8, linux.rocm.gpu.gfx950.1) Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 1 checks: linux-binary-manywheel / libtorch-rocm7_14-shared-with-deps-release-extract Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…ds (pytorch#189704) ## Summary Fixes a macOS import failure for from-source builds in conda/pixi environments: the build completes, but `import torch` fails with ``` ImportError: dlopen(.../torch/_C.cpython-313-darwin.so, 0x0002): Library not loaded: @rpath/libtorch_cpu.dylib Referenced from: .../torch/lib/libtorch_python.dylib Reason: tried: ... '.../torch/lib/libtorch_cpu.dylib' (duplicate LC_RPATH '@loader_path'), ... ``` ## Root cause `tools/embed_libomp_macos.py` (from pytorch#180239, invoked at install time via `cmake/PostBuildSteps.cmake`) handles the conda-style layout by renaming the rpath that points at the build-time libomp directory to `@loader_path`. Every torch library already carries `@loader_path` via `CMAKE_INSTALL_RPATH` (`cmake/Dependencies.cmake:13`), so the rename writes a second, identical `LC_RPATH` into `libtorch_cpu.dylib`. dyld on macOS 15.4+ refuses to load an image with duplicate `LC_RPATH` entries; older dyld tolerated the duplicate silently, and the CD wheels never showed it because delocate normalizes rpaths afterwards. The triggering configuration is a conda/pixi env providing libomp: the env lib dir ends up as an rpath on `libtorch_cpu.dylib` (via `CMAKE_INSTALL_RPATH_USE_LINK_PATH` and/or the conda toolchain's `-Wl,-rpath,$PREFIX/lib`), which is exactly the rename target. ## Fix In the rename branch, when `@loader_path` is already among the rpaths, delete the build-time rpath instead of renaming it. The rename is kept for layouts without a preexisting `@loader_path` (e.g. builds run with `-DCMAKE_SKIP_INSTALL_RPATH=ON`, where `LDFLAGS`-injected rpaths survive but CMake-managed ones are stripped); the `add_rpath` branch was already guarded. Workaround for already-built trees until a rebuild picks this up: ``` install_name_tool -delete_rpath @loader_path torch/lib/libtorch_cpu.dylib ``` ## Test plan All four decision branches exercised with `parse_otool` / `install_name_tool` mocked; the pre-fix script provably issues the duplicate-creating rename in the conda case, the fixed one issues `-delete_rpath`: <details> <summary>mock test (ALL CASES PASS)</summary> ```python import importlib.util, sys, tempfile from pathlib import Path from unittest import mock def load(path, name): spec = importlib.util.spec_from_file_location(name, path) m = importlib.util.module_from_spec(spec) spec.loader.exec_module(m) return m def run_case(script, rpaths, libs, tmp): m = load(script, "emb") omp_dir = tmp / "omp"; lib_dir = tmp / "lib" omp_dir.mkdir(exist_ok=True); lib_dir.mkdir(exist_ok=True) (omp_dir / "libomp.dylib").write_bytes(b"x") (lib_dir / "libtorch_cpu.dylib").write_bytes(b"x") calls = [] with mock.patch.object(m, "parse_otool", return_value=(rpaths, libs)), \ mock.patch.object(m.subprocess, "check_call", lambda cmd, *a, **k: calls.append(cmd)), \ mock.patch.object(sys, "argv", ["x", "--libomp-path", str(omp_dir/"libomp.dylib"), "--lib-dir", str(lib_dir)]): m.main() return [" ".join(c[:3]) for c in calls] with tempfile.TemporaryDirectory() as td: tmp = Path(td); env_rp = str(tmp / "omp") # conda-style (@loader_path + env rpath): fixed script must delete, not rename c = run_case("tools/embed_libomp_macos.py", ["@loader_path", env_rp], ["@rpath/libomp.dylib"], tmp) assert "-delete_rpath" in c[0], c # env rpath only: rename preserved c = run_case("tools/embed_libomp_macos.py", [env_rp], ["@rpath/libomp.dylib"], tmp) assert "-rpath" in c[0], c # homebrew abs load command, @loader_path present: only the -change rewrite c = run_case("tools/embed_libomp_macos.py", ["@loader_path"], [str(tmp/"omp"/"libomp.dylib")], tmp) assert len(c) == 1 and "-change" in c[0], c # not linked against libomp: untouched c = run_case("tools/embed_libomp_macos.py", ["@loader_path"], ["@rpath/libc++.dylib"], tmp) assert c == [], c print("ALL CASES PASS") ``` </details> ``` lintrunner tools/embed_libomp_macos.py # clean ``` Reported by a user building viable/strict `84cc6889912` in a pixi env on macOS 15.4+; that environment reproduces the failure and can confirm the fix end-to-end. This PR was authored with the assistance of Claude Code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#189704 Approved by: https://github.com/ezyang
Summary
Fixes a macOS import failure for from-source builds in conda/pixi
environments: the build completes, but
import torchfails withRoot cause
tools/embed_libomp_macos.py(from #180239, invoked at install time viacmake/PostBuildSteps.cmake) handles the conda-style layout by renaming therpath that points at the build-time libomp directory to
@loader_path.Every torch library already carries
@loader_pathviaCMAKE_INSTALL_RPATH(
cmake/Dependencies.cmake:13), so the rename writes a second, identicalLC_RPATHintolibtorch_cpu.dylib. dyld on macOS 15.4+ refuses to load animage with duplicate
LC_RPATHentries; older dyld tolerated the duplicatesilently, and the CD wheels never showed it because delocate normalizes
rpaths afterwards.
The triggering configuration is a conda/pixi env providing libomp: the env
lib dir ends up as an rpath on
libtorch_cpu.dylib(viaCMAKE_INSTALL_RPATH_USE_LINK_PATHand/or the conda toolchain's-Wl,-rpath,$PREFIX/lib), which is exactly the rename target.Fix
In the rename branch, when
@loader_pathis already among the rpaths,delete the build-time rpath instead of renaming it. The rename is kept for
layouts without a preexisting
@loader_path(e.g. builds run with-DCMAKE_SKIP_INSTALL_RPATH=ON, whereLDFLAGS-injected rpaths survive butCMake-managed ones are stripped); the
add_rpathbranch was alreadyguarded.
Workaround for already-built trees until a rebuild picks this up:
Test plan
All four decision branches exercised with
parse_otool/install_name_toolmocked; the pre-fix script provably issues theduplicate-creating rename in the conda case, the fixed one issues
-delete_rpath:mock test (ALL CASES PASS)
Reported by a user building viable/strict
84cc6889912in a pixi env onmacOS 15.4+; that environment reproduces the failure and can confirm the
fix end-to-end.
This PR was authored with the assistance of Claude Code.
🤖 Generated with Claude Code