4
import onnxruntime as rt
ort_session = rt.InferenceSession(
            "my_model.onnx",
            providers=["CUDAExecutionProvider"],
)

onnxruntime (onnxruntime-gpu 1.13.1) works (in Jupyter VsCode env - Python 3.8.15) well when providers is ["CPUExecutionProvider"]. But for ["CUDAExecutionProvider"] it sometimes(not always) throws an error as:

[W:onnxruntime:Default, onnxruntime_pybind_state.cc:578 CreateExecutionProviderInstance] Failed to create CUDAExecutionProvider. Please reference https://onnxruntime.ai/docs/reference/execution-providers/CUDA-ExecutionProvider.html#requirements to ensure all dependencies are met.

I tried following the provided link in the error, and tried different setups in the conda environment to test the code with various version combinations.

Oguz Hanoglu
  • 161
  • 1
  • 6

4 Answers4

9

Replacing:

import onnxruntime as rt

with

import torch
import onnxruntime as rt

somehow perfectly solved my problem.

Oguz Hanoglu
  • 161
  • 1
  • 6
  • 1
    The reason might be related to the fact that requirements include *CUDA* and *cuDNN* and these are installed within *pytorch* in *conda*. Importing torch would be enabling CUDA/cuDNN in the kernel. – Oguz Hanoglu Jan 28 '23 at 12:07
  • Because pytorch contains all cuda libraries. When you import pytorch, it also imports cuda libraries in memory. – RedEyed Apr 26 '23 at 10:36
0
  1. You should check your onnxruntime-gpu version ,cuda version and cudnn version in this link 'https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html'
  2. Use 'nvcc -V' and 'cat /usr/local/cuda/include/cudnn_version.h' make sure your env is useful.
  3. 'import torch' is necessary,the code as is follows:
  • import torch
  • import onnxruntime as rt
  • providers = ['CUDAExecutionProvider', 'CPUExecutionProvider']
  • session = rt.InferenceSession("yolo.onnx", providers=providers)
peng yao
  • 1
  • 1
0

In my case the following helped:

  1. uninstall onnxruntime
  2. uninstall onnxruntime-gpu
  3. install optimum[onnxruntime-gpu]

more here

thawro
  • 31
  • 2
0

I had the same issue but with TensorRT TensorrtExecutionProvider:

[W:onnxruntime:Default, onnxruntime_pybind_state.cc:614 CreateExecutionProviderInstance] Failed to create TensorrtExecutionProvider. Please reference https://onnxruntime.ai/docs/execution-providers/TensorRT-ExecutionProvider.html#requirements to ensure all dependencies are met.

Look like in this case one have to import tensorrt and have to do so before importing onnxruntime (GPU):

import tensorrt
import onnxruntime as ort

# Inference with ONNX TensorRT
Louis Lac
  • 5,298
  • 1
  • 21
  • 36