Error when importing PyTorch XLA on Google Colab

I am trying to run some code on Google Colab TPU.

I am installing pytorch-xla using the following lines of code:

!pip install cloud-tpu-client==0.10 https://storage.googleapis.com/tpu-pytorch/wheels/torch_xla-1.9-cp37-cp37m-linux_x86_64.whl

This outputs

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.
earthengine-api 0.1.278 requires google-api-python-client<2,>=1.12.1, but you have google-api-python-client 1.8.0 which is incompatible.
Successfully installed cloud-tpu-client-0.10 google-api-python-client-1.8.0 torch-xla-1.9.1

When I am trying to import torch_xla, I am getting the error
ImportError: /usr/local/lib/python3.7/dist-packages/_XLAC.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZNK2at10TensorBase8data_ptrIN3c107complexIfEEEEPT_v

This issue is occurring even when using the example notebooks given in pytorch-xla github repo readme. But I received no error yesterday running the same notebooks!

What is the reason for this error and what is the solution?

EDIT:

When I run the following code:

!curl https://raw.githubusercontent.com/pytorch/xla/master/contrib/scripts/env-setup.py -o pytorch-xla-env-setup.py
!python pytorch-xla-env-setup.py --version 1.9
import os
os.environ['LD_LIBRARY_PATH']='/usr/local/lib'
!echo $LD_LIBRARY_PATH
!sudo ln -s /usr/local/lib/libmkl_intel_lp64.so /usr/local/lib/libmkl_intel_lp64.so.1
!sudo ln -s /usr/local/lib/libmkl_intel_thread.so /usr/local/lib/libmkl_intel_thread.so.1
!sudo ln -s /usr/local/lib/libmkl_core.so /usr/local/lib/libmkl_core.so.1
!ldconfig
!ldd /usr/local/lib/python3.7/dist-packages/torch/lib/libtorch.so

It uninstalls torch-1.9.0+cu102 and install torch-1.10.0a0+git88c0ea9

When importing torch I get this output

/usr/local/lib/python3.7/dist-packages/torch/package/_directory_reader.py:17: UserWarning: Failed to initialize NumPy: module compiled against API version 0xe but this version of numpy is 0xd (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:68.)
  _dtype_to_storage = {data_type(0).dtype: data_type for data_type in _storages}

What is the reason behind this behavior?

Using

!pip uninstall -y torch
!pip install torch==1.8.2+cpu torchvision==0.9.2+cpu -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html
!pip install cloud-tpu-client==0.10 [https://storage.googleapis.com/tpu-pytorch/wheels/torch_xla-1.8-cp37-cp37m-linux_x86_64.whl](https://storage.googleapis.com/tpu-pytorch/wheels/torch_xla-1.9-cp37-cp37m-linux_x86_64.whl

works for now!!

Sorry but this solution doesn’t work any more! we get a dependency error!

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.
torchtext 0.10.0 requires torch==1.9.0, but you have torch 1.8.2+cpu which is incompatible.

Hi @Bttxy ,
I get the dependency error too, but since I don’t need torchtext for my work, I ignored that dependency error!! The solution will be install torchtext version which is compatible with torch-1.8.2.

You can try installing torch-xla-1.9 with torch-1.9.0 in a similar way, but in my case it did not work!

1 Like

As of today (14th September, 2021), the torch-xla-1.9 wheel has been fixed, as reported in the GitHub Issue tab (#3121).

So, now anyone can just use

!pip install cloud-tpu-client==0.10 https://storage.googleapis.com/tpu-pytorch/wheels/torch_xla-1.9-cp37-cp37m-linux_x86_64.whl

why do i get this error

Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
ERROR: torch_xla-1.9-cp37-cp37m-linux_x86_64.whl is not a supported wheel on this platform.
1 Like