functorch
functorch copied to clipboard
Cannot import vmap after new release
I am installing functorch on google colab; when I don't specify the version, it installs version 0.2.2 and PyTorch version 1.12.0, and uninstall currently installed PyTorch 1.11.0 on colab. But, in the line where I import vmap, it throws an error that functorch is not compatible with PyTorch 1.12.0:
RuntimeError Traceback (most recent call last)
[<ipython-input-1-0691ca18293b>](https://localhost:8080/#) in <module>()
3
4 from torchsummary import summary
----> 5 from functorch import vmap
6 import torch
7 import torch.nn as nn
[/usr/local/lib/python3.7/dist-packages/functorch/__init__.py](https://localhost:8080/#) in <module>()
20 if torch_cuda_version not in pytorch_cuda_restrictions:
21 raise RuntimeError(
---> 22 f"We've detected an installation of PyTorch 1.12 with {verbose_torch_cuda_version} support. "
23 "This functorch 0.2.0 binary is not compatible with the PyTorch installation. "
24 "Please see our install page for suggestions on how to resolve this: "
RuntimeError: We've detected an installation of PyTorch 1.12 with CUDA 10.2 support. This functorch 0.2.0 binary is not compatible with the PyTorch installation. Please see our install page for suggestions on how to resolve this: https://pytorch.org/functorch/stable/install.html
I tried the older version, functorch 0.1.1 with PyTorch 1.11.0, but it also gives some errors during the import:
ImportError Traceback (most recent call last)
[<ipython-input-3-abbd2ba6241c>](https://localhost:8080/#) in <module>()
3
4 from torchsummary import summary
----> 5 from functorch import vmap
6 import torch
7 import torch.nn as nn
[/usr/local/lib/python3.7/dist-packages/functorch/__init__.py](https://localhost:8080/#) in <module>()
5 # LICENSE file in the root directory of this source tree.
6 import torch
----> 7 from . import _C
8
9 # Monkey patch PyTorch. This is a hack, we should try to upstream
ImportError: /usr/local/lib/python3.7/dist-packages/functorch/_C.so: undefined symbol: _ZNK3c1010TensorImpl5sizesEv
Note: I was able to use vmap from older version just a few hours ago, then I came to notebook started it and now it doesn't work
Can you try the following on colab?
pip3 uninstall functorch torch
pip3 uninstall functorch torch # just for good measure.
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
pip3 install functorch
The situation is not great right now, but I think pip install functorch
will try to install PyTorch 1.12 from pip, but the PyTorch 1.12 in pip isn't compatible with functorch 0.2.0 :/. We're working on fixing the problem
Again it gives an error:
Found existing installation: functorch 0.2.0
Uninstalling functorch-0.2.0:
Successfully uninstalled functorch-0.2.0
Found existing installation: torch 1.11.0+cu113
Uninstalling torch-1.11.0+cu113:
Successfully uninstalled torch-1.11.0+cu113
Usage:
pip3 uninstall [options] <package> ...
pip3 uninstall [options] -r <requirements file> ...
no such option: -#
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/, https://download.pytorch.org/whl/cu113
Collecting torch
tcmalloc: large alloc 1837662208 bytes == 0x2674000 @ 0x7f2e4bd1e1e7 0x4a3940 0x5b438c 0x5ea94f 0x5939cb 0x594cd3 0x5d0ecb 0x59aeca 0x515655 0x593dd7 0x511e2c 0x593dd7 0x511e2c 0x549e0e 0x4bca8a 0x59c019 0x595ef6 0x5134a6 0x549576 0x4bca8a 0x59c019 0x595ef6 0x5134a6 0x549576 0x4bca8a 0x59c019 0x595ef6 0x5134a6 0x549e0e 0x4bca8a 0x59c019
tcmalloc: large alloc 1837662208 bytes == 0x6fefc000 @ 0x7f2e4bd1e1e7 0x4a3940 0x5b438c 0x64cfe7 0x59b076 0x515655 0x593dd7 0x511e2c 0x593dd7 0x511e2c 0x549e0e 0x4bca8a 0x59c019 0x595ef6 0x5134a6 0x549576 0x4bca8a 0x59c019 0x595ef6 0x5134a6 0x549576 0x4bca8a 0x59c019 0x595ef6 0x5134a6 0x549e0e 0x4bca8a 0x59c019 0x595ef6 0x5134a6 0x549576
tcmalloc: large alloc 1837662208 bytes == 0xdd784000 @ 0x7f2e4bd1e1e7 0x4a3940 0x59b5e2 0x63a515 0x63bd66 0x63be16 0x59afff 0x515655 0x593dd7 0x511e2c 0x549576 0x593fce 0x548ae9 0x5127f1 0x593dd7 0x5118f8 0x593dd7 0x511e2c 0x593dd7 0x511e2c 0x549e0e 0x4bca8a 0x59c019 0x595ef6 0x5134a6 0x549576 0x4bca8a 0x59c019 0x595ef6 0x5134a6 0x549576
tcmalloc: large alloc 1837662208 bytes == 0x14b00c000 @ 0x7f2e4bd1e1e7 0x4a3940 0x59b6f0 0x59f499 0x4d3969 0x512147 0x549576 0x593fce 0x511e2c 0x549576 0x593fce 0x511e2c 0x549e0e 0x593fce 0x511e2c 0x549e0e 0x593fce 0x511e2c 0x549e0e 0x593fce 0x511e2c 0x549576 0x593fce 0x548ae9 0x5127f1 0x593dd7 0x5118f8 0x593dd7 0x511e2c 0x593dd7 0x511e2c
tcmalloc: large alloc 1837662208 bytes == 0x1b8894000 @ 0x7f2e4bd1e1e7 0x4a3940 0x5b438c 0x638cb2 0x59644e 0x5946b8 0x515600 0x549e0e 0x593fce 0x511e2c 0x549e0e 0x593fce 0x511e2c 0x549e0e 0x593fce 0x511e2c 0x549576 0x593fce 0x548ae9 0x5127f1 0x593dd7 0x5118f8 0x593dd7 0x511e2c 0x593dd7 0x511e2c 0x549e0e 0x4bca8a 0x59c019 0x595ef6 0x5134a6
tcmalloc: large alloc 2297077760 bytes == 0x6fefc000 @ 0x7f2e4bd1f615 0x592b76 0x4df71e 0x59afff 0x515655 0x549576 0x593fce 0x511e2c 0x549576 0x593fce 0x511e2c 0x549576 0x593fce 0x511e2c 0x549576 0x593fce 0x511e2c 0x549576 0x593fce 0x511e2c 0x593dd7 0x511e2c 0x549576 0x593fce 0x548ae9 0x5127f1 0x549576 0x593fce 0x511e2c 0x549e0e 0x593fce
Using cached https://download.pytorch.org/whl/cu113/torch-1.12.0%2Bcu113-cp37-cp37m-linux_x86_64.whl (1837.7 MB)
Requirement already satisfied: torchvision in /usr/local/lib/python3.7/dist-packages (0.12.0+cu113)
Requirement already satisfied: torchaudio in /usr/local/lib/python3.7/dist-packages (0.11.0+cu113)
Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch) (4.1.1)
Using cached https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp37-cp37m-linux_x86_64.whl (1637.0 MB)
Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /usr/local/lib/python3.7/dist-packages (from torchvision) (7.1.2)
Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from torchvision) (1.21.6)
Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from torchvision) (2.23.0)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->torchvision) (1.24.3)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests->torchvision) (2.10)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->torchvision) (2022.6.15)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->torchvision) (3.0.4)
Installing collected packages: torch
Successfully installed torch-1.11.0+cu113
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting functorch
Using cached functorch-0.2.0-cp37-cp37m-manylinux1_x86_64.whl (26.5 MB)
Collecting torch<1.13,>=1.12
Using cached torch-1.12.0-cp37-cp37m-manylinux1_x86_64.whl (776.3 MB)
Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch<1.13,>=1.12->functorch) (4.1.1)
Installing collected packages: torch, functorch
Attempting uninstall: torch
Found existing installation: torch 1.11.0+cu113
Uninstalling torch-1.11.0+cu113:
Successfully uninstalled torch-1.11.0+cu113
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchvision 0.12.0+cu113 requires torch==1.11.0, but you have torch 1.12.0 which is incompatible.
torchtext 0.12.0 requires torch==1.11.0, but you have torch 1.12.0 which is incompatible.
torchaudio 0.11.0+cu113 requires torch==1.11.0, but you have torch 1.12.0 which is incompatible.
fastai 2.6.3 requires torch<1.12,>=1.7.0, but you have torch 1.12.0 which is incompatible.
Successfully installed functorch-0.2.0 torch-1.12.0
ImportError Traceback (most recent call last)
[<ipython-input-3-0d8749858e7f>](https://localhost:8080/#) in <module>()
6 get_ipython().system('pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113')
7 get_ipython().system('pip install functorch')
----> 8 from functorch import vmap
9 import torch
10 import torch.nn as nn
[/usr/local/lib/python3.7/dist-packages/functorch/__init__.py](https://localhost:8080/#) in <module>()
32 pass
33
---> 34 from . import _C
35
36 # Monkey patch PyTorch. This is a hack, we should try to upstream
ImportError: /usr/local/lib/python3.7/dist-packages/functorch/_C.so: undefined symbol: _ZNK3c1010TensorImpl12sizes_customEv
@KananMahammadli it looks like somehow colab is forcing install of PyTorch 1.12 from pip when one installs functorch 0.2.0. This is not expected.
In the medium-term, we're going to fix this in functorch 0.2.1 and PyTorch 1.12.1 (which should be out before the end of the month).
In the short term, you should be able to use the default colab PyTorch installation (PyTorch 1.11) with functorch 0.1.1. I installed functorch with !pip3 install functorch==0.1.1
in colab and it seemed to work:
The new functorch 0.2.1 release should fix this problem