“importerror: torch.utils.ffi is deprecated. please use cpp extensions instead ” error message is because of torch.utils.ffi incompatibility. Actually, The internal module of Pytorch has some structural change. Now we can use torch.utils.cpp_extension_versioner in the above place. In this article, we will understand this error in more detail and explore the solution in detail.
importerror: torch.utils.ffi is deprecated. please use cpp extensions instead ( Ground level Analysis)-
Step 1 :
Mostly while running this line –
from torch.utils.ffi import _wrap_function
throws the above error. There can be some other scenario, where we end up with a similar error statement. But the best fix in that
from torch.utils.cpp import xxx from torch.utils.cpp_extension import xxxx from torch.utils.cpp_extension_versioner import xxx
Actually, this error does not only occur while importing specific modules but while also build of the complete code. This torch. utils.CPP package will also resolve such issues.
This cpp module is useful in creating a c++ extension. Most of the time where the performance of the application is a critical angle we use this CPP.
Step 2 :
In some situations even following the above solution. We do not get rid of the error. Then we need to upgrade the pytorch module. In order to upgrade this pytorch module, we can use pip and conda package manager. Actually, there are various ways to install the PyTorch but these two are the most convenient and popular. Here is the command-
pip install torch
The alternative command for conda is –
conda install -c pytorch pytorch
Once we upgrade the PyTorch package, we need to restart the terminal and rerun the code where we have this import statement. Because if we do not restart the terminal or interpreter, It may probably prompt to older existing .pyc files. I will surely fix up the error.
Sometimes we use the correct syntax but with an older version of pytorch. But this upgrade will mostly fix all such issues. Hope now you can easily fix the error for yourself.
Data Science Leaner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.