RuntimeError: operator torchvision::nms does not exist (fix)
import torchvision fails with RuntimeError: operator torchvision::nms does not exist, or the process just crashes. We reproduced both with mismatched torch/torchvision pairs and a CPU/CUDA mix, then fixed them.
1. Reproducing it
A test that prints what pip thinks is installed, then imports torchvision:
import importlib.metadata as m
print("torch", m.version("torch"), "| torchvision", m.version("torchvision"))
import torchvision
print("imported torchvision", torchvision.__version__)
torch 2.8.0 with torchvision 0.24.0 (0.24 is built for torch 2.9; traceback without source lines):
torch 2.8.0+cpu | torchvision 0.24.0+cpu
Traceback (most recent call last):
File "b1.py", line 3, in <module>
File ".../site-packages/torchvision/__init__.py", line 10, in <module>
File ".../site-packages/torchvision/_meta_registrations.py", line 163, in <module>
File ".../site-packages/torch/library.py", line 1069, in register
File ".../site-packages/torch/library.py", line 219, in _register_fake
File ".../site-packages/torch/_library/fake_impl.py", line 50, in register
RuntimeError: operator torchvision::nms does not exist
Same version, different build: torch 2.8.0+cpu with the PyPI torchvision 0.23.0 wheel (a CUDA cu128 build) gave the identical error:
torch 2.8.0+cpu | torchvision 0.23.0
Traceback (most recent call last):
File "b1.py", line 3, in <module>
File ".../site-packages/torchvision/__init__.py", line 10, in <module>
File ".../site-packages/torchvision/_meta_registrations.py", line 163, in <module>
File ".../site-packages/torch/library.py", line 1069, in register
File ".../site-packages/torch/library.py", line 219, in _register_fake
File ".../site-packages/torch/_library/fake_impl.py", line 50, in register
RuntimeError: operator torchvision::nms does not exist
torch 2.9.0 with torchvision 0.23.0 (older torchvision on newer torch) raised nothing. The process died while loading torchvision's C++ extension: three runs gave exit 139 (segmentation fault), 134 (aborted) and 139. With python -X faulthandler (trimmed):
torch 2.9.0+cpu | torchvision 0.23.0+cpu
Fatal Python error: Segmentation fault
Current thread 0x00007f19c1ef8740 (most recent call first):
File ".../ctypes/__init__.py", line 376 in __init__
File ".../site-packages/torch/_ops.py", line 1488 in load_library
File ".../site-packages/torchvision/extension.py", line 34 in <module>
...
File "b1.py", line 3 in <module>
Extension modules: numpy..., torch._C, ... (total: 13)
exit 139
The cause in every case: torchvision's compiled ops library must match the exact torch build. When it can't be loaded, torchvision::nms is never registered, and torchvision/_meta_registrations.py, which registers a fake implementation for it with @torch.library.register_fake("torchvision::nms"), raises operator torchvision::nms does not exist.
2. Check the pair without importing torchvision
Importing is what fails (or crashes), so read the metadata and torchvision's version file, which keeps the +cpu/+cu128 tag:
# Diagnose without importing torchvision: versions AND build tags must match
import importlib.metadata as m, importlib.util, pathlib, torch
need = [r for r in (m.requires("torchvision") or []) if r.startswith("torch")]
print("torchvision requires:", need)
ta_dir = pathlib.Path(importlib.util.find_spec("torchvision").origin).parent
print("torchvision build:", (ta_dir / "version.py").read_text().splitlines()[0])
print("torch build: ", torch.__version__, "| CUDA:", torch.version.cuda)
CPU torch with the CUDA torchvision wheel:
torchvision requires: ['torch (==2.8.0)']
torchvision build: __version__ = '0.23.0+cu128'
torch build: 2.8.0+cpu | CUDA: None
torch 2.9.0 with torchvision 0.23.0:
torchvision requires: ['torch (==2.8.0)']
torchvision build: __version__ = '0.23.0+cpu'
torch build: 2.9.0+cpu | CUDA: None
The version must be the one torchvision requires (0.23 needs torch 2.8.0, 0.24 needs 2.9.0) and the tags must agree; CUDA: None means you need a +cpu torchvision. pip check only catches the version case:
torchvision 0.23.0+cpu has requirement torch==2.8.0, but you have torch 2.9.0+cpu.
For the CPU/CUDA mix it printed No broken requirements found.
3. Fix: force-reinstall the matching torchvision
Install the torchvision that pairs with your torch, from the index that matches its build tag. For torch 2.9.0+cpu:
pip install --force-reinstall --no-deps torchvision==0.24.0 --index-url https://download.pytorch.org/whl/cpu
After that, b1.py and b2.py:
torch 2.9.0+cpu | torchvision 0.24.0+cpu
imported torchvision 0.24.0+cpu
torchvision requires: ['torch (==2.9.0)']
torchvision build: __version__ = '0.24.0+cpu'
torch build: 2.9.0+cpu | CUDA: None
and the op that was "missing" works:
import torch, torchvision
boxes = torch.tensor([[0., 0, 10, 10], [1, 1, 11, 11], [50, 50, 60, 60]])
scores = torch.tensor([0.9, 0.8, 0.7])
print(torchvision.ops.nms(boxes, scores, iou_threshold=0.5))
tensor([0, 2])
The CPU/CUDA mix was fixed the same way with torchvision==0.23.0 from /whl/cpu (imported torchvision 0.23.0+cpu). Use --force-reinstall: a CUDA build already counts as ==0.23.0, so a plain install can leave it in place (that is what happened in our torchaudio test). On a CUDA torch, put its tag in the URL instead (e.g. /whl/cu128). If you'd rather move torch, reinstall torch and torchvision together in one command from one index.
Related: torchaudio libtorchaudio.so undefined symbol (the same mismatch for torchaudio) · Could not load libtorchcodec · torch.load Weights only load failed
Frequently asked questions
What causes operator torchvision::nms does not exist?
torchvision was built for a different torch than the one installed (torchvision 0.24 needs torch 2.9.0, 0.23 needs 2.8.0), or a CUDA torchvision is paired with a CPU torch. Its C++ ops fail to load, so nms is never registered.
Why does import torchvision segfault?
In our test an older torchvision (0.23.0) on a newer torch (2.9.0) crashed with exit 139/134 while loading its extension. Install the torchvision version that matches torch.
Written with AI assistance. Measured on 2026-10-24 on Linux with CPython 3.11.17, torch 2.8.0/2.9.0 CPU wheels, torchvision 0.23.0/0.24.0 CPU wheels and the PyPI torchvision 0.23.0 (cu128) wheel. Output pasted unedited except shortened paths and trimmed tracebacks. PlainTables is our extension; torch and torchvision are free.