Pytorch: torch.utils.ffi is deprecated. How do I use cpp extensions instead?

Created on 1 Jan 2019  ·  10Comments  ·  Source: pytorch/pytorch

🐛 Bug

Trying to build code with a current pytorch under conda fails with the following error:

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

To Reproduce

Steps to reproduce the behavior:

  1. On Ubuntu 16.04 x64, download and install anaconda

  2. Create an environment and install pytorch there: conda install -c pytorch pytorch

  3. Follow the instructions to try running this code: https://github.com/ruotianluo/pytorch-faster-rcnn
  4. Get to the ./make.sh part.
  5. Get a ImportError: torch.utils.ffi is deprecated. Please use cpp extensions instead. error

Expected behavior

./make.sh building all the code cleanly

Environment

Collecting environment information...
PyTorch version: 1.0.0
Is debug build: No
CUDA used to build PyTorch: 9.0.176

OS: Ubuntu 16.04.5 LTS
GCC version: (Ubuntu 7.4.0-1ubuntu1~16.04~ppa1) 7.4.0
CMake version: version 3.13.20181022-g64947

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: 7.5.17
GPU models and configuration: GPU 0: GeForce GTX 750 Ti
Nvidia driver version: 410.79
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.7.3.1
/usr/lib/x86_64-linux-gnu/libcudnn_static_v7.a

Versions of relevant libraries:
[pip] Could not collect
[conda] Could not collect

Most helpful comment

The problem is related to the version of pytorch you installed. I reduced its version from 1.0 to 0.4, and the problem is solved. Newer is not better!

All 10 comments

so there is no easy solution to this? it looks like it requires a full revamp of the code that used to work for pytorch <= 0.4.1

Unfortunately yes. An example port of some other ffi code is at https://github.com/pytorch/audio/commit/8a41ecdc1ba365fb9d51e12b8ab793bc2a3f67fa but some rewriting is necessary. Let us know if you need help.

damn, weeks of work to the trash...

do you plan on deprecating such low-level stuff on a regular basis or is it really worth it trying to make a cpp extension now ?

@aliutkus we deprecated the feature after 1.5 years, and we really apologize for not having a structured deprecation path for it (it was technically not possible). We dont plan to deprecate any public API on a regular basis, especially without deprecation warnings over a few releases. This was a special case, and we apologize.

ok, great. Well I guess it's time to switch from C to C++ =)

thanks for all the work

You should change it as "import torch.utils.cpp_extension"

The problem is related to the version of pytorch you installed. I reduced its version from 1.0 to 0.4, and the problem is solved. Newer is not better!

I am using torch version 1.4.0 but I got the same issue how can I solve it?

Same, I tried import torch.utils.cpp_extension, but no dice.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eliabruni picture eliabruni  ·  3Comments

dablyo picture dablyo  ·  3Comments

soumith picture soumith  ·  3Comments

rajarshd picture rajarshd  ·  3Comments

szagoruyko picture szagoruyko  ·  3Comments