Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'MultiScaleDeformableAttention' from 'mmcv.cnn.bricks.transformer' #1399

Closed
FrancescoSaverioZuppichini opened this issue Oct 13, 2021 · 18 comments

Comments

@FrancescoSaverioZuppichini

Thanks for reporting the unexpected results and we appreciate it a lot.

Checklist

  1. I have searched related issues but cannot get the expected help.
  2. I have read the FAQ documentation but cannot get the expected help.
  3. The unexpected results still exist in the latest version.

Describe the Issue

/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmcv/cnn/bricks/transformer.py:28: UserWarning: Fail to import ``MultiScaleDeformableAttention`` from ``mmcv.ops.multi_scale_deform_attn``, You should install ``mmcv-full`` if you need this module. 
  warnings.warn('Fail to import ``MultiScaleDeformableAttention`` from '
/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmdet/models/utils/transformer.py:26: UserWarning: `MultiScaleDeformableAttention` in MMCV has been moved to `mmcv.ops.multi_scale_deform_attn`, please update your MMCV
  warnings.warn(
Traceback (most recent call last):
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmdet/models/utils/transformer.py", line 23, in <module>
    from mmcv.ops.multi_scale_deform_attn import MultiScaleDeformableAttention
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmcv/ops/__init__.py", line 2, in <module>
    from .ball_query import ball_query
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmcv/ops/ball_query.py", line 7, in <module>
    ext_module = ext_loader.load_ext('_ext', ['ball_query_forward'])
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmcv/utils/ext_loader.py", line 13, in load_ext
    ext = importlib.import_module('mmcv.' + name)
  File "/home/zuppif/miniconda3/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: /home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmcv/_ext.cpython-39-x86_64-linux-gnu.so: undefined symbol: _ZNK2at6Tensor6deviceEv

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/zuppif/integration-object-detection-icevision/notebook.py", line 7, in <module>
    from icevision import ObjectDetectionRecord, Parser, ClassMap, BBox, ImgSize
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/icevision/__init__.py", line 7, in <module>
    from icevision import models
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/icevision/models/__init__.py", line 15, in <module>
    from icevision.models import mmdet
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/icevision/models/mmdet/__init__.py", line 1, in <module>
    from icevision.models.mmdet import common
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/icevision/models/mmdet/common/__init__.py", line 3, in <module>
    from icevision.models.mmdet.common import bbox
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/icevision/models/mmdet/common/bbox/__init__.py", line 1, in <module>
    from icevision.models.mmdet.common.bbox.dataloaders import *
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/icevision/models/mmdet/common/bbox/dataloaders.py", line 10, in <module>
    from icevision.models.mmdet.common.utils import convert_background_from_zero_to_last
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/icevision/models/mmdet/common/utils.py", line 11, in <module>
    from mmdet.models import build_detector
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmdet/models/__init__.py", line 2, in <module>
    from .backbones import *  # noqa: F401,F403
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmdet/models/backbones/__init__.py", line 2, in <module>
    from .csp_darknet import CSPDarknet
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmdet/models/backbones/csp_darknet.py", line 11, in <module>
    from ..utils import CSPLayer
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmdet/models/utils/__init__.py", line 16, in <module>
    from .transformer import (DetrTransformerDecoder, DetrTransformerDecoderLayer,
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmdet/models/utils/transformer.py", line 29, in <module>
    from mmcv.cnn.bricks.transformer import MultiScaleDeformableAttention
ImportError: cannot import name 'MultiScaleDeformableAttention' from 'mmcv.cnn.bricks.transformer' (/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmcv/cnn/bricks/transformer.py)

Reproduction

Install mmcv-full using mim or

pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.9.1/index.html

then try to use vfnet

Environment

  1. Please run python -c "from mmcv.utils import collect_env; print(collect_env())" to collect necessary environment information
    It results in an error
 python -c "from mmcv.utils import collect_env; print(collect_env())"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmcv/utils/env.py", line 87, in collect_env
    from mmcv.ops import get_compiler_version, get_compiling_cuda_version
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmcv/ops/__init__.py", line 2, in <module>
    from .ball_query import ball_query
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmcv/ops/ball_query.py", line 7, in <module>
    ext_module = ext_loader.load_ext('_ext', ['ball_query_forward'])
  File "/home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmcv/utils/ext_loader.py", line 13, in load_ext
    ext = importlib.import_module('mmcv.' + name)
  File "/home/zuppif/miniconda3/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: /home/zuppif/integration-object-detection-icevision/.venv/lib/python3.9/site-packages/mmcv/_ext.cpython-39-x86_64-linux-gnu.so: undefined symbol: _ZNK2at6Tensor6deviceEv
@zhouzaida
Copy link
Member

zhouzaida commented Oct 13, 2021

hi, had the mmcv-full been installed? please provide the output of pip list | grep mmcv-full

@zhouzaida
Copy link
Member

hi, @FrancescoSaverioZuppichini , in the latest version (v1.3.15), we provide pre-compiled packages for the Python 3.9 environment.
You can install the latest mmcv-full with the following command.

pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.9.0/index.html

@FrancescoSaverioZuppichini
Copy link
Author

Thank you very much, I'll check this out

@zhouzaida
Copy link
Member

hi, is there any progress?

@FrancescoSaverioZuppichini
Copy link
Author

yes so let me share a minimum example container in which the problem arises

FROM nvcr.io/nvidia/cuda:11.2.0-cudnn8-runtime-ubuntu20.04

RUN apt-get -yq update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -yqq --no-install-recommends \
    git \
    ssh \
    wget \
    python3-dev \ 
    python3-pip \ 
    python3-opencv \ 
    build-essential \
    gcc \
    && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN pip install cython
RUN pip install mmcv-full==1.3.16 -f https://download.openmmlab.com/mmcv/dist/cu112/torch1.9.1/index.html
RUN pip install mmdet==2.17.0

env

{'CUDA available': True,
 'CUDA_HOME': '/usr/local/cuda',
 'GCC': 'gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0',
 'GPU 0,1,2': 'GeForce GTX 1080 Ti',
 'MMCV': '1.3.16',
 'MMCV CUDA Compiler': 'n/a',
 'MMCV Compiler': 'n/a',
 'NVCC': '',
 'OpenCV': '4.5.4-dev',
 'PyTorch': '1.9.1+cu102',
 'PyTorch compiling details': 'PyTorch built with:\n'
                              '  - GCC 7.3\n'
                              '  - C++ Version: 201402\n'
                              '  - Intel(R) Math Kernel Library Version '
                              '2020.0.0 Product Build 20191122 for Intel(R) 64 '
                              'architecture applications\n'
                              '  - Intel(R) MKL-DNN v2.1.2 (Git Hash '
                              '98be7e8afa711dc9b66c8ff3504129cb82013cdb)\n'
                              '  - OpenMP 201511 (a.k.a. OpenMP 4.5)\n'
                              '  - NNPACK is enabled\n'
                              '  - CPU capability usage: AVX2\n'
                              '  - CUDA Runtime 10.2\n'
                              '  - NVCC architecture flags: '
                              '-gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70\n'
                              '  - CuDNN 7.6.5\n'
                              '  - Magma 2.5.2\n'
                              '  - Build settings: BLAS_INFO=mkl, '
                              'BUILD_TYPE=Release, CUDA_VERSION=10.2, '
                              'CUDNN_VERSION=7.6.5, '
                              'CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, '
                              'CXX_FLAGS= -Wno-deprecated '
                              '-fvisibility-inlines-hidden -DUSE_PTHREADPOOL '
                              '-fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM '
                              '-DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK '
                              '-DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE '
                              '-O2 -fPIC -Wno-narrowing -Wall -Wextra '
                              '-Werror=return-type '
                              '-Wno-missing-field-initializers '
                              '-Wno-type-limits -Wno-array-bounds '
                              '-Wno-unknown-pragmas -Wno-sign-compare '
                              '-Wno-unused-parameter -Wno-unused-variable '
                              '-Wno-unused-function -Wno-unused-result '
                              '-Wno-unused-local-typedefs -Wno-strict-overflow '
                              '-Wno-strict-aliasing '
                              '-Wno-error=deprecated-declarations '
                              '-Wno-stringop-overflow -Wno-psabi '
                              '-Wno-error=pedantic -Wno-error=redundant-decls '
                              '-Wno-error=old-style-cast '
                              '-fdiagnostics-color=always -faligned-new '
                              '-Wno-unused-but-set-variable '
                              '-Wno-maybe-uninitialized -fno-math-errno '
                              '-fno-trapping-math -Werror=format '
                              '-Wno-stringop-overflow, LAPACK_INFO=mkl, '
                              'PERF_WITH_AVX=1, PERF_WITH_AVX2=1, '
                              'PERF_WITH_AVX512=1, TORCH_VERSION=1.9.1, '
                              'USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, '
                              'USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, '
                              'USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, '
                              'USE_NNPACK=ON, USE_OPENMP=ON, \n',
 'Python': '3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0]',
 'TorchVision': '0.10.1+cu102',
 'sys.platform': 'linux'}

@zhouzaida
Copy link
Member

| pip install mmcv-full==1.3.16 -f https://download.openmmlab.com/mmcv/dist/cu112/torch1.9.1/index.html

Hi, we do not provide pre-compiled packages for cu112 and torch1.9.1, but we do provide cu111 and torch1.9.0.

You can use the follow command to install it.

pip install mmcv-full==1.3.16 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.0/index.html

@dwight-foster
Copy link

dwight-foster commented Nov 24, 2021

Hello I am getting the same error. I used pip install mmcv-full==1.3.16 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.0/index.html, but it has not changed anything. The full error is

/opt/conda/lib/python3.7/site-packages/mmdet/models/utils/transformer.py:27: UserWarning: MultiScaleDeformableAttention in MMCV has been moved to mmcv.ops.multi_scale_deform_attn, please update your MMCV
'MultiScaleDeformableAttention in MMCV has been moved to '

ImportError Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/mmdet/models/utils/transformer.py in
22 try:
---> 23 from mmcv.ops.multi_scale_deform_attn import MultiScaleDeformableAttention
24

/opt/conda/lib/python3.7/site-packages/mmcv/ops/init.py in
1 # Copyright (c) OpenMMLab. All rights reserved.
----> 2 from .assign_score_withk import assign_score_withk
3 from .ball_query import ball_query

/opt/conda/lib/python3.7/site-packages/mmcv/ops/assign_score_withk.py in
5 ext_module = ext_loader.load_ext(
----> 6 '_ext', ['assign_score_withk_forward', 'assign_score_withk_backward'])
7

/opt/conda/lib/python3.7/site-packages/mmcv/utils/ext_loader.py in load_ext(name, funcs)
12 def load_ext(name, funcs):
---> 13 ext = importlib.import_module('mmcv.' + name)
14 for fun in funcs:

/opt/conda/lib/python3.7/importlib/init.py in import_module(name, package)
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
128

ImportError: libtorch_cpu.so: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

ImportError Traceback (most recent call last)
in
----> 1 from mmdet.models import build_detector
2 from config import get_config
3 from mmcv import Config, DictAction
4
5 args = parse_args()

/opt/conda/lib/python3.7/site-packages/mmdet/models/init.py in
1 # Copyright (c) OpenMMLab. All rights reserved.
----> 2 from .backbones import * # noqa: F401,F403
3 from .builder import (BACKBONES, DETECTORS, HEADS, LOSSES, NECKS,
4 ROI_EXTRACTORS, SHARED_HEADS, build_backbone,
5 build_detector, build_head, build_loss, build_neck,

/opt/conda/lib/python3.7/site-packages/mmdet/models/backbones/init.py in
1 # Copyright (c) OpenMMLab. All rights reserved.
----> 2 from .csp_darknet import CSPDarknet
3 from .darknet import Darknet
4 from .detectors_resnet import DetectoRS_ResNet
5 from .detectors_resnext import DetectoRS_ResNeXt

/opt/conda/lib/python3.7/site-packages/mmdet/models/backbones/csp_darknet.py in
9
10 from ..builder import BACKBONES
---> 11 from ..utils import CSPLayer
12
13

/opt/conda/lib/python3.7/site-packages/mmdet/models/utils/init.py in
14 from .res_layer import ResLayer, SimplifiedBasicBlock
15 from .se_layer import SELayer
---> 16 from .transformer import (DetrTransformerDecoder, DetrTransformerDecoderLayer,
17 DynamicConv, PatchEmbed, Transformer, nchw_to_nlc,
18 nlc_to_nchw)

/opt/conda/lib/python3.7/site-packages/mmdet/models/utils/transformer.py in
27 'MultiScaleDeformableAttention in MMCV has been moved to '
28 'mmcv.ops.multi_scale_deform_attn, please update your MMCV')
---> 29 from mmcv.cnn.bricks.transformer import MultiScaleDeformableAttention
30
31

ImportError: cannot import name 'MultiScaleDeformableAttention' from 'mmcv.cnn.bricks.transformer' (/opt/conda/lib/python3.7/site-packages/mmcv/cnn/bricks/transformer.py)`
I cannot seem to figure out why this error keeps coming back. The correct version is installed I checked it. Can anyone help?

@deepwilson
Copy link

Same issue. Looking forward to a solution!

@tabmoo
Copy link

tabmoo commented May 1, 2022

Me too!

@amine0110
Copy link

Same thing here!

@zhouzaida
Copy link
Member

Hi, what is your mmcv version?

@amine0110
Copy link

@zhouzaida it is 1.5 the same as mmcv-full

I checked if the paths and files are put in the right places, and everything is put without any problem!

And when I tried to do the import without the try statement, I got this:

ImportError: DLL load failed: The specified module could not be found.

@Matesanz
Copy link

Matesanz commented May 24, 2022

The problem is that ImportError in this line in is silently catching another exception rather than the "install mmcv-full" one.

if you try the line that is raising the Error:

from mmcv.ops.multi_scale_deform_attn import MultiScaleDeformableAttention
>>> ImportError: .../lib/python3.9/site-packages/mmcv/_ext.cpython-39-x86_64-linux-gnu.so: undefined symbol: _ZNK2at6Tensor4add_ERKS0_RKN3c106ScalarE

Solution

For me was install mmcv CPU version:

pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.11.0/index.html

@qzhai
Copy link

qzhai commented Jul 13, 2022

Hi, what is your mmcv version?

Same question.

I test the mmcv==1.6.0, cu113, pytorch=1.9.0, and the same question when using the CPU version.

@ganesh3
Copy link

ganesh3 commented Sep 22, 2022

same question when I create a docker container with the below commands
RUN pip install mmcv-full==1.3.7 -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.8.0/index.html -U
RUN pip install mmdet==2.13.0 -U
RUN pip install mmsegmentation==0.17.0 -U

@howardchina
Copy link

howardchina commented Dec 6, 2022

same question, why always the same question?

terminal:
python3 -m pip list | grep mmcv-full mmcv-full 1.7.0

error:
"/home/data/programs/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/c
nn/bricks/transformer.py:33: UserWarning: Fail to import MultiScaleDeformableA ttention from mmcv.ops.multi_scale_deform_attn, You should install mmcv- full if you need this module."

@AlistairMcCutcheon
Copy link

AlistairMcCutcheon commented Jul 2, 2023

I am running pytorch 1.8 and cuda 11.1 in a docker container.

I had the issue when running (this installed mmcv-full 1.7.0):
RUN pip install openmim
RUN mim install mmcv-full

However this version of mmcv-full fixed the issue without needing to change to a CPU version:
RUN pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.8.0/mmcv_full-1.7.1-cp39-cp39-manylinux1_x86_64.whl

@anamazingclown
Copy link

anamazingclown commented Mar 21, 2024

I also had the issue when running my code.

environments:

torch:1.9.0

torchvision:0.10.0

mmcv-full==1.4.7

mmdet==2.20.0

GPU 0,1: NVIDIA GeForce RTX 4090,

CUDA Version: 12.1

The way I installed mmcv-full on the anaconda virtual environment on the far server is:
pip install mmcv_full-1.4.7-cp37-cp37m-manylinux1_x86_64.whl

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

No branches or pull requests