RuntimeError: operator torchvision::nms does not exist
Your torch and torchvision versions do not match — usually one was upgraded without the other. Reinstall both together, in one command, from the same index.
Updated
The error
RuntimeError: operator torchvision::nms does not exist
Often preceded by the warning that explains everything:
UserWarning: Failed to load image Python extension: Could not find module ... Couldn't load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible.
What it means
torchvision ships compiled C++ operators — nms (non-maximum suppression, the box-deduplication step in object detection) is one of them. Those compiled ops are built against one exact PyTorch version. When the installed torch is a different version than the one torchvision was built for, the ops fail to register, and the first model that needs one crashes with this message.
This is a version mismatch, not a bug in your code.
Why it happens
Each torchvision release pairs with exactly one torch release. The pairing breaks easily:
pip install -U torchupgraded torch and left torchvision behind.- Installing some package pulled in a different torch as a dependency.
- torch came from one source (conda) and torchvision from another (pip).
- A CUDA build of one meets a CPU build of the other.
How to fix it
1. See what you have.
import torch, torchvision
print(torch.__version__, torchvision.__version__)2.8.0+cpu 0.19.0+cpu
torchvision 0.19 pairs with torch 2.4 — this pair is broken. The compatibility table lives in the torchvision README on GitHub.
2. Reinstall both together, one command, same index.
pip uninstall -y torch torchvision torchaudio
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126Use the exact command from the pytorch.org selector for your OS and CUDA version. Installing them in one command lets pip resolve the matching pair; add torchaudio if you use it, since it has the same pairing rule.
3. Never upgrade one of the family alone. If you need a newer torch, upgrade the trio in the same command. The same applies inside requirements files: pin them as a set.
4. In conda environments, pick one package manager for the trio. Mixing a conda torch with a pip torchvision reintroduces the mismatch through the back door. If the environment history is murky, a fresh environment is faster than archaeology.
How to prevent it
Treat torch, torchvision and torchaudio as one unit everywhere: install together, pin together, upgrade together. After any environment change, the two-line version print above is the fastest health check — do it before launching a long training run.
Related errors
- torch.cuda.is_available() returns False — often caused by the same accidental reinstall
- no kernel image is available for execution
- A module compiled using NumPy 1.x cannot be run in NumPy 2 — the same disease between other libraries