29

I am using pip3 install tensorflow==1.8.0, but it doesn't have GPU support.

So I am using pip3 install tensorflow-gpu==1.8.0, but it still raises an exception

libcudart.so.VERSION No such file.

Should I use colab to install tensorflow from source?

After pip3 list:

tensorboard              1.10.0   
tensorflow               1.10.0   
tensorflow-hub           0.1.1   
miguelmorin
  • 5,025
  • 4
  • 29
  • 64
二进制
  • 681
  • 1
  • 6
  • 6

6 Answers6

40

You can downgrade Tensorflow to a previous version without GPU support on Google Colab. I ran:

!pip install tensorflow==1.14.0
import tensorflow as tf
print(tf.__version__)

which initially returned

2.0.0-dev20190130

but when I returned to it after a few hours, I got the version I requested:

1.14.0

Trying to downgrade to a version with GPU support:

!pip install tensorflow-gpu==1.14.0

requires restarting the runtime and fails, as importing import tensorflow as tf returns:

ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

Update

When the import fails you can always downgrade CUDA to version 9.0 using following commands

!wget https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64-deb
!dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64-deb
!apt-key add /var/cuda-repo-9-0-local/7fa2af80.pub
!apt-get update
!apt-get install cuda=9.0.176-1

You can check the version of CUDA by running:

!nvcc --version

Second update

This code now seems to fail, see the follow-up question at How to downgrade to tensorflow-gpu version 1.12 in google colab

Sudhanshu
  • 704
  • 1
  • 9
  • 24
miguelmorin
  • 5,025
  • 4
  • 29
  • 64
  • I know it's illegal but I have to say: worked perfectly. Thank you. – emremrah Mar 21 '19 at 08:53
  • @emremrah What is illegal in the answer? – user4052054 Mar 27 '20 at 20:46
  • @user4052054 StackExchange discourages comments saying "thank you" or "+1". emremah probably knows about it and took the risk. I don't think anything in the answer is illegal. – miguelmorin Mar 28 '20 at 07:38
  • @miguelmorin Nice, for a moment I thought that using `dpkg` or `apt-key` was against Colab's terms of service or something. – user4052054 Mar 29 '20 at 22:56
  • 1
    Well using pip install in Colab is not recommended since it builds tf from source to ensure compatibility. Using pip may not be very beneficial. – Arpan Srivastava Apr 05 '20 at 17:35
  • @miguelmorin I tried this but, this does not work anymore. I get "dpkg-deb (subprocess): cannot copy archive member from 'cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64-deb' to decompressor pipe: unexpected end of file or stream " error and some other errors followed by that. Can you give me an solution. I need tf-gpu=1.12 installed on my colab – Gayal Kuruppu Jun 12 '20 at 08:09
  • 1
    @GayalKuruppu This solution was a year and a half ago and I no longer use Google Colab. I suggest asking a new question and referencing this answer. – miguelmorin Jun 12 '20 at 13:31
  • @miguelmorin I did, can you help me with it? https://stackoverflow.com/q/62357382/7876086 – Gayal Kuruppu Jun 13 '20 at 19:02
  • 1
    @GayalKuruppu I'm afraid I no longer use Google Colab so I can't help you. I added your question in an update to my answer. – miguelmorin Jun 16 '20 at 17:49
39

Google recommends you not to do pip installs!!!!

  1. use this instead: %tensorflow_version 1.x

  2. Restart the Runtime and check if its changed:

import tensorflow
print(tensorflow.__version__)

Here is a link to the main article:
https://colab.research.google.com/notebooks/tensorflow_version.ipynb#scrollTo=8UvRkm1JGUrk

gawi
  • 2,843
  • 4
  • 29
  • 44
17

Google gives quite a simple solution to downgrade to the previously used Colab tf v.1.15.2. Just run the following magic line in Colab:

%tensorflow_version 1.x

Ther recommend "against using pip install to specify a particular TensorFlow version for both GPU and TPU backends. Colab builds TensorFlow from the source to ensure compatibility with our fleet of accelerators. Versions of TensorFlow fetched from PyPI by pip may suffer from performance problems or may not work at all". This means if you need GPU support, use one of the two given TF versions. The other versions will not necessary work I guess even for CPU.

1

The build process for GPU-enabled tensorflow is involved. In particular, old versions of TensorFlow use (or require) older versions of CUDA, which itself depends on system libraries and configuration beyond the scope of a pip install.

I suspect that downgrading TensorFlow on a VM configured for a newer version is going to be an involved process, perhaps involving downgrades / reinstalls of system libraries.

If it's practical, it might be simpler to update your code to use the latest version of TensorFlow, at least until Colab supports persistent backend enivronments.

Bob Smith
  • 36,107
  • 11
  • 98
  • 91
1

%tensorflow_version 1.x no longer works.

%tensorflow_version 1.x
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-8d2919c1d33c> in <module>
----> 1 get_ipython().run_line_magic('tensorflow_version', '1.x')

1 frames
/usr/local/lib/python3.8/dist-packages/google/colab/_tensorflow_magics.py in _tensorflow_version(line)
     33 
     34   if line.startswith("1"):
---> 35     raise ValueError(
     36         # pylint: disable=line-too-long
     37         textwrap.dedent("""\

ValueError: Tensorflow 1 is unsupported in Colab.

Your notebook should be updated to use Tensorflow 2.
See the guide at https://www.tensorflow.org/guide/migrate#migrate-from-tensorflow-1x-to-tensorflow-2.
ron_g
  • 1,474
  • 2
  • 21
  • 39
-1

It seems that only tensorflow 2 is supported by Colab, but that's not true, you still can use pip to uninstall tensorflow 2 and install a specific version of tf1. !yes|pip uninstall tensorflow, !pip install tensorflow==1.15.5 Maybe you should install other dependencies. So use !pip install -r requirements.txt Attention! You must restart the runtime in order to use newly installed versions.

Claude COULOMBE
  • 3,434
  • 2
  • 36
  • 39