TensorStack-AI / OnnxStack

C# Stable Diffusion using ONNX Runtime
Apache License 2.0
187 stars 27 forks source link

LoadLibrary failed with error 126 #140

Open JacobCZ opened 2 months ago

JacobCZ commented 2 months ago

Trying the minimal stable diffusion example from the readme, when I run the code (with executionProvider: ExecutionProvider.Cuda in the ctor to use CUDA) I get the following error:

Unhandled exception. Microsoft.ML.OnnxRuntime.OnnxRuntimeException: [ErrorCode:RuntimeException] D:\a\_work\1\s\onnxruntime\core\session\provider_bridge_ort.cc:1209 onnxruntime::ProviderLibrary::Get [ONNXRuntimeError] : 1 : FAIL : LoadLibrary failed with error 126 "" when trying to load "...\bin\Debug\net8.0\onnxruntime_providers_cuda.dll"

   at Microsoft.ML.OnnxRuntime.SessionOptions.AppendExecutionProvider_CUDA(Int32 deviceId)
   at OnnxStack.Core.Extensions.GetSessionOptions(OnnxModelConfig configuration)
   at OnnxStack.Core.Model.OnnxModelSession..ctor(OnnxModelConfig configuration)
   at OnnxStack.StableDiffusion.Models.UNetConditionModel..ctor(UNetConditionModelConfig configuration)
   at OnnxStack.StableDiffusion.Pipelines.StableDiffusionPipeline.CreatePipeline(StableDiffusionModelSet modelSet, ILogger logger)
   at OnnxStack.StableDiffusion.Pipelines.StableDiffusionPipeline.CreatePipeline(String modelFolder, ModelType modelType, Int32 deviceId, ExecutionProvider executionProvider, MemoryModeType memoryMode, ILogger logger)
   at UnstableDiffusion.UnstableDiff..ctor(String model) in ...\StableDiff.cs:line 20
   at Program.<Main>$(String[] args) in ...\Program.cs:line 3
   at Program.<Main>(String[] args)

I'm not sure what to do about this. I tried manually installing the CUDA SDK and cuDNN to no avail. bin\Debug\net8.0\onnxruntime_providers_cuda.dll exists and seems to be a valid DLL

Environment:

saddam213 commented 2 months ago

Hey JacobCZ

The CUDA and TensorRT OnnxRuntime packages require their own dependencies to be installed, CUDA Toolkit and cuDNN

LoadLibrary failed with error 126 happens when it cant find one of those dependencies, unfortunately this happens to a few users and I have no idea what causes the issue.

We recommend DirectML if your card supports DirectX as its significantly faster than CUDA and does not require external dependencies.