From 69146fe3d741b70ee4f09385cb2d22218b0d30a5 Mon Sep 17 00:00:00 2001 From: pc Date: Fri, 11 Jun 2021 16:30:39 +0800 Subject: [PATCH] add load_ext warning (#1089) --- mmcv/utils/ext_loader.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mmcv/utils/ext_loader.py b/mmcv/utils/ext_loader.py index a894132ac..2a3c22383 100644 --- a/mmcv/utils/ext_loader.py +++ b/mmcv/utils/ext_loader.py @@ -1,6 +1,7 @@ import importlib import os import pkgutil +import warnings from collections import namedtuple import torch @@ -14,6 +15,7 @@ if torch.__version__ != 'parrots': return ext else: from parrots import extension + from parrots.base import ParrotsException has_return_value_ops = [ 'nms', @@ -33,11 +35,11 @@ else: 'ms_deform_attn_forward', ] - def get_fake_func(name): + def get_fake_func(name, e): def fake_func(*args, **kwargs): - raise RuntimeError( - '{} is not supported in parrots now'.format(name)) + warnings.warn(f'{name} is not supported in parrots now') + raise e return fake_func @@ -48,8 +50,10 @@ else: for fun in funcs: try: ext_fun = extension.load(fun, name, lib_dir=lib_root) - except Exception: - ext_fun = get_fake_func(fun) + except ParrotsException as e: + if 'No element registered' not in e.message: + warnings.warn(e.message) + ext_fun = get_fake_func(fun, e) ext_list.append(ext_fun) else: if fun in has_return_value_ops: