CenterNet icon indicating copy to clipboard operation
CenterNet copied to clipboard

ImportError: torch.utils.ffi is deprecated. Please use cpp extensions instead.

Open MARMOTatZJU opened this issue 5 years ago • 9 comments

During DCNv2 compilation, I encountered this ImportError and I have already identified the reason (PyTorch 1.0.0+ has changed API name). Would you mind add a PyTorch version check conditional branch to fix this issue? Thanks in advance.

The complete Traceback is pasted bellow:

/home/lan/Documents/xuyinda/Projects/CenterNet/src/lib/models/networks/DCNv2
Traceback (most recent call last):
  File "build.py", line 3, in <module>
    from torch.utils.ffi import create_extension
  File "/home/lan/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/utils/ffi/__init__.py", line 1, in <module>
    raise ImportError("torch.utils.ffi is deprecated. Please use cpp extensions instead.")
ImportError: torch.utils.ffi is deprecated. Please use cpp extensions instead.
Traceback (most recent call last):
  File "build_double.py", line 3, in <module>
    from torch.utils.ffi import create_extension
  File "/home/lan/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/utils/ffi/__init__.py", line 1, in <module>
    raise ImportError("torch.utils.ffi is deprecated. Please use cpp extensions instead.")
ImportError: torch.utils.ffi is deprecated. Please use cpp extensions instead.

MARMOTatZJU avatar Jan 02 '20 06:01 MARMOTatZJU

[UPDATE] With the following conditional branch, the import issue was fixed.

from pkg_resources import parse_version
if parse_version(torch.__version__) >= parse_version("1.0.0"):
    from torch.utils.cpp_extension import BuildExtension as create_extension
else:
    from torch.utils.ffi import create_extension

However, I encountered new issue which throws "TypeError: dist must be a Distribution instance". This issue seems to be unfixable by simply change the imported API.

The complete traceback is pasted as below.

/home/lan/Documents/xuyinda/Projects/CenterNet/src/lib/models/networks/DCNv2
Including CUDA code.
/home/lan/Documents/xuyinda/Projects/CenterNet/src/lib/models/networks/DCNv2
Traceback (most recent call last):
  File "build.py", line 44, in <module>
    extra_compile_args=extra_compile_args
  File "/home/lan/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 234, in __init__
    super(BuildExtension, self).__init__(*args, **kwargs)
  File "/home/lan/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/setuptools/__init__.py", line 163, in __init__
    _Command.__init__(self, dist)
  File "/home/lan/anaconda3/envs/open-mmlab/lib/python3.7/distutils/cmd.py", line 57, in __init__
    raise TypeError("dist must be a Distribution instance")
TypeError: dist must be a Distribution instance
Including CUDA code.
/home/lan/Documents/xuyinda/Projects/CenterNet/src/lib/models/networks/DCNv2
Traceback (most recent call last):
  File "build_double.py", line 44, in <module>
    extra_compile_args=extra_compile_args
  File "/home/lan/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 234, in __init__
    super(BuildExtension, self).__init__(*args, **kwargs)
  File "/home/lan/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/setuptools/__init__.py", line 163, in __init__
    _Command.__init__(self, dist)
  File "/home/lan/anaconda3/envs/open-mmlab/lib/python3.7/distutils/cmd.py", line 57, in __init__
    raise TypeError("dist must be a Distribution instance")
TypeError: dist must be a Distribution instance

MARMOTatZJU avatar Jan 02 '20 07:01 MARMOTatZJU

Hi, I installed torch=0.4.1. However, there is another error: Bus error (core dumped). Do you know how to fix this?

neoyang0620 avatar Jan 03 '20 01:01 neoyang0620

I have the same problem... Have there been solutions for this issue in pytorch 1.0+?

Thanks~

EricKani avatar Jan 14 '20 03:01 EricKani

@EricKani @neoyang0620 Solved by this issue

MARMOTatZJU avatar Jan 14 '20 06:01 MARMOTatZJU

@MARMOTatZJU Thank you~

EricKani avatar Jan 14 '20 06:01 EricKani

[UPDATE] With the following conditional branch, the import issue was fixed.

from pkg_resources import parse_version
if parse_version(torch.__version__) >= parse_version("1.0.0"):
    from torch.utils.cpp_extension import BuildExtension as create_extension
else:
    from torch.utils.ffi import create_extension

However, I encountered new issue which throws "TypeError: dist must be a Distribution instance". This issue seems to be unfixable by simply change the imported API.

The complete traceback is pasted as below.

/home/lan/Documents/xuyinda/Projects/CenterNet/src/lib/models/networks/DCNv2
Including CUDA code.
/home/lan/Documents/xuyinda/Projects/CenterNet/src/lib/models/networks/DCNv2
Traceback (most recent call last):
  File "build.py", line 44, in <module>
    extra_compile_args=extra_compile_args
  File "/home/lan/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 234, in __init__
    super(BuildExtension, self).__init__(*args, **kwargs)
  File "/home/lan/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/setuptools/__init__.py", line 163, in __init__
    _Command.__init__(self, dist)
  File "/home/lan/anaconda3/envs/open-mmlab/lib/python3.7/distutils/cmd.py", line 57, in __init__
    raise TypeError("dist must be a Distribution instance")
TypeError: dist must be a Distribution instance
Including CUDA code.
/home/lan/Documents/xuyinda/Projects/CenterNet/src/lib/models/networks/DCNv2
Traceback (most recent call last):
  File "build_double.py", line 44, in <module>
    extra_compile_args=extra_compile_args
  File "/home/lan/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 234, in __init__
    super(BuildExtension, self).__init__(*args, **kwargs)
  File "/home/lan/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/setuptools/__init__.py", line 163, in __init__
    _Command.__init__(self, dist)
  File "/home/lan/anaconda3/envs/open-mmlab/lib/python3.7/distutils/cmd.py", line 57, in __init__
    raise TypeError("dist must be a Distribution instance")
TypeError: dist must be a Distribution instance

I have the same issue. Do you know how to fix it now?

nthhiep avatar Oct 06 '20 15:10 nthhiep

I am still having this same issue. Anyone found solution for this?

sanket1012 avatar Apr 23 '21 05:04 sanket1012

Until 9/9/2021, you can refer to the repo here https://github.com/jinfagang/DCNv2_latest I already checked it. Note that, remove the "sudo" before the python in make.sh if you can't run the sh script because torch is not found.

Guanbin-Huang avatar Sep 09 '21 13:09 Guanbin-Huang

Until 9/9/2021, you can refer to the repo here https://github.com/jinfagang/DCNv2_latest I already checked it. Note that, remove the "sudo" before the python in make.sh if you can't run the sh script because torch is not found.

Thank you, this work for me

hongsamvo avatar Oct 29 '21 01:10 hongsamvo