Error
python3 -c "import functorch; from functorch.einops import rearrange"
/usr/local/lib/python3.12/dist-packages/torch/_subclasses/functional_tensor.py:295: UserWarning: Failed to initialize NumPy: No module named 'numpy' (Triggered internally at /pytorch/torch/csrc/utils/tensor_numpy.cpp:81.)
cpu = _conversion_method_template(device=torch.device("cpu"))
RuntimeError: First class dim doesn't work with python 3.12
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.12/dist-packages/functorch/einops/init.py", line 1, in
from .rearrange import rearrange
File "/usr/local/lib/python3.12/dist-packages/functorch/einops/rearrange.py", line 7, in
from functorch._C import dim as _C
ImportError: initialization failed
Solution
First, check if there are any updated versions of functorch available. You can try upgrading it using the command pip install --upgrade functorch to see if the developers have already fixed this compatibility issue in a newer release.
If upgrading doesn't work, you might consider using a different version of Python that is known to work well with functorch. For example, downgrading to Python 3.11 (if feasible in your setup) could potentially avoid this specific runtime error, as it might be more compatible with the current version of functorch you're using.