Repository navigation
Description
Nixpkgs version
- Unstable (25.11) (
c5ae371f1a6a7fd27823bc500d9390b38c05fa55)
Describe the bug
using pythonPackages.torch, cudnn can't load libnvrtc. this is supposed to work via this injected runpath
| extraRunpaths = lib.optionals cudaSupport [ "${lib.getLib cudaPackages.cuda_nvrtc}/lib" ]; |
but this doesn't work with the source torch package. this does work perfectly with torch-bin.
this is related to #296179
Steps to reproduce
On a machine with an H100 (or similar GPU),
in a nix-shell --arg config '{ cudaSupport = true; allowUnfree = true; }' -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/c5ae371f1a6a7fd27823bc500d9390b38c05fa55.tar.gz -p 'python3.withPackages (ps: [ps.torch])'
run python test.py, where test.py is the below script:
import torch
import os
import ctypes
print(f"PyTorch version: {torch.__version__}")
print(f"CUDA available: {torch.cuda.is_available()}")
print(f"cuDNN version: {torch.backends.cudnn.version()}")
device = torch.device("cuda:0")
# seems to trigger runtime compilation
batch, heads, seq_len, head_dim = 2, 32, 4096, 128
q = torch.randn(batch, heads, seq_len, head_dim, device=device, dtype=torch.bfloat16, requires_grad=True)
k = torch.randn(batch, heads, seq_len, head_dim, device=device, dtype=torch.bfloat16, requires_grad=True)
v = torch.randn(batch, heads, seq_len, head_dim, device=device, dtype=torch.bfloat16, requires_grad=True)
# causal mask + large seq len on an H100 triggers cudnn runtime compilation
try:
output = torch.nn.functional.scaled_dot_product_attention(
q, k, v,
attn_mask=None,
dropout_p=0.0,
is_causal=True, # triggers torch to compile a fused kernel
scale=None
)
loss = output.sum()
loss.backward()
print("compiled fused kernel!")
except RuntimeError as e:
print(f"failed to do sdpa: {e}")
if "libnvrtc" in str(e):
print("\n yayyyy we reproduced the issue!")Expected behaviour
we see "compiled fused kernel!" as in torch-bin
Screenshots
No response
Relevant log output
torch-bin
via nix-shell -p 'python3.withPackages (ps: [ps.torch-bin])' -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/c5ae371f1a6a7fd27823bc500d9390b38c05fa55.tar.gz --arg config '{ cudaSupport = true; allowUnfree = true; }'
(nix:nix-shell-env) ari@dell-h100-nj4-2:~/src/psyche$ python test.py
PyTorch version: 2.9.0+cu128
CUDA available: True
cuDNN version: 91300
compiled fused kernel!torch
via nix-shell -p 'python3.withPackages (ps: [ps.torch])' -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/c5ae371f1a6a7fd27823bc500d9390b38c05fa55.tar.gz --arg config '{ cudaSupport = true; allowUnfree = true; }'
(nix:nix-shell-env) ari@dell-h100-nj4-2:~/src/psyche$ python test.py
PyTorch version: 2.9.0
CUDA available: True
cuDNN version: 91300
failed to do sdpa: cuDNN Frontend error: No valid engine configs for Matmul_MUL_GEN_INDEX_GEN_INDEX_CMP_GE_BINARY_SELECT_Reduction_SUB_EXP_Reduction_LOG_ADD_DIV_Matmul_
{"engineId":2,"smVersion":900,"knobChoices":{"CUDNN_KNOB_TYPE_KERNEL_CFG":7}}
Warning: CUDNN_STATUS_NOT_SUPPORTED_RUNTIME_PREREQUISITE_MISSING; Reason: Could not open libnvrtc at: this->libnvrtc == nullptr
Warning: CUDNN_STATUS_NOT_SUPPORTED_RUNTIME_PREREQUISITE_MISSING; Reason: compiler.load()
Warning: CUDNN_STATUS_NOT_SUPPORTED_RUNTIME_PREREQUISITE_MISSING; Reason: rtk(kernelNumRunning)->loadDLL()
Warning: CUDNN_STATUS_NOT_SUPPORTED_RUNTIME_PREREQUISITE_MISSING; Reason: status == CUDNN_STATUS_NOT_SUPPORTED_RUNTIME_PREREQUISITE_MISSING
Warning: CUDNN_STATUS_NOT_SUPPORTED_RUNTIME_PREREQUISITE_MISSING; Reason: ptr->isSupported()
Warning: CUDNN_STATUS_NOT_SUPPORTED_RUNTIME_PREREQUISITE_MISSING; Reason: finalize_internal()
{"engineId":1,"smVersion":900,"knobChoices":{"CUDNN_KNOB_TYPE_KERNEL_CFG":3}}
Warning: CUDNN_STATUS_NOT_SUPPORTED_RUNTIME_PREREQUISITE_MISSING; Reason: Could not open libnvrtc at: this->libnvrtc == nullptr
Warning: CUDNN_STATUS_NOT_SUPPORTED_RUNTIME_PREREQUISITE_MISSING; Reason: compiler.load()
Warning: CUDNN_STATUS_NOT_SUPPORTED_RUNTIME_PREREQUISITE_MISSING; Reason: rtk(kernelNumRunning)->loadDLL()
Warning: CUDNN_STATUS_NOT_SUPPORTED_RUNTIME_PREREQUISITE_MISSING; Reason: status == CUDNN_STATUS_NOT_SUPPORTED_RUNTIME_PREREQUISITE_MISSING
Warning: CUDNN_STATUS_NOT_SUPPORTED_RUNTIME_PREREQUISITE_MISSING; Reason: ptr->isSupported()
Warning: CUDNN_STATUS_NOT_SUPPORTED_RUNTIME_PREREQUISITE_MISSING; Reason: finalize_internal()
yayyyy we reproduced the issue!Additional context
No response
System metadata
- system:
"x86_64-linux" - host os:
Linux 5.15.0-119-generic, Ubuntu, 22.04.4 LTS (Jammy Jellyfish), nobuild - multi-user?:
yes - sandbox:
yes - version:
nix-env (Nix) 2.24.6 - nixpkgs:
/nix/store/yff8cp4mrjrf71i1g9llxqpip8a6sfyj-source
Notify maintainers
@GaetanLepage @teh @thoughtpolice @tscholak
Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)
I assert that this issue is relevant for Nixpkgs
- I assert that this is a bug and not a support request.
- I assert that this is not a duplicate of an existing issue.
- I assert that I have read the NixOS Code of Conduct and agree to abide by it.
Is this issue important to you?
Add a 👍 reaction to issues you find important.
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fields✅ Done
Activity
ethernet8023 commentedon Nov 24, 2025
This is very related to, if not the exact same issue, as #296179
#315694 was designed to fix it, but somehow seems like it didn't.
SomeoneSerge commentedon Nov 24, 2025
Could it be it's libcudnn trying to load libnvrtc, and doing that before torch (which does know the location) has
Could you re-run your test with
LD_DEBUG=libs, and locate the "using DT_RUNPATH from ..." bit relating to the libnvrtc look-up? Tyethernet8023 commentedon Dec 10, 2025
I don't see any "using DT_RUNPATH from ..." in my output.
FWIW, this is running under nix-gl-host on ubuntu.
Here's all the logs from the
torchpackage: https://gist.github.com/arilotter/0993568341df8df1cc9aa422b6735cfdWhat seems to be of note is
surprisingly though, the torch-bin package does have the same error.
here's the output from the working torch-bin one: https://gist.github.com/arilotter/e10d3224745ebcc6ed8ceb27e7111b4d
SomeoneSerge commentedon Dec 10, 2025
The bit I was looking for is
RUNPATH from file /nix/store/.../lib/python3.13/site-packages/torch/lib/libtorch_global_deps.so. This should have contained the nvrtc directory and it doesn'tethernet8023 commentedon Dec 15, 2025
my understanding is that dlopen does not use the runpath of the caller library. so, when
libcudnn.socallsdlopen("libnvrtc.so.12"),it does not look at the runpath of
libtorch_cuda.sonorlibcudnn.so- so adding nvrtc to torch's runpath is a no-op and it only would work accidentally.doing a shell with
export LD_LIBRARY_PATH=${pkgs.lib.getLib pkgs.cudaPackages.cuda_nvrtc}/lib:$LD_LIBRARY_PATHwould work because dlopen always checksLD_LIBRARY_PATH.so, when python imports torch,
what we'd have to do somehow is modify python's runpath, not torch's.
i'm not sure if there's a nixpkgs mechanism to patch runpaths for dlopens like this - such that if we build a
python.withPackagesthat depends on atorchwe'd automatically propagate the runpath to the python binary? it seems.. very sketchy.SomeoneSerge commentedon Dec 16, 2025
No, cf. "
RUNPATH from ..."cudaPackages.cudnn: add nvrtc to runpath
cudaPackages.cudnn: add nvrtc to runpath
cudaPackages.cudnn: add nvrtc to runpath