Repository navigation
Conversation
[Medium impact] The PR appears safe to merge; no new actionable issues were found. SummaryThe PR puts Python-provided CUDA libraries ahead of the dynamic linker's default locations while keeping explicitly selected locations first.
The four previous, unnumbered findings have been addressed: token searches stay within their selected entry, missing Python cuBLAS and cudart no longer raise immediately, and unversioned library names take priority. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Load cuDNN or NVRTC] --> B[Explicit library and toolkit paths]
B --> C{Found?}
C -->|No| D[LD_LIBRARY_PATH entries]
D --> E{Found?}
E -->|No| F[Python packages]
F --> G{Found?}
G -->|No| H[Dynamic linker defaults]
C -->|Yes| I[Keep library handle]
E -->|Yes| I
G -->|Yes| I
H --> I
Reviews (4) · Last reviewed commit: "[Common] Fix CUDA library loading for pi..." · Reviewed by Greptile |
|
@ksivaman, would you mind taking a look at this follow-up to your runtime loader work? It keeps framework-provided CUDA libraries ahead of linker defaults, preserves explicit path overrides, and removes the unnecessary cuRAND import dependency. If someone else owns this path now, happy to redirect. |
A pip-installed framework depends on the CUDA libraries in its own Python environment. Previously, _load_cuda_library searched the dynamic linker's default locations before Python packages, so a host-wide cuDNN replaced the copy required by PyPI torch or mapped a duplicate copy alongside JAX. Keep explicit environment and toolkit locations first (<LIBRARY>_LIBRARY_PATH, <LIBRARY>_HOME, <LIBRARY>_PATH, CUDA_HOME, CUDA_PATH, /usr/local/cuda, and LD_LIBRARY_PATH), then search Python packages, and fall back to the dynamic linker's default search last. Read LD_LIBRARY_PATH entries directly so versioned libraries without unversioned symlinks are found while preserving unversioned symlink priority and $ORIGIN/$LIB token scoping. Pass CUDNN_LIBRARY_PATH to the minimum-versions import checks so they match the apt cuDNN selected at build time. Also drop the import-time libcurand load: Transformer Engine only uses cuRAND device headers, and PyTorch 2.15 and JAX do not install libcurand by default. When NVRTC comes from Python packages, load cuBLAS and cudart from Python packages only when present and leave remaining libraries to the linker. Signed-off-by: Bruno Volpato <brunocvcunha@gmail.com>
acfbca9 to
8d7b541
Compare
|
rebased and squashed onto current for some context, added |
Description
Fix two ways that the runtime CUDA library search breaks environments where a pip-installed framework supplies the CUDA libraries.
A host-wide cuDNN replaces the cuDNN that the framework needs. The
CDLL("libcudnn.so")fallback is described as anLD_LIBRARY_PATHsearch, but it also searches the dynamic linker's default locations, and it runs before the Python environment. PyPItorchpins its ownnvidia-cudnn-cu13, so on a host with an older system cuDNN it fails with:With JAX, the same search maps two copies of cuDNN into one process.
The import also requires
libcurand. PyTorch 2.15 removedcurandfrom itscuda-toolkitextras, and JAX does not install it, so on a host without the CUDA toolkit the import fails withcurand shared object not found. Transformer Engine only uses cuRAND's device-side headers. The core library does not linklibcurandand calls none of its host functions.Related to #2373 and #2297, which made
LD_LIBRARY_PATHtake priority over Python packages. This PR keeps that priority.Type of change
Changes
<LIBRARY>_LIBRARY_PATH,<LIBRARY>_HOME,<LIBRARY>_PATH,CUDA_HOME,CUDA_PATH,/usr/local/cuda,LD_LIBRARY_PATH, the Python environment, and then the dynamic linker's default locations.LD_LIBRARY_PATHdirectly, so that it also finds versioned libraries such aslibcudnn.so.9. The pip packages have no unversioned symlink, so the previous lookup could not find them there. An entry's unversioned name still takes priority when it exists.$ORIGINexpands to the executable's directory, and an entry with another token, such as$LIB, goes todlopenas a path. An entry that does not have the library does not affect the search.CUDNN_LIBRARY_PATHto the minimum-versions import checks so they use the same apt cuDNN selected at build time rather than the older pip copy installed with PyTorch 2.8.PyTorch preloads the cuDNN from its own Python package, so when the environment selects the system cuDNN, PyTorch's copy is mapped too and PyTorch rejects the older version. That behavior is not new.
One behavior changes on purpose. If a framework uses a system cuDNN and an unrelated pip cuDNN package is also installed, Transformer Engine now loads the pip package unless the environment selects a location.
CUDNN_PATHorLD_LIBRARY_PATHselects the system copy.Before and after
These runs used one NVIDIA B200 with system cuDNN 9.20 and PyTorch 2.15.0+cu132, which installs cuDNN 9.26.
cuDNN version incompatibilityLD_LIBRARY_PATHset to pip cuDNNcuDNN version incompatibilityCUDNN_PATHset to pip cuDNNLD_LIBRARY_PATHorCUDNN_PATHset to system cuDNNtransformer_engine.commoncurand shared object not foundcurand shared object not foundLD_LIBRARY_PATHentry with$ORIGINor$LIBthat selects system cuDNNLD_LIBRARY_PATHentry with$ORIGINor$LIBthat has no cuDNNcuDNN version incompatibilityLD_LIBRARY_PATHentry whoselibcudnn.soselects one of two versionslibcudnn.soValidation
The source builds targeted
100awith CUDA 13.2, PyTorch 2.15.0+cu132, cuDNN 9.26, FlashAttention 2.8.4, and JAX 0.12.0.1. The base wasb0219803.test_sanity.pyfail when the search order or the cuRAND load is reverted, or when theLD_LIBRARY_PATHname and token handling is removed, and they pass with this change.test_torch_compile.py([PyTorch] torch.compile fails on FusedAttnBackend IntEnum comparisons #3716),test_dot_product_attention_score_mod([PyTorch] Keep Flex Attention score_mod graphs on the cuDNN backend #3796), and FP32 numerics cases ([CI] Disable TF32 for the L0 PyTorch numerics tests #3797).test_layer.pyandtest_fused_attn_score_mod.pyfound no failures in the default environment, with the system cuDNN present, before the last commit.test_fused_attn.pyfound no failures before the last two commits. The last commit only changesLD_LIBRARY_PATHentries that contain tokens, and JAX import was rechecked after it.test_sanity.py,test_numerics.py,tests/pytorch/nvfp4,tests/pytorch/mxfp8, andtest_quantized_tensor.pyfound no failures before the last commit, withNVIDIA_TF32_OVERRIDE=0set. JAX imported and ran a basic operation. The no-toolkit import and a forward pass were rechecked on the final code.Pylint reported no issues for the changed module, and the repository hooks passed. A100, H100, aarch64, and NGC images, where the framework uses the system cuDNN, were not tested. Release wheels were not rebuilt with this change.
Checklist: