# Failed to create CUDAExecutionProvider

**URL:** <https://discuss.huggingface.co/t/failed-to-create-cudaexecutionprovider/26501>\
**Category:** 🤗Optimum\
**Created:** [November 22, 2022, 11:02am UTC](https://discuss.huggingface.co/t/failed-to-create-cudaexecutionprovider/26501 "2022-11-22T11:02:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![serdarcaglar](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@serdarcaglar](https://discuss.huggingface.co/u/serdarcaglar)\
**Post date:** [November 22, 2022, 11:02am UTC](https://discuss.huggingface.co/t/failed-to-create-cudaexecutionprovider/26501/1 "2022-11-22T11:02:11Z")

</div>

Hello Everyone,  
I have been trying to Optimize the model (Text Classification, BERT) for GPU using `ORTOptimizer` but first, I got this warning message:

`[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. 2022-11-22 13:46:00.800872459 [W:onnxruntime:, inference_session.cc:1458 Initialize] Serializing optimized model with Graph Optimization level greater than ORT_ENABLE_EXTENDED and the NchwcTransformer enabled. The generated model may contain hardware-specific optimizations, and should only be used in the same environment the model was optimized in.`

**Then I faced an error:**  
`assert "CUDAExecutionProvider" in session.get_providers() # Make sure there is GPU 107 assert os.path.exists(optimized_model_path) and os.path.isfile(optimized_model_path) 108 logger.debug("Save optimized model by onnxruntime to {}".format(optimized_model_path)) `  
**Environment check:**  
`get_available_providers()` output: [‘TensorrtExecutionProvider’, ‘CUDAExecutionProvider’, ‘CPUExecutionProvider’]

---

<div class="post-metadata">

**Author:** ![fxmarty](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/fxmarty/32/23782_2.png) [@fxmarty](https://discuss.huggingface.co/u/fxmarty)\
**Post date:** [November 23, 2022, 8:37am UTC](https://discuss.huggingface.co/t/failed-to-create-cudaexecutionprovider/26501/2 "2022-11-23T08:37:49Z")

</div>

Hello @serdarcaglar , ONNX Runtime + GPU can be tricky. Although `get_available_providers()` shows CUDAExecutionProvider available, ONNX Runtime can fail to find CUDA dependencies when initializing the model.

I would recommend you to refer to [Accelerated inference on NVIDIA GPUs](https://huggingface.co/docs/optimum/main/en/onnxruntime/usage_guides/gpu#installation) , especially the section “Checking the installation is successful”, to see if your install is good. I would recommend to follow Nvidia documentation to install CUDA and cuDNN, it’s well written.

---

<div class="post-metadata">

**Author:** ![serdarcaglar](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@serdarcaglar](https://discuss.huggingface.co/u/serdarcaglar)\
**Post date:** [November 28, 2022, 2:34pm UTC](https://discuss.huggingface.co/t/failed-to-create-cudaexecutionprovider/26501/3 "2022-11-28T14:34:32Z")

</div>

Thanks. Problem was solved.

---

<div class="post-metadata">

**Author:** ![fxmarty](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/fxmarty/32/23782_2.png) [@fxmarty](https://discuss.huggingface.co/u/fxmarty)\
**Post date:** [December 1, 2022, 2:58pm UTC](https://discuss.huggingface.co/t/failed-to-create-cudaexecutionprovider/26501/4 "2022-12-01T14:58:49Z")

</div>

Better error message will be present in the next release, to check the CUDA is well installed: [Clearer error messages when initilizing the requested ONNX Runtime execution provider fails by fxmarty · Pull Request #514 · huggingface/optimum · GitHub](https://github.com/huggingface/optimum/pull/514)

---

<div class="post-metadata">

**Author:** ![Illthink](https://avatars.discourse-cdn.com/v4/letter/i/9d8465/32.png) [@Illthink](https://discuss.huggingface.co/u/Illthink)\
**Post date:** [January 31, 2023, 5:34am UTC](https://discuss.huggingface.co/t/failed-to-create-cudaexecutionprovider/26501/5 "2023-01-31T05:34:17Z")

</div>

> <https://stackoverflow.com/questions/75267445/why-does-onnxruntime-fail-to-create-cudaexecutionprovider-in-linuxubuntu-20/75267493#75267493>

solved my problem.
