From 16c082880456096782886bfdb8d903acf566a319 Mon Sep 17 00:00:00 2001 From: YiyaoYang1 Date: Wed, 25 Oct 2023 16:07:14 +0800 Subject: [PATCH 01/14] improve error handling and faq.md --- docs/en/faq.md | 7 ++++++- docs/zh_cn/faq.md | 7 ++++++- mmcv/ops/csrc/common/pytorch_device_registry.hpp | 2 +- mmcv/utils/ext_loader.py | 9 ++++++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/en/faq.md b/docs/en/faq.md index 02d31c233a..3e68f6ab0a 100644 --- a/docs/en/faq.md +++ b/docs/en/faq.md @@ -10,7 +10,7 @@ Feel free to enrich the list if you find any frequent issues and have ways to he The registry mechanism will be triggered only when the file of the module is imported. So you need to import that file somewhere. More details can be found at [KeyError: "MaskRCNN: 'RefineRoIHead is not in the models registry'"](https://github.com/open-mmlab/mmdetection/issues/5974). -- "No module named 'mmcv.ops'"; "No module named 'mmcv.\_ext'" +- "No module named 'mmcv.ops'"; "No module named 'mmcv.\_ext'"; "ImportError: DLL load failed while importing \_ext" 1. Uninstall existing mmcv in the environment using `pip uninstall mmcv` 2. Install mmcv-full following the [installation instruction](https://mmcv.readthedocs.io/en/latest/get_started/installation.html) or [Build MMCV from source](https://mmcv.readthedocs.io/en/latest/get_started/build.html) @@ -91,3 +91,8 @@ Feel free to enrich the list if you find any frequent issues and have ways to he - "RuntimeError: Trying to backward through the graph a second time" `GradientCumulativeOptimizerHook` and `OptimizerHook` are both set which causes the `loss.backward()` to be called twice so `RuntimeError` was raised. We can only use one of these. More datails at [Trying to backward through the graph a second time](https://github.com/open-mmlab/mmcv/issues/1379). + +- "RuntimeError: xxx: implementation for device cuda:0 not found." + + This error indicates that maybe mmcv was not installed with cuda op support. You can uninstall and install with `pip install mmcv==2.1.0 -f https://download.openmmlab.com/mmcv/dist/cu121/torch2.1/index.html`. + \ No newline at end of file diff --git a/docs/zh_cn/faq.md b/docs/zh_cn/faq.md index 6cfb100c63..6ff0d13bb5 100644 --- a/docs/zh_cn/faq.md +++ b/docs/zh_cn/faq.md @@ -9,7 +9,7 @@ 只有模块所在的文件被导入时,注册机制才会被触发,所以您需要在某处导入该文件,更多详情请查看 [KeyError: "MaskRCNN: 'RefineRoIHead is not in the models registry'"](https://github.com/open-mmlab/mmdetection/issues/5974)。 -- "No module named 'mmcv.ops'"; "No module named 'mmcv.\_ext'" +- "No module named 'mmcv.ops'"; "No module named 'mmcv.\_ext'"; "ImportError: DLL load failed while importing \_ext" 1. 使用 `pip uninstall mmcv` 卸载您环境中的 mmcv 2. 参考 [installation instruction](https://mmcv.readthedocs.io/en/latest/get_started/installation.html) 或者 [Build MMCV from source](https://mmcv.readthedocs.io/en/latest/get_started/build.html) 安装 mmcv-full @@ -89,3 +89,8 @@ - "RuntimeError: Trying to backward through the graph a second time" 不能同时设置 `GradientCumulativeOptimizerHook` 和 `OptimizerHook`,这会导致 `loss.backward()` 被调用两次,于是程序抛出 `RuntimeError`。我们只需设置其中的一个。更多细节见 [Trying to backward through the graph a second time](https://github.com/open-mmlab/mmcv/issues/1379)。 + +- "RuntimeError: xxx: implementation for device cuda:0 not found." + + 这个错误是因为mmcv可能没有安装cuda-op支持。您可以卸载mmcv并使用以下命令进行安装`pip install mmcv==2.1.0 -f https://download.openmmlab.com/mmcv/dist/cu121/torch2.1/index.html`。 + \ No newline at end of file diff --git a/mmcv/ops/csrc/common/pytorch_device_registry.hpp b/mmcv/ops/csrc/common/pytorch_device_registry.hpp index 2a32b7270c..6ca3a90426 100644 --- a/mmcv/ops/csrc/common/pytorch_device_registry.hpp +++ b/mmcv/ops/csrc/common/pytorch_device_registry.hpp @@ -119,7 +119,7 @@ auto Dispatch(const R& registry, const char* name, Args&&... args) { " vs ", GetDeviceStr(device).c_str(), "\n") auto f_ptr = registry.Find(device.type()); TORCH_CHECK(f_ptr != nullptr, name, ": implementation for device ", - GetDeviceStr(device).c_str(), " not found.\n") + GetDeviceStr(device).c_str(), " not found.\n", "For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md \n") return f_ptr(std::forward(args)...); } diff --git a/mmcv/utils/ext_loader.py b/mmcv/utils/ext_loader.py index a31e107dfe..c38986ce6f 100644 --- a/mmcv/utils/ext_loader.py +++ b/mmcv/utils/ext_loader.py @@ -10,7 +10,14 @@ if torch.__version__ != 'parrots': def load_ext(name, funcs): - ext = importlib.import_module('mmcv.' + name) + try: + ext = importlib.import_module('mmcv.' + name) + except ImportError: + print("Check whether the CUDA/GCC runtimes are the same as those used for compiling mmcv") + print("For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md") + except ModuleNotFoundError: + print("try re-installing mmcv with specific version") + print("For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md") for fun in funcs: assert hasattr(ext, fun), f'{fun} miss in module {name}' return ext From 6722cc6b2171830032ed031612f0fca4cbda9898 Mon Sep 17 00:00:00 2001 From: YiyaoYang1 Date: Fri, 27 Oct 2023 15:38:53 +0800 Subject: [PATCH 02/14] improve raise error --- mmcv/utils/ext_loader.py | 45 ++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/mmcv/utils/ext_loader.py b/mmcv/utils/ext_loader.py index c38986ce6f..bc63c5cb4f 100644 --- a/mmcv/utils/ext_loader.py +++ b/mmcv/utils/ext_loader.py @@ -9,15 +9,48 @@ if torch.__version__ != 'parrots': + class ext_ImportError(Exception): + def __init__(self, arg): + print(arg) + print("mmcv is installed incorrectly.") + print("1. Uninstall existing mmcv in the environment using `pip uninstall mmcv`") + print("2. Install mmcv-full following the https://mmcv.readthedocs.io/en/latest/get_started/installation.html or https://mmcv.readthedocs.io/en/latest/get_started/build.html") + print("For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md") + + class undefine_symbol_Error(Exception): + def __init__(self, arg): + print(arg) + print("If those symbols are CUDA/C++ symbols (e.g., libcudart.so or GLIBCXX), check whether the CUDA/GCC runtimes are the same as those used for compiling mmcv") + print("If those symbols are Pytorch symbols (e.g., symbols containing caffe, aten, and TH), check whether the Pytorch version is the same as that used for compiling mmcv") + print("For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md") + + class ext_not_found_Error(Exception): + def __init__(self, arg): + print(arg) + print("mmcv is installed incorrectly.") + print("1. Uninstall existing mmcv in the environment using `pip uninstall mmcv`") + print("2. Install mmcv-full following the https://mmcv.readthedocs.io/en/latest/get_started/installation.html or https://mmcv.readthedocs.io/en/latest/get_started/build.html") + print("For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md") + def load_ext(name, funcs): + import re try: ext = importlib.import_module('mmcv.' + name) - except ImportError: - print("Check whether the CUDA/GCC runtimes are the same as those used for compiling mmcv") - print("For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md") - except ModuleNotFoundError: - print("try re-installing mmcv with specific version") - print("For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md") + except Exception, e: + exception_inf = str(e) + + pattern = "DLL load failed while importing _ext" + if re.search(pattern, exception_inf, re.S): + raise ext_ImportError(exception_inf) + + pattern = "undefined symbol" + if re.search(pattern, exception_inf, re.S): + raise undefine_symbol_Error(exception_inf) + + pattern = "No module named 'mmcv._ext'" + if re.search(pattern, exception_inf, re.S): + raise ext_not_found_Error(exception_inf) + for fun in funcs: assert hasattr(ext, fun), f'{fun} miss in module {name}' return ext From 864e316cf982485c33df3a3b3bd95f31e2df726a Mon Sep 17 00:00:00 2001 From: YiyaoYang1 Date: Fri, 27 Oct 2023 16:04:02 +0800 Subject: [PATCH 03/14] fix invalid synax --- mmcv/utils/ext_loader.py | 47 +++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/mmcv/utils/ext_loader.py b/mmcv/utils/ext_loader.py index bc63c5cb4f..dd441e94f0 100644 --- a/mmcv/utils/ext_loader.py +++ b/mmcv/utils/ext_loader.py @@ -10,47 +10,60 @@ if torch.__version__ != 'parrots': class ext_ImportError(Exception): + def __init__(self, arg): print(arg) - print("mmcv is installed incorrectly.") - print("1. Uninstall existing mmcv in the environment using `pip uninstall mmcv`") - print("2. Install mmcv-full following the https://mmcv.readthedocs.io/en/latest/get_started/installation.html or https://mmcv.readthedocs.io/en/latest/get_started/build.html") - print("For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md") - + print('mmcv is installed incorrectly.') + print('1. Uninstall existing mmcv') + print('2. Install mmcv-full') + print( + 'For more information, see', + 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md') + class undefine_symbol_Error(Exception): + def __init__(self, arg): print(arg) - print("If those symbols are CUDA/C++ symbols (e.g., libcudart.so or GLIBCXX), check whether the CUDA/GCC runtimes are the same as those used for compiling mmcv") - print("If those symbols are Pytorch symbols (e.g., symbols containing caffe, aten, and TH), check whether the Pytorch version is the same as that used for compiling mmcv") - print("For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md") + print('For CUDA/C++ symbols, ', + 'check whether the CUDA/GCC runtimes are the same', + 'as those used for compiling mmcv') + print('For Pytorch symbols, ', + 'check whether the Pytorch version is the same', + 'as that used for compiling mmcv') + print( + 'For more information, see', + 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md') class ext_not_found_Error(Exception): + def __init__(self, arg): print(arg) - print("mmcv is installed incorrectly.") - print("1. Uninstall existing mmcv in the environment using `pip uninstall mmcv`") - print("2. Install mmcv-full following the https://mmcv.readthedocs.io/en/latest/get_started/installation.html or https://mmcv.readthedocs.io/en/latest/get_started/build.html") - print("For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md") + print('mmcv is installed incorrectly.') + print('1. Uninstall existing mmcv') + print('2. Install mmcv-full') + print( + 'For more information, see', + 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md') def load_ext(name, funcs): import re try: ext = importlib.import_module('mmcv.' + name) - except Exception, e: + except Exception as e: exception_inf = str(e) - pattern = "DLL load failed while importing _ext" + pattern = 'DLL load failed while importing _ext' if re.search(pattern, exception_inf, re.S): raise ext_ImportError(exception_inf) - - pattern = "undefined symbol" + + pattern = 'undefined symbol' if re.search(pattern, exception_inf, re.S): raise undefine_symbol_Error(exception_inf) pattern = "No module named 'mmcv._ext'" if re.search(pattern, exception_inf, re.S): raise ext_not_found_Error(exception_inf) - + for fun in funcs: assert hasattr(ext, fun), f'{fun} miss in module {name}' return ext From c7cc6d0e5cf15992e54d039777c66e111de2c22e Mon Sep 17 00:00:00 2001 From: YiyaoYang1 Date: Fri, 27 Oct 2023 16:09:21 +0800 Subject: [PATCH 04/14] fix invalid synax --- mmcv/ops/csrc/common/pytorch_device_registry.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmcv/ops/csrc/common/pytorch_device_registry.hpp b/mmcv/ops/csrc/common/pytorch_device_registry.hpp index 6ca3a90426..a6a7ff1720 100644 --- a/mmcv/ops/csrc/common/pytorch_device_registry.hpp +++ b/mmcv/ops/csrc/common/pytorch_device_registry.hpp @@ -119,7 +119,7 @@ auto Dispatch(const R& registry, const char* name, Args&&... args) { " vs ", GetDeviceStr(device).c_str(), "\n") auto f_ptr = registry.Find(device.type()); TORCH_CHECK(f_ptr != nullptr, name, ": implementation for device ", - GetDeviceStr(device).c_str(), " not found.\n", "For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md \n") + GetDeviceStr(device).c_str(), " not found.\n", "mmcv was not installed with cuda op support.\n", "For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md \n") return f_ptr(std::forward(args)...); } From 83eddb3492c244e9f2a559a4057363ec36d4cd71 Mon Sep 17 00:00:00 2001 From: YiyaoYang1 Date: Fri, 27 Oct 2023 16:27:47 +0800 Subject: [PATCH 05/14] fix invalid synax --- docs/en/faq.md | 1 - docs/zh_cn/faq.md | 1 - 2 files changed, 2 deletions(-) diff --git a/docs/en/faq.md b/docs/en/faq.md index 3e68f6ab0a..4b7412651e 100644 --- a/docs/en/faq.md +++ b/docs/en/faq.md @@ -95,4 +95,3 @@ Feel free to enrich the list if you find any frequent issues and have ways to he - "RuntimeError: xxx: implementation for device cuda:0 not found." This error indicates that maybe mmcv was not installed with cuda op support. You can uninstall and install with `pip install mmcv==2.1.0 -f https://download.openmmlab.com/mmcv/dist/cu121/torch2.1/index.html`. - \ No newline at end of file diff --git a/docs/zh_cn/faq.md b/docs/zh_cn/faq.md index 6ff0d13bb5..0b4121d12d 100644 --- a/docs/zh_cn/faq.md +++ b/docs/zh_cn/faq.md @@ -93,4 +93,3 @@ - "RuntimeError: xxx: implementation for device cuda:0 not found." 这个错误是因为mmcv可能没有安装cuda-op支持。您可以卸载mmcv并使用以下命令进行安装`pip install mmcv==2.1.0 -f https://download.openmmlab.com/mmcv/dist/cu121/torch2.1/index.html`。 - \ No newline at end of file From f3b232f73b7573820442bab34dd2e527d3de6157 Mon Sep 17 00:00:00 2001 From: YiyaoYang1 Date: Mon, 30 Oct 2023 14:58:10 +0800 Subject: [PATCH 06/14] fix print --- .../csrc/common/pytorch_device_registry.hpp | 2 +- mmcv/utils/ext_loader.py | 49 ++++++++++--------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/mmcv/ops/csrc/common/pytorch_device_registry.hpp b/mmcv/ops/csrc/common/pytorch_device_registry.hpp index a6a7ff1720..6ca3a90426 100644 --- a/mmcv/ops/csrc/common/pytorch_device_registry.hpp +++ b/mmcv/ops/csrc/common/pytorch_device_registry.hpp @@ -119,7 +119,7 @@ auto Dispatch(const R& registry, const char* name, Args&&... args) { " vs ", GetDeviceStr(device).c_str(), "\n") auto f_ptr = registry.Find(device.type()); TORCH_CHECK(f_ptr != nullptr, name, ": implementation for device ", - GetDeviceStr(device).c_str(), " not found.\n", "mmcv was not installed with cuda op support.\n", "For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md \n") + GetDeviceStr(device).c_str(), " not found.\n", "For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md \n") return f_ptr(std::forward(args)...); } diff --git a/mmcv/utils/ext_loader.py b/mmcv/utils/ext_loader.py index dd441e94f0..34d0a512d0 100644 --- a/mmcv/utils/ext_loader.py +++ b/mmcv/utils/ext_loader.py @@ -9,41 +9,44 @@ if torch.__version__ != 'parrots': - class ext_ImportError(Exception): + class ExtImportError(Exception): def __init__(self, arg): print(arg) - print('mmcv is installed incorrectly.') - print('1. Uninstall existing mmcv') - print('2. Install mmcv-full') print( + 'mmcv is installed incorrectly.', + '1. Uninstall existing mmcv', + '2. Install mmcv-full', 'For more information, see', - 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md') + 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md', + sep='\n') - class undefine_symbol_Error(Exception): + class UndefineSymbolError(Exception): def __init__(self, arg): print(arg) - print('For CUDA/C++ symbols, ', - 'check whether the CUDA/GCC runtimes are the same', - 'as those used for compiling mmcv') - print('For Pytorch symbols, ', - 'check whether the Pytorch version is the same', - 'as that used for compiling mmcv') print( - 'For more information, see', - 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md') - - class ext_not_found_Error(Exception): + '1. For CUDA/C++ symbols, ' + 'check whether the CUDA/GCC runtimes are the same ' + 'as those used for compiling mmcv. ', + '2. For Pytorch symbols, ' + 'check whether the Pytorch version is the same ' + 'as that used for compiling mmcv.', + 'For more information, see ' + 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md', + sep='\n') + + class ExtNotFoundError(Exception): def __init__(self, arg): print(arg) - print('mmcv is installed incorrectly.') - print('1. Uninstall existing mmcv') - print('2. Install mmcv-full') print( + 'mmcv is installed incorrectly.', + '1. Uninstall existing mmcv', + '2. Install mmcv-full', 'For more information, see', - 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md') + 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md', + sep='\n') def load_ext(name, funcs): import re @@ -54,15 +57,15 @@ def load_ext(name, funcs): pattern = 'DLL load failed while importing _ext' if re.search(pattern, exception_inf, re.S): - raise ext_ImportError(exception_inf) + raise ExtImportError(exception_inf) pattern = 'undefined symbol' if re.search(pattern, exception_inf, re.S): - raise undefine_symbol_Error(exception_inf) + raise UndefineSymbolError(exception_inf) pattern = "No module named 'mmcv._ext'" if re.search(pattern, exception_inf, re.S): - raise ext_not_found_Error(exception_inf) + raise ExtNotFoundError(exception_inf) for fun in funcs: assert hasattr(ext, fun), f'{fun} miss in module {name}' From 6413df68569824a454b12bc5213b28af3b4b9407 Mon Sep 17 00:00:00 2001 From: YiyaoYang1 Date: Mon, 30 Oct 2023 15:12:30 +0800 Subject: [PATCH 07/14] ext_loader no change --- mmcv/utils/ext_loader.py | 58 +--------------------------------------- 1 file changed, 1 insertion(+), 57 deletions(-) diff --git a/mmcv/utils/ext_loader.py b/mmcv/utils/ext_loader.py index 34d0a512d0..a31e107dfe 100644 --- a/mmcv/utils/ext_loader.py +++ b/mmcv/utils/ext_loader.py @@ -9,64 +9,8 @@ if torch.__version__ != 'parrots': - class ExtImportError(Exception): - - def __init__(self, arg): - print(arg) - print( - 'mmcv is installed incorrectly.', - '1. Uninstall existing mmcv', - '2. Install mmcv-full', - 'For more information, see', - 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md', - sep='\n') - - class UndefineSymbolError(Exception): - - def __init__(self, arg): - print(arg) - print( - '1. For CUDA/C++ symbols, ' - 'check whether the CUDA/GCC runtimes are the same ' - 'as those used for compiling mmcv. ', - '2. For Pytorch symbols, ' - 'check whether the Pytorch version is the same ' - 'as that used for compiling mmcv.', - 'For more information, see ' - 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md', - sep='\n') - - class ExtNotFoundError(Exception): - - def __init__(self, arg): - print(arg) - print( - 'mmcv is installed incorrectly.', - '1. Uninstall existing mmcv', - '2. Install mmcv-full', - 'For more information, see', - 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md', - sep='\n') - def load_ext(name, funcs): - import re - try: - ext = importlib.import_module('mmcv.' + name) - except Exception as e: - exception_inf = str(e) - - pattern = 'DLL load failed while importing _ext' - if re.search(pattern, exception_inf, re.S): - raise ExtImportError(exception_inf) - - pattern = 'undefined symbol' - if re.search(pattern, exception_inf, re.S): - raise UndefineSymbolError(exception_inf) - - pattern = "No module named 'mmcv._ext'" - if re.search(pattern, exception_inf, re.S): - raise ExtNotFoundError(exception_inf) - + ext = importlib.import_module('mmcv.' + name) for fun in funcs: assert hasattr(ext, fun), f'{fun} miss in module {name}' return ext From 156e044090b65224eab6ce413812f70270734993 Mon Sep 17 00:00:00 2001 From: YiyaoYang1 Date: Mon, 30 Oct 2023 15:37:43 +0800 Subject: [PATCH 08/14] ext_loader no change --- mmcv/utils/ext_loader.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mmcv/utils/ext_loader.py b/mmcv/utils/ext_loader.py index a31e107dfe..c2824e8edb 100644 --- a/mmcv/utils/ext_loader.py +++ b/mmcv/utils/ext_loader.py @@ -10,7 +10,10 @@ if torch.__version__ != 'parrots': def load_ext(name, funcs): - ext = importlib.import_module('mmcv.' + name) + try: + ext = importlib.import_module('mmcv.' + name) + except Exception: + raise RuntimeError for fun in funcs: assert hasattr(ext, fun), f'{fun} miss in module {name}' return ext From 7b84cea54c3585c01fde8c82bda0e62c7d75eca2 Mon Sep 17 00:00:00 2001 From: YiyaoYang1 Date: Mon, 30 Oct 2023 15:45:53 +0800 Subject: [PATCH 09/14] ext_loader no change --- mmcv/utils/ext_loader.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mmcv/utils/ext_loader.py b/mmcv/utils/ext_loader.py index c2824e8edb..a31e107dfe 100644 --- a/mmcv/utils/ext_loader.py +++ b/mmcv/utils/ext_loader.py @@ -10,10 +10,7 @@ if torch.__version__ != 'parrots': def load_ext(name, funcs): - try: - ext = importlib.import_module('mmcv.' + name) - except Exception: - raise RuntimeError + ext = importlib.import_module('mmcv.' + name) for fun in funcs: assert hasattr(ext, fun), f'{fun} miss in module {name}' return ext From 22a865c0663bac346b48cf816a33fb6348d4361e Mon Sep 17 00:00:00 2001 From: YiyaoYang1 Date: Mon, 30 Oct 2023 17:02:50 +0800 Subject: [PATCH 10/14] add subclass of ImportError --- mmcv/utils/ext_loader.py | 69 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/mmcv/utils/ext_loader.py b/mmcv/utils/ext_loader.py index a31e107dfe..820e049e78 100644 --- a/mmcv/utils/ext_loader.py +++ b/mmcv/utils/ext_loader.py @@ -8,9 +8,76 @@ import torch if torch.__version__ != 'parrots': + """Three subclasses of ImportError are defined in order to help users solve + the following errors. + + 1. DLL load failed while importing _ext + https://github.com/open-mmlab/mmcv/issues/2937 + + 2. undefined symbol + https://github.com/open-mmlab/mmcv/issues/2904 + + 3. No module named 'mmcv._ext' + https://github.com/open-mmlab/mmcv/issues/2929 + """ + + class ExtImportError(ImportError): + + def __init__(self, arg): + print(arg) + print( + 'mmcv is installed incorrectly.', + '1. Uninstall existing mmcv', + '2. Install mmcv-full', + 'For more information, see', + 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md', + sep='\n') + + class UndefineSymbolError(ImportError): + + def __init__(self, arg): + print(arg) + print( + '1. For CUDA/C++ symbols, ' + 'check whether the CUDA/GCC runtimes are the same ' + 'as those used for compiling mmcv. ', + '2. For Pytorch symbols, ' + 'check whether the Pytorch version is the same ' + 'as that used for compiling mmcv.', + 'For more information, see ' + 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md', + sep='\n') + + class ExtNotFoundError(ImportError): + + def __init__(self, arg): + print(arg) + print( + 'mmcv is installed incorrectly.', + '1. Uninstall existing mmcv', + '2. Install mmcv-full', + 'For more information, see', + 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md', + sep='\n') def load_ext(name, funcs): - ext = importlib.import_module('mmcv.' + name) + try: + ext = importlib.import_module('mmcv.' + name) + except Exception as e: + exception_inf = str(e) + + message_error = 'DLL load failed while importing _ext' + if message_error in exception_inf: + raise ExtImportError(exception_inf) + + message_error = 'undefined symbol' + if message_error in exception_inf: + raise UndefineSymbolError(exception_inf) + + message_error = "No module named 'mmcv._ext'" + if message_error in exception_inf: + raise ExtNotFoundError(exception_inf) + for fun in funcs: assert hasattr(ext, fun), f'{fun} miss in module {name}' return ext From 8655110604e3d40b70ab76d2dab92e45f6184503 Mon Sep 17 00:00:00 2001 From: YiyaoYang1 Date: Mon, 30 Oct 2023 17:18:24 +0800 Subject: [PATCH 11/14] add subclass of ImportError --- mmcv/utils/ext_loader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmcv/utils/ext_loader.py b/mmcv/utils/ext_loader.py index 820e049e78..59e7b97649 100644 --- a/mmcv/utils/ext_loader.py +++ b/mmcv/utils/ext_loader.py @@ -48,7 +48,7 @@ def __init__(self, arg): 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md', sep='\n') - class ExtNotFoundError(ImportError): + class ExtNotFoundError(ModuleNotFoundError): def __init__(self, arg): print(arg) From 6b7d67be79d4f248fd189958646fbe0f2f23dc0b Mon Sep 17 00:00:00 2001 From: YiyaoYang1 Date: Mon, 30 Oct 2023 20:27:15 +0800 Subject: [PATCH 12/14] fix typo --- mmcv/utils/ext_loader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mmcv/utils/ext_loader.py b/mmcv/utils/ext_loader.py index 59e7b97649..99671b04b5 100644 --- a/mmcv/utils/ext_loader.py +++ b/mmcv/utils/ext_loader.py @@ -33,7 +33,7 @@ def __init__(self, arg): 'https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md', sep='\n') - class UndefineSymbolError(ImportError): + class UndefinedSymbolError(ImportError): def __init__(self, arg): print(arg) @@ -72,7 +72,7 @@ def load_ext(name, funcs): message_error = 'undefined symbol' if message_error in exception_inf: - raise UndefineSymbolError(exception_inf) + raise UndefinedSymbolError(exception_inf) message_error = "No module named 'mmcv._ext'" if message_error in exception_inf: From dcf8dc8d56623d4380f7fa75ab38b7692b2669c6 Mon Sep 17 00:00:00 2001 From: YiyaoYang1 Date: Tue, 31 Oct 2023 11:38:29 +0800 Subject: [PATCH 13/14] fix cuda codes format --- mmcv/ops/csrc/common/pytorch_device_registry.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mmcv/ops/csrc/common/pytorch_device_registry.hpp b/mmcv/ops/csrc/common/pytorch_device_registry.hpp index 6ca3a90426..99f4cca643 100644 --- a/mmcv/ops/csrc/common/pytorch_device_registry.hpp +++ b/mmcv/ops/csrc/common/pytorch_device_registry.hpp @@ -119,7 +119,9 @@ auto Dispatch(const R& registry, const char* name, Args&&... args) { " vs ", GetDeviceStr(device).c_str(), "\n") auto f_ptr = registry.Find(device.type()); TORCH_CHECK(f_ptr != nullptr, name, ": implementation for device ", - GetDeviceStr(device).c_str(), " not found.\n", "For more information, see https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md \n") + GetDeviceStr(device).c_str(), " not found.\n", + "For more information, see ", \ + "https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md \n") return f_ptr(std::forward(args)...); } From c7be12ce796f32c71821b8bd9ebeb3e1993ff756 Mon Sep 17 00:00:00 2001 From: YiyaoYang1 Date: Tue, 31 Oct 2023 14:10:51 +0800 Subject: [PATCH 14/14] fix cuda codes format --- mmcv/ops/csrc/common/pytorch_device_registry.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmcv/ops/csrc/common/pytorch_device_registry.hpp b/mmcv/ops/csrc/common/pytorch_device_registry.hpp index 99f4cca643..68afc55b48 100644 --- a/mmcv/ops/csrc/common/pytorch_device_registry.hpp +++ b/mmcv/ops/csrc/common/pytorch_device_registry.hpp @@ -120,7 +120,7 @@ auto Dispatch(const R& registry, const char* name, Args&&... args) { auto f_ptr = registry.Find(device.type()); TORCH_CHECK(f_ptr != nullptr, name, ": implementation for device ", GetDeviceStr(device).c_str(), " not found.\n", - "For more information, see ", \ + "For more information, see ", "https://github.com/open-mmlab/mmcv/blob/main/docs/en/faq.md \n") return f_ptr(std::forward(args)...); }