Skip to content

Improve error when torchvision C++ ops fail to load - #9649

Open
YeonwooSung wants to merge 1 commit into
pytorch:mainfrom
YeonwooSung:fix/nms-missing-op-error-9337
Open

Improve error when torchvision C++ ops fail to load#9649
YeonwooSung wants to merge 1 commit into
pytorch:mainfrom
YeonwooSung:fix/nms-missing-op-error-9337

Conversation

@YeonwooSung

Copy link
Copy Markdown

Summary

Importing an unbuilt torchvision source tree (or a broken / ABI-mismatched wheel) currently fails at import time with:

RuntimeError: operator torchvision::nms does not exist

This happens because _meta_registrations.py registers fake kernels for torchvision::nms / torchvision::qnms unconditionally. torch.library.register_fake requires the C++ operator to already exist, so the failure happens before nms() can reach _assert_has_ops().

_load_library() also swallowed ImportError / OSError and returned False, so the original missing .so / wheel-mismatch reason was lost.

Changes

  • Guard register_fake for nms / qnms with torchvision.extension._has_ops(), matching register_meta. Importing torchvision without compiled ops now succeeds; calling nms() then hits _assert_has_ops().
  • Cache the extension load exception as _EXTENSION_LOAD_ERROR (preferring the _C_stable error so a later optional-extension failure does not hide it) and include it in _assert_has_ops().
  • Add hermetic tests in test/test_extension.py covering the cached load error, _assert_has_ops() message, and the register_fake guard.

Fixes #9337

Skip register_fake for nms/qnms when compiled ops are missing so
importing an unbuilt source tree no longer fails with
"operator torchvision::nms does not exist". Cache the extension load
exception and include it in _assert_has_ops().

Fixes pytorch#9337
@pytorch-bot

pytorch-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9649

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make "RuntimeError: operator torchvision::nms does not exist" error better

1 participant