简体   繁体   中英

How to upgrade tensorflow with GPU on google colaboratory

Currently google colaboratory uses tensorflow 1.4.1. I want to upgrade it to 1.5.0 version. Each time when i executed !pip install --upgrade tensorflow command, notebook instance succesfully upgrades the tensorflow version to 1.5.0. But after upgrade operation tensorflow instance only supports "CPU".

When i have executed this command it shows nothing :

from tensorflow.python.client import device_lib device_lib.list_local_devices()

Should there be another way for upgrading tensorflow ? such as upgrading to tensorflow-gpu package ? Also when will notebooks will come with upgraded tensorflows ?

As of 2020, Colab can run Tensorflow 2.0. Uninstall the current version of Tensorflow:

!pip uninstall tensorflow

and simply reinstall using pip.

!pip install tensorflow==2.0.0

If you so choose, you can also install the beta version with

!pip install tensorflow==2.0.0-beta1

Once you've reinstalled Tensorflow, make sure you don't forget to restart the runtime under the Runtime tab.

A native solution is to start your code with

%tensorflow_version 2.x

Even if you will install gpu version !pip install tensorflow-gpu==1.5.0 it will still fail to import it because of the cuda libraries. Currently I have not found a way to use 1.5 version with GPU. So I would rather use 1.4.1 with gpu than 1.5 without gpu.

You can send them a feedback ( Home - Send Feedback ) and hopefully if enough people will send something similar, they will update the new gpu version.

Google Colaboratory seems to now support tensorflow up to version 1.6.0rc1 .

import tensorflow as tf
tf.__version__

#'1.6.0-rc1'

And the gpu should work if you enable the GPU hardware accelerator . Then, you can test if things are working:

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

Output:

[name: "/device:CPU:0"
 device_type: "CPU"
 memory_limit: 268435456
 locality {
 }
 incarnation: 14621691266205111434, name: "/device:GPU:0"
 device_type: "GPU"
 memory_limit: 198836224
 locality {
   bus_id: 1
 }
 incarnation: 17821632640358169265
 physical_device_desc: "device: 0, name: Tesla K80, pci bus id: 0000:00:04.0, compute capability: 3.7"]

Edit: this will not work. Look at Salvador's answer.

Uninstall tensorflow

!pip uninstall tensorflow -y

install tensorflow-gpu

!pip install tensorflow-gpu==1.5.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM