Fix CUDA version hardcoding to support CUDA 13+ dynamically - #26518
Merged
Tianlei Wu (tianleiwu) merged 4 commits intoNov 9, 2025
Merged
Conversation
The runtime Python code had CUDA 12 hardcoded in multiple locations, causing library loading failures when building with CUDA 13. Changes in onnxruntime/__init__.py: - Dynamic library path generation using detected CUDA version - Updated version validation to accept CUDA 12+ - Fixed PyTorch compatibility check to compare CUDA versions dynamically - Updated diagnostic checks to report correct nvidia packages Changes in setup.py: - Added is_cuda_version_13 flag and proper version parsing - Added CUDA 13 library versions to dependency exclusion list - Added CUDA 13 extras_require with nvidia-*-cu13 packages - Fixed TensorRT RTX to use dynamic CUDA version Fixes runtime "CUDA 12 not found" errors on CUDA 13 systems while maintaining backward compatibility with CUDA 12 builds.
Contributor
Author
|
@microsoft-github-policy-service agree |
- Extract CUDA major version parsing into _extract_cuda_major_version() helper - Add _get_cufft_version() for CUDA-version-specific cufft mapping (11 for CUDA 12.x, 12 for CUDA 13.x) - Replace all try-except-pass blocks with contextlib.suppress() (fixes RUFF/SIM105) - Apply dynamic cufft version to both Windows and Linux DLL paths - Add contextlib import to setup.py and onnxruntime/__init__.py This eliminates code duplication and ensures correct library versions across CUDA versions.
…if blocks - Replace separate is_cuda_version_12/13 conditions with single dynamic block - Use cuda_major_version variable with f-strings for package names - Apply correct cufft version mapping (11.0 for CUDA 12, 12.0 for CUDA 13) - Works automatically for future CUDA versions
Contributor
|
Please format the code with lintrunner: https://github.com/microsoft/onnxruntime/blob/main/docs/Coding_Conventions_and_Standards.md#Linting |
Contributor
Author
|
Maybe this way? deduplicated some code |
Contributor
|
/azp run Linux QNN CI Pipeline, Win_TRT_Minimal_CUDA_Test_CI,Windows ARM64 QNN CI Pipeline,Windows GPU Doc Gen CI Pipeline,Windows x64 QNN CI Pipeline |
|
Azure Pipelines successfully started running 4 pipeline(s). |
Tianlei Wu (tianleiwu)
approved these changes
Nov 9, 2025
Rohanjames1997
pushed a commit
to Rohanjames1997/onnxruntime
that referenced
this pull request
Dec 4, 2025
…t#26518) ## Description Fixes runtime library loading failures when building with CUDA 13 by replacing hardcoded CUDA 12 references with dynamic version detection. Related to microsoft#26516 which updates CUDA 13 build pipelines, but this PR fixes the Python runtime code that was still hardcoded to CUDA 12. ## Problem The build system correctly detects CUDA 13 via CMake, but the runtime Python code had CUDA 12 hardcoded in multiple locations, causing "CUDA 12 not found" errors on CUDA 13 systems. ## Solution Modified onnxruntime/__init__.py and setup.py to dynamically use the detected CUDA version instead of hardcoded "12" strings. ## Changes - Dynamic CUDA version extraction from build info - Library paths now use f-strings with cuda_major_version - Added CUDA 13 support to extras_require and dependency exclusions - Fixed TensorRT RTX package to use correct CUDA version - Updated version validation to accept CUDA 12+ - Fixed PyTorch compatibility checks to compare versions dynamically ## Impact - CUDA 13 builds now load correct libraries - Backward compatible with CUDA 12 - Forward compatible with future CUDA versions ## Testing Verified with CUDA 13.0 build that library paths resolve correctly and preload_dlls() loads CUDA 13 libraries without errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes runtime library loading failures when building with CUDA 13 by replacing hardcoded CUDA 12 references with dynamic version detection.
Related to #26516 which updates CUDA 13 build pipelines, but this PR fixes the Python runtime code that was still hardcoded to CUDA 12.
Problem
The build system correctly detects CUDA 13 via CMake, but the runtime Python code had CUDA 12 hardcoded in multiple locations, causing "CUDA 12 not found" errors on CUDA 13 systems.
Solution
Modified onnxruntime/init.py and setup.py to dynamically use the detected CUDA version instead of hardcoded "12" strings.
Changes
Impact
Testing
Verified with CUDA 13.0 build that library paths resolve correctly and preload_dlls() loads CUDA 13 libraries without errors.