CUDA error: no kernel image is available for execution on the device
Your PyTorch build does not include compiled code for your GPU's generation — typically a brand-new GPU with an older PyTorch. Install the build made for a CUDA version that supports your card.
Updated
The error
RuntimeError: CUDA error: no kernel image is available for execution on the device
Frequently, a warning earlier in the output already gave the diagnosis:
UserWarning: NVIDIA GeForce RTX 5090 with CUDA capability sm_120 is not compatible with the current PyTorch installation. The current PyTorch install supports CUDA capabilities sm_50 sm_60 sm_70 sm_75 sm_80 sm_86 sm_90.
What it means
Every NVIDIA GPU generation has a compute capability — an architecture code like sm_86 (RTX 30 series) or sm_120 (RTX 50 series). PyTorch wheels ship compiled GPU code for a fixed list of capabilities. Your GPU's code is not on the installed build's list, so there is no machine code the GPU can run. The card is detected, memory can even be allocated — and the first real computation fails.
Why it happens
Two mirror-image cases:
- New GPU, older PyTorch. A new architecture needs a PyTorch built against a new enough CUDA toolkit. RTX 50-series (Blackwell) cards need builds targeting CUDA 12.8 or newer; older wheels know nothing of sm_120.
- Old GPU, newer PyTorch. Support for old architectures gets dropped over time. A Kepler or Maxwell card that ran fine years ago is absent from current wheels.
A stale environment does the same: the wheel you installed in January does not cover the GPU you bought in June.
How to fix it
1. Establish both sides of the mismatch.
import torch
print(torch.cuda.get_device_name(0))
print(torch.cuda.get_device_capability(0)) # e.g. (12, 0) -> sm_120
print(torch.cuda.get_arch_list()) # what this build supportsIf the capability is missing from the arch list, the diagnosis is confirmed.
2. For a new GPU, install the newest matching build. Use the selector on pytorch.org and pick the newest CUDA variant offered:
pip uninstall -y torch torchvision torchaudio
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128If the stable release does not cover your card yet, the nightly build usually does — the selector has a Nightly option.
3. Update the NVIDIA driver at the same time. A new-generation card also needs a recent driver; check nvidia-smi runs and shows a current version.
4. For an old GPU dropped from current wheels, install an older PyTorch. Find the last release that lists your sm code, and pin it. Accept the trade-off consciously: old PyTorch means old everything downstream.
5. Building from source is the escape hatch for unusual combinations — set TORCH_CUDA_ARCH_LIST to your capability. It is slow but unblocks cards the wheels ignore.
How to prevent it
When you get a new GPU, plan a PyTorch reinstall as part of the setup — wheels are architecture-specific in a way most Python packages are not. After every reinstall, run the three-line check from fix 1 plus one small matrix multiply on cuda before starting real work.