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 ya está trabajando en esto.
Desde el 21/9/2026.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 5k
- Forks
- 1.2k
- Merge medio
- 2 d 12 h
- PR fusionados (30 d)
- 588
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pytorch/executorch
-
enhancement triaged
Dificultad 2/5 Medio día Aptitud para principiantes 68/100
pytorch/executorch#21640 ·
-
enhancement module: cuda module: examples module: mlx module: vulkan module: xnnpack
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
pytorch/executorch#23131 · 1 reacción ·
-
bug module: qnn module: quantization
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
pytorch/executorch#23108 ·
-
good first issue module: examples module: webgpu
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
pytorch/executorch#23099 ·
-
good first issue module: examples module: vulkan
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
pytorch/executorch#23098 ·
Todos los issues de pytorch/executorch
Issues similares
-
agent-ready documentation needs-triage
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
-
documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
-
Add https://search.jeremyh.xyz/ Abiertoinstance instance add
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
searxng/searx-instances#939 · 1 comentario ·
-
area-deployment area-integrations triage:bot-seen
Dificultad 2/5 Medio día Aptitud para principiantes 86/100