Fix ONNX Runtime CUDA fallback by preloading shared library dependencies#276
Fix ONNX Runtime CUDA fallback by preloading shared library dependencies#276Misty-Star wants to merge 2 commits intonomadkaraoke:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds ONNX Runtime visibility and optional shared-library preloading, defers Separator imports in the CLI, and adds unit tests for the GPU/ORT setup and CLI no-args behavior. Changes
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/unit/test_gpu_runtime_setup.py`:
- Line 12: The test currently patches
"audio_separator.separator.separator.ort.preload_dlls" assuming the attribute
exists; update the patch call that creates mock_preload to include create=True
so the test tolerates environments where ort.preload_dlls is absent (i.e.,
change the patch for ort.preload_dlls to
patch("audio_separator.separator.separator.ort.preload_dlls", create=True) while
keeping the rest of the test and the mock_preload variable unchanged).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8146c522-64a5-4451-a9fc-5b22aadd4e81
📒 Files selected for processing (5)
audio_separator/separator/architectures/mdx_separator.pyaudio_separator/separator/separator.pyaudio_separator/utils/cli.pytests/unit/test_cli.pytests/unit/test_gpu_runtime_setup.py
Summary
This PR improves GPU initialization for ONNX Runtime in pip-based CUDA environments by preloading
shared library dependencies before provider setup.
It also adds a clearer warning when an ONNX Runtime session cannot activate the requested
execution provider, and defers CLI imports so
audio-separatorhelp/usage paths do not eagerlytrigger heavy runtime initialization.
Problem
In some Linux environments where CUDA and cuDNN are installed via pip wheels,
onnxruntime-gpumay report
CUDAExecutionProvideras available, but actual ONNX sessions can still fall back toCPU because the required shared libraries are not visible to the dynamic loader at session
creation time.
In this case, users may see errors similar to:
Failed to load library ... libonnxruntime_providers_cuda.solibcudnn.so.9: cannot open shared object fileFailed to create CUDAExecutionProviderThis can be confusing because PyTorch may still detect and use CUDA successfully, while ONNX
Runtime silently falls back to CPU for ONNX models.
Root Cause
The CUDA/cuDNN runtime libraries provided by pip-installed NVIDIA wheels are not always discovered
automatically by ONNX Runtime before the first CUDA execution provider session is created.
Changes
onnxruntime.preload_dlls()during accelerated device setup when the installed ONNXRuntime version supports it.
activated by the created session.
Separatorin the CLI until it is actually needed, so no-argument/help flows donot eagerly trigger ONNX Runtime initialization.
behavior.
Why this helps
This makes pip-installed CUDA/cuDNN runtimes visible to ONNX Runtime earlier in the startup flow,
which avoids a common failure mode where ONNX Runtime advertises CUDA support but then creates
CPU-only sessions in practice.
It also makes provider fallback much more obvious in logs, which should make future GPU
troubleshooting easier.
Validation
Validated locally with a pip-based GPU environment on Linux using:
2.11.0+cu130onnxruntime-gpu1.24.4Before this change:
CUDAExecutionProviderin provider discovery.InferenceSession(..., providers=["CUDAExecutionProvider"])failed to load CUDAdependencies and fell back to
CPUExecutionProvider.After this change:
CUDAExecutionProviderwithout requiring a manual
LD_LIBRARY_PATHworkaround.Notes
This PR is focused on CUDA dependency loading and provider activation.
It does not attempt to address unrelated ONNX Runtime device discovery warnings such as Linux
DRM probing messages (for example,
/sys/class/drm/card0/device/vendoron systems wherecard0is a framebuffer device rather than the NVIDIA device).
Summary by CodeRabbit
Improvements
Tests