Metal backend: exported `.pte` does not load outside a process that already has PyTorch's libomp (embedded AOTI object links `/opt/llvm-openmp/lib/libomp.dylib`)
@metascroy がすでに取り組んでいます。
2026年9月21日 から。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
調査の方向性
Start with metal_backend.cpp around line 352 and the MetalBackend.codesign_so path, then inspect run_metal_test.sh's existing library-reference rewrite. Reproduce export and loading outside executor_runner, and determine whether the accepted fix should remove unused dependencies or reject unsupported ones at export time. Done means the chosen behavior is verified for an app without PyTorch's libomp.
索引モデルが issue の本文から書いたものです。
説明
Summary
A Metal .pte loads under executor_runner built by run_metal_test.sh, but fails in an application that links the ExecuTorch runtime on its own:
E executorch:metal_backend.cpp:352] Failed to load shared library: dlopen(.../<hash>_so_blob<pid>.so, 0x0005):
Library not loaded: /opt/llvm-openmp/lib/libomp.dylib
E executorch:method.cpp:132] Init failed for backend MetalBackend: 0x22
Cause
On macOS inductor's _get_openmp_args always adds -lomp. The libomp it resolves is the one bundled in the PyTorch wheel (torch/lib/libomp.dylib), whose LC_ID_DYLIB is the absolute path /opt/llvm-openmp/lib/libomp.dylib, and that path is recorded as a dependency of the AOTI object embedded in the .pte. The path exists on no end-user machine.
It goes unnoticed in-tree because run_metal_test.sh already rewrites the same reference in executor_runner to @rpath/libomp.dylib with an rpath into torch/lib. The runner therefore loads PyTorch's libomp first, and dyld then satisfies the model's dependency by install name. An app that ships its own libomp (or none) has no image with that install name loaded, so dlopen fails.
The dependency is not used: nm -u on the embedded object shows no omp / kmp symbol for a Metal-delegated MobileNet, as expected for a graph that runs on the GPU.
Possible directions
- Link the AOTI object with
-Wl,-dead_strip_dylibsfor the Metal backend, so dylibs the object does not reference are dropped and libomp stays only if a model really needs it. Inductor has no option for extra link flags today; we do it from outside by pointingtorch._inductor.config.cpp.cxxat a wrapper compiler that appends the flag on link steps. The resulting object links onlylibc++andlibSystemand loads in a process with no libomp at all. - Independently, a check next to
MetalBackend.codesign_sothat the compiled object has no dependency outside/usr/liband/Systemwould turn this from a load-time surprise on someone else's machine into an export-time error.
Happy to send a PR for the check if that direction sounds right; the link-flag part probably belongs in inductor.
- 主要言語
- Python
- スター
- 5k
- フォーク
- 1.2k
- 平均マージ
- 2日 12時間
- マージ済み PR(30日)
- 588
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pytorch/executorch のほかの issue
-
enhancement triaged
難易度 2/5 半日 初心者へのやさしさ 68/100
pytorch/executorch#21640 ·
-
enhancement module: cuda module: examples module: mlx module: vulkan module: xnnpack
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
pytorch/executorch#23131 · リアクション 1 件 ·
-
bug module: qnn module: quantization
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
pytorch/executorch#23108 ·
-
good first issue module: examples module: webgpu
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
pytorch/executorch#23099 ·
-
good first issue module: examples module: vulkan
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
pytorch/executorch#23098 ·
pytorch/executorch の issue をすべて見る
似ている issue
-
bug priority:low
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
CyberAgent/psd2svg#436 ·
-
area/install-update comp/cli comp/desktop P3 sweeper:risk-compatibility type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
NousResearch/hermes-agent#122386 · コメント 1 件 ·
-
ai-generated
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
vllm-project/production-stack#1105 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100