Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backward/forward compatibility with different version of ORT #727

Closed
skyline75489 opened this issue Jul 26, 2024 · 1 comment
Closed

Backward/forward compatibility with different version of ORT #727

skyline75489 opened this issue Jul 26, 2024 · 1 comment
Labels
bug Something isn't working platform:windows

Comments

@skyline75489
Copy link
Contributor

skyline75489 commented Jul 26, 2024

Observation

With #662 merged, it became crucial for ort-genai to have certain level of backward/forward compatibility with different version of ORT. However, the current status isn't ideal.

During my work on #724, the following observations was found on Win32.

Forward compatibility

Compile ort-genai with ORT 1.18 headers + DLLs, the wheel produced will refuse to load ORT 1.19 (ort-nightly atm):

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\jialli\AppData\Local\Anaconda3\envs\ort-genai-py311\Lib\site-packages\onnxruntime_genai\__init__.py", line 23, in <module>
    raise e
  File "C:\Users\jialli\AppData\Local\Anaconda3\envs\ort-genai-py311\Lib\site-packages\onnxruntime_genai\__init__.py", line 13, in <module>
    from onnxruntime_genai.onnxruntime_genai import *
ImportError: DLL load failed while importing onnxruntime_genai: A dynamic link library (DLL) initialization routine failed.

The search path is correct. It's a pure DLL initialization thing. I suppose direct linkage with ORT 1.18 causes the initialization routine to expect a fixed memory layout. Using a newer version breaks this expectation.

Manually switching ORT lib to 1.18 fixes the DLL initialization issue.

Backward compatibility

Compile ort-genai with ORT 1.19 headers + DLLs, similar issue exists if you try to load ORT 1.18 :

>>> import onnxruntime_genai as oga
The requested API version [19] is not available, only API versions [1, 18] are supported in this build. Current ORT Version is: 1.18.0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\jialli\AppData\Local\Anaconda3\envs\ort-genai-py311\Lib\site-packages\onnxruntime_genai\__init__.py", line 22, in <module>
    raise e
  File "C:\Users\jialli\AppData\Local\Anaconda3\envs\ort-genai-py311\Lib\site-packages\onnxruntime_genai\__init__.py", line 12, in <module>
    from onnxruntime_genai.onnxruntime_genai import *
ImportError: DLL load failed while importing onnxruntime_genai: A dynamic link library (DLL) initialization routine failed.

Solution

Implementing #693 on Windows should help. With #724, I see no similar issue on Linux between 1.18 and 1.19. It's still not perfect, but it hugely reduces the possibility of forementioned crashes.

This is just part of the "C++ ABI compatibility" rabbit hole. Win32 actually solves this issue decades ago. The (almost) perfect solution was named COM. Although COM is still widely used by Windows itself, it should not be considered a viable solution in the modern C++ world.

@skyline75489 skyline75489 added the bug Something isn't working label Jul 26, 2024
@skyline75489
Copy link
Contributor Author

Seems like an env issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working platform:windows
Projects
None yet
Development

No branches or pull requests

1 participant