PyTorch XLA incompatibility issue when running a modified official example - pytorch

When running this sample using PyTorch XLA modified slightly from the official sample in Colab, the following errors are presented:
ImportError: /usr/local/lib/python3.7/dist-packages/_XLAC.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZN2at13_foreach_erf_EN3c108ArrayRefINS_6TensorEEE.
This seems to be from the code snippet import torch_xla, which seems to point to an incompatibility error. However, I am not able to locate the error.

This error happens because your torch_xla and torch are not the same versions, as I see in the sample you shared you use torch_xla version 1.9.
Check your torch version; torch.__version__
if it is not '1.9.0+cu111'
Use;
!pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
Then
!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 should solve your issue.

Related

the imageai module requires Pytorch to work in Python3.10

I am trying to install imageai in Python3.10. It is installed but when I import the module imageai, it requires installing pytorch and torchvision:
Dependency error!!! PyTorch and TorchVision are not installed. Please see installation instructions in the documentation https://imageai.readthedocs.io/
I installed Pytorch and Torchvision using the below commands in CMD:
pip3.10 install torch pip3.10 install torchvision
Yet I receive the above dependency error when I import imageai. Any idea?
I had the same problem. Try to use the exact versions of the dependencies listed in the instructions of imageai.
I have uninstalled all modules first, then installed with the exact versions and the problem is solved.
I am using python 3.8.5.
I hope this works with you also.

ModuleNotFoundError: No module named sklearn

Please help me for making a good solutions of my problems. I don't work for these issue.
Below the code:
from sklearn import datasets
Below the error:
ModuleNotFoundError: No module named 'sklearn'
You may also try to install: scikit-learn
pip install scikit-learn
or via Conda:
conda install scikit-learn
you basically not installed sklearn library.. so first install sklearn with below command.
pip install sklearn
and then run the code it will resolve your issue.
If PIP is already installed on you PC, its just a matter of running a single command pip install sklearn and it will install the sklearn module easily. You can refer to https://scikit-learn.org/stable/install.html.
else you will need to install pip. Refer https://phoenixnap.com/kb/install-pip-windows for PIP installation.

pytorch code sudden fails on colab with NVIDIA driver on your system is too old

I had some code which worked on colab (gpu runtime) just a short while ago. Suddenly I am getting
The NVIDIA driver on your system is too old (found version 10010).
nvcc shows
Cuda compilation tools, release 10.1, V10.1.243
I tried torch versions 1.5.1, then 1.13.0. Both keep getting this error.
There is a discussion showing other people having doubts. with no clear resolution.
https://github.com/pytorch/pytorch/issues/27738
Anyone having the same problem?
The light-the-torch package is designed to solve exactly this type of issue. Try this:
!pip install light-the-torch
!ltt install torch torchvision
I think this might be to do with the fact that Google Colab randomly connects you to a GPU when you start a runtime. Some might have different drivers installed, which could result in that error to display only part of the time, as you've experienced.
You can see the current version of CUDA by running !nvidia-smi in Colab. You can then simply install a version of PyTorch that is compatible with this version of CUDA. The PyTorch website can generate a pip command for your language/environment/CUDA version, and there is also a list of previous versions and their corresponding commands if you have a CUDA version that the current version doesn't support.
This is what I got working with a CUDA version of 10.1:
!pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 -f https://download.pytorch.org/whl/torch_stable.html
Late reply, but maybe it will help others to ease their problems.
Pytorch has a previous versions page that has both PyTorch and Torchvision installation commands recommended for older versions. For your case, I used !pip install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html and worked just fine in Google Colab, taking into consideration the NVidia driver version as well.
I was also getting the same error.
This one fixed the issue for me:
pip install torch==1.4.0+cu100 torchvision==0.5.0+cu100 -f https://download.pytorch.org/whl/torch_stable.html
I just had the same issue on google colab. Following this github issue I downgraded to torch==1.4.0 using !pip.
Since I had several other requirements, I am reading them from a local file like this:
with open('attribute_hallucination/editing_tool/requirements.txt', 'w') as f:
f.write("cupy-cuda101==7.4.0\ncycler==0.10.0\nfastrlock==0.4\nfuture==0.18.2\nimageio==2.8.0\njoblib==0.14.1\nkiwisolver==1.2.0\nmatplotlib==3.2.1\nnumpy==1.18.4\nopencv-python==4.2.0.34\nPillow==7.1.2\npynvrtc==9.2\npyparsing==2.4.7\npython-dateutil==2.8.1\nscikit-learn==0.22.2.post1\nscipy==1.2.0\nsix==1.14.0\nsklearn==0.0\ntorch==1.4.0\ntorchvision==0.6.0\ntqdm==4.46.0")
!pip install -r attribute_hallucination/editing_tool/requirements.txt
This one worked for me:
pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
Source: https://discuss.pytorch.org/t/userwarning-cuda-initialization-the-nvidia-driver-on-your-system-is-too-old-found-version-10010/141547/5
I'm not sure if it is important, but I ran this after I installed all the my other dependencies.

How do I install PyTorch v1.0.0+ on Google Colab?

PyTorch v1.0.0 stable was released on 8 December 2018 after being announced 7 months earlier.
I want get a version optimised for the hardware that my IPython kernel is running on.
How do I get this version on Google Colab?
try the following code snippet (it works equally for the runtime with or without gpu)
!pip install -q torch==1.0.0 torchvision
to check the version
import torch
print(torch.__version__)
here you have the version 1.0.0
UPDATE
!pip install torch
Works fine now, as the most stable version is 1.0.0
With version 1.0.0, PyTorch changed the download URL format from:
https://download.pytorch.org/whl/cu92/torch-1.0.0-cp36-cp36m-linux_x86_64.whl
to
https://download.pytorch.org/whl/cu90/torch-1.0.0-cp36-cp36m-linux_x86_64.whl
(The change is in the CUDA version part, where cu92 changes to cu90.)
To programmatically generate that URL, I used the following code:
from os.path import exists
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag
platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
cuda_output = !ldconfig -p|grep cudart.so|sed -e 's/.*\.\([0-9]*\)\.\([0-9]*\)$/cu\10/'
accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu'
torch_url=f"http://download.pytorch.org/whl/{accelerator}/torch-{version}-{platform}-linux_x86_64.whl"
version='1.0.0'
!pip install -U {torch_url} torchvision
You can then change the version variable as desired as newer versions are released.
You can now just
import torch
No need for additional installation.
For version 1.1.0, this works
!pip install -q torch==1.1.0 torchvision
It worked for me you can try
!pip install torch
!pip install torchvision
!pip install mxnet-cu101
Here is a code to install pytorch. You can change it to whatever version you want.
!pip3 install http://download.pytorch.org/whl/cu92/torch-1.0.0-cp36-cp36m-linux_x86_64.whl

ImportError:'save_weights' requires h5py

When I save weights during training my CNN model using keras, it says ImportError:'save_weights' requires h5py, but I have already installed h5py.
I would greatly appreciate if someone could explain how to fix this issue.
Just install necessary packages
sudo apt-get install libhdf5-dev
pip install h5py
If you are using windows and python IDE, open cmd and input following commands:
pip install h5py
pip install cython
I hope it helps.
I was getting the same error as you.
I installed all the requirements listed here: https://github.com/fchollet/keras/issues/3426
Finally just needed to reboot and it started working.
As suggested by others:
pip install h5py
Note that this may not immediately resolve the issue in your active session and you may need to reload keras.models either through the following commands or by just creating a new session/re-opening your jupyter notebook.
In Python3:
from importlib import reload
reload(keras.models)
In Python2:
use importlib.import_module instead. See docs for a reference.
These additional steps may be necessary because of the try/except ImportError in keras sourcecode that assigns h5py = None when it's unable to locate it the first time it's executed.
In my case, re-installing did the trick:
pip uninstall -y cython h5py
pip install cython h5py
(Windows 10, Conda, Keras 2.4.3)
I think you may miss this
from keras.applications import imagenet_utils
I got the same problem even though I have imported the h5py.
It is the load error with the keras. It has to be reloaded.
import keras
from importlib import reload
reload(keras.models)
It has worked for me.
h5py==2.10.0 works well with TF >= 2.1 so try 'pip install h5py==2.10.0'
Have you tried directly installing h5py? http://docs.h5py.org/en/latest/build.html
Try running:
pip install h5py
or
sudo apt-get install libhdf5

Resources