Reputation: 78
I tried running cython compile time optimization on FastAPI serving layer in python during ML Model inferencing. Instead of loading plain python module for ML Model , I tried loading cython compile ML Module in FastAPI Server.
I am getting below error while loading ML Model while running on Mac OS Monterey ( Version 12.5)
Getting invalid ELF header issue
Command to used to compile python file
python setup.py build_ext --inplace
Content of setup.py file
from distutils.core import setup from Cython.Build import cythonize setup(ext_modules = cythonize('v2/model.pyx','v2/model_config.pyx','v2/utils.pyx'), extra_compile_args=["-mmacosx-version-min=10.9", "-stdlib=libc++"], extra_link_args=["-mmacosx-version-min=10.9", "-stdlib=libc++"], )
File which I has trying to load in python code model.cpython-310-darwin.so
Any help would be appreciated here
Upvotes: 1
Views: 321
Reputation: 11
If you're trying to load/compile with a shared object file, you might need to specify it in the libraries argument of the setup file. For example if I have a file called libcalg.so
and want to dynamically link with my cython code, you'd need something like this.
ext_modules = cythonize([
Extension(
"queue",
sources=["queue.pyx"],
libraries=["calg"]) # would be libcalg.so somewhere in usr/local/lib
])
Usually shared objects files are prefixed with an l
so C/C++ knows where to look for it in the usr/local/lib
directory. If you're just trying to use the functions in model.cpython-310-darwin.so
you'll need to dynamically link it. Hopefully this helps
Upvotes: 1