onnxruntime icon indicating copy to clipboard operation
onnxruntime copied to clipboard

onnxruntime-directml import interference with sklearn

Open xcmgttacct opened this issue 1 year ago • 1 comments

Describe the issue

There is a weird bug when working with sklearn and onnxruntime-directml. When running natively with python, if the sklearn is imported before onnxruntime, the onnxruntime will throw DLL load failed exception:

...\onnxruntime\capi\_pybind_state.py", line 32, in <module>
from .onnxruntime_pybind11_state import *  # noqa
ImportError: DLL load failed while importing onnxruntime_pybind11_state: A dynamic link library (DLL) initialization routine failed.

This behavior can be fixed by import onnxruntime first. However, in pyinstaller packed executable, rearrange the import order does not fix the issues.

To reproduce

A simple script to reproduce, the code below will throw exception:

import numpy
import sklearn
import onnxruntime

print(onnxruntime.__version__)

The code below works:

import numpy
import onnxruntime
import sklearn

print(onnxruntime.__version__)

Urgency

No response

Platform

Windows

OS Version

11 (Build number) 22631.3880)

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.18.1

ONNX Runtime API

Python

Architecture

X64

Execution Provider

DirectML

Execution Provider Library Version

No response

xcmgttacct avatar Aug 13 '24 15:08 xcmgttacct

image ImportError: DLL load failed while importing onnxruntime_pybind11_state: 动态链接库(DLL)初始化例程失败。

bluceliuljx avatar Aug 29 '24 09:08 bluceliuljx

It seems that building pyinstaller exe on a minimal script with onnxruntime-directml and a few libraries will pass. Compile the onnxruntime part into a single file and make the main process to use it.

shinnpuru avatar Jul 14 '25 14:07 shinnpuru

Applying stale label due to no activity in 30 days

Applying stale label due to no activity in 30 days

Closing issue due to no activity in 30 days