Skip to content

Bug: CUDA provider DLLs copied to wrong directory, causing Error 126 on model load #469

@jessehouwing

Description

@jessehouwing

Summary

When loading a CUDA-GPU model variant (e.g. qwen2.5-coder-1.5b-instruct-cuda-gpu), the extension correctly detects an NVIDIA GPU and triggers an on-demand download of the ONNX Runtime CUDA provider DLLs. However, the DLLs are copied to the wrong directory and are never found by the inference agent, resulting in a hard failure.

Error Message

Failed loading model qwen2.5-coder-1.5b-instruct-cuda-gpu:4.
E:_work\1\s\onnxruntime\core\session\provider_bridge_ort.cc:1844
onnxruntime::ProviderLibrary::Get [ONNXRuntimeError] : 1 : FAIL :
Error loading "...\ai-mlstudio\bin\onnxruntime_providers_cuda.dll" which is missing.
(Error 126: "The specified module could not be found.")

Root Cause

OnnxRuntimeHandler.ensureOnnxRuntimeCudaLib() constructs the copy destination using:

l.default.join(p.ext.context.extensionUri.fsPath, "bin", dllName)

This resolves to <extension root>\bin\ — but Inference.Service.Agent.exe lives in <extension root>\ai-mlstudio\bin\ and ONNX Runtime resolves provider DLL paths relative to that directory.

getToolkitStaticFolder() (defined in module 72057) correctly returns <extension root>\ai-mlstudio, but it is not imported in the OnnxRuntimeHandler module and is not used here. All 6 path constructions in ensureOnnxRuntimeTRTLib and ensureOnnxRuntimeCudaLib share the same wrong base path.

Affected Files

  • dist/extension.jsOnnxRuntimeHandler class (ensureOnnxRuntimeTRTLib, ensureOnnxRuntimeCudaLib)

Fix

Replace all occurrences of:

p.ext.context.extensionUri.fsPath, "bin"

with:

p.ext.context.extensionUri.fsPath, "ai-mlstudio", "bin"

within the OnnxRuntimeHandler class (both the existence check and the ensureDir/copyFile destination paths).

In source, this means using getToolkitStaticFolder() as the base instead of extensionUri.fsPath when constructing the bin/ path for CUDA provider DLLs.

Secondary Issue (PATH not set for child process)

The inference agent is launched via:

y.exec(`start /B "" "${exe}" ${args}`, { shell: cmdExe, windowsHide: true })

No env is passed, so the child process PATH does not include ai-mlstudio\bin\. Even after fixing the copy destination, Windows DLL loader may fail to resolve transitive dependencies of onnxruntime_providers_cuda.dll (e.g. cublas64_12.dll, cudnn64_9.dll) unless ai-mlstudio\bin\ is on PATH.

Fix: pass env: { ...process.env, PATH: \${binDir};${process.env.PATH}` }` when spawning the agent on Windows.

Steps to Reproduce

  1. Install the extension on a machine with an NVIDIA GPU but without the CUDA toolkit in System32/PATH
  2. Select a *-cuda-gpu model variant in the playground
  3. Observe the on-demand download progress notification (DLLs download successfully)
  4. Model load fails with Error 126

Environment

  • Extension: ms-windows-ai-studio 1.4.3
  • OS: Windows 11
  • GPU: NVIDIA RTX PRO 1000 Blackwell (driver installed, CUDA toolkit NOT separately installed system-wide)

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs attentionThe issue needs contributor's attention

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions