Error when importing PyTorch XLA on Google Colab

Siladittya_Manna: <p>I am trying to run some code on Google Colab TPU.</p>
<p>I am installing pytorch-xla using the following lines of code:</p>
<p><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</code></p>
<p>This outputs</p>
<pre><code class="lang-auto">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&lt;2,&gt;=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
</code></pre>
<p>When I am trying to import <strong>torch_xla</strong>, I am getting the error<br>
<code>ImportError: /usr/local/lib/python3.7/dist-packages/_XLAC.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZNK2at10TensorBase8data_ptrIN3c107complexIfEEEEPT_v</code></p>
<p>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!</p>
<p>What is the reason for this error and what is the solution?</p>
<p>EDIT:</p>
<p>When I run the following code:</p>
<pre><code class="lang-auto">!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
</code></pre>
<p>It uninstalls torch-1.9.0+cu102 and install torch-1.10.0a0+git88c0ea9</p>
<p>When importing torch I get this output</p>
<pre><code class="lang-auto">/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}
</code></pre>
<p>What is the reason behind this behavior?</p>

Siladittya_Manna: <p>Using</p>
<pre><code class="lang-auto">!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
</code></pre>
<p>works for now!!</p>

Bttxy: <p>Sorry but this solution doesn’t work any more! we get a dependency error!</p>
<pre><code class="lang-auto">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.
</code></pre>

Siladittya_Manna: <p>Hi <a class="mention" href="/u/bttxy">@Bttxy</a> ,<br>
I get the dependency error too, but since I don’t need <code>torchtext</code> for my work, I ignored that dependency error!! The solution will be install <code>torchtext</code> version which is compatible with <code>torch-1.8.2</code>.</p>
<p>You can try installing <code>torch-xla-1.9</code> with <code>torch-1.9.0</code> in a similar way, but in my case it did not work!</p>

Siladittya_Manna: <p>As of today (14th September, 2021), the torch-xla-1.9 wheel has been fixed, as reported in the GitHub Issue tab (<span class="hashtag">#3121</span>).</p>
<p>So, now anyone can just use</p>
<p><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</code></p>

Septi_Pujiani: <p>why do i get this error</p>
<pre><code class="lang-auto">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.
</code></pre>