Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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`)

Abierto
#22,955 1 comentario 0 reacciones 2 asignados Ver en GitHub

@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
Stack tecnológico
cpp, macos, python

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

module: metal triaged
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_dylibs for 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 pointing torch._inductor.config.cpp.cxx at a wrapper compiler that appends the flag on link steps. The resulting object links only libc++ and libSystem and loads in a process with no libomp at all.
  • Independently, a check next to MetalBackend.codesign_so that the compiled object has no dependency outside /usr/lib and /System would 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

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pytorch/executorch

Todos los issues de pytorch/executorch

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.