How to install CUDA in Google Colab GPU's

六眼飞鱼酱① 提交于 2020-04-27 21:09:10

问题


It seems that Google Colab GPU's doesn't come with CUDA Toolkit, how can I install CUDA in Google Colab GPU's. I am getting this error in installing mxnet in Google Colab.

Installing collected packages: mxnet
Successfully installed mxnet-1.2.0

ERROR: Incomplete installation for leveraging GPUs for computations. Please make sure you have CUDA installed and run the following line in your terminal and try again:

pip uninstall -y mxnet && pip install mxnet-cu90==1.1.0

Adjust 'cu90' depending on your CUDA version ('cu75' and 'cu80' are also available). You can also disable GPU usage altogether by invoking turicreate.config.set_num_gpus(0). An exception has occurred, use %tb to see the full traceback.

SystemExit: 1

回答1:


I pretty much believe that Google Colab has Cuda pre-installed... You can make sure by opening a new notebook and type !nvcc --version which would return the installed Cuda version.

Here is mine:




回答2:


  1. Go here: https://developer.nvidia.com/cuda-downloads
  2. Select Linux -> x86_64 -> Ubuntu -> 16.04 -> deb (local)
  3. Copy link from the download button.
  4. Now you have to compose the sequence of commands. First one will be the call to wget that will download CUDA installer from the link you saved on step 3
  5. There will be installation instruction under "Base installer" section. Copy them as well, but remove sudo from all the lines.
  6. Preface each line with commands with !, insert into a cell and run
  7. For me the command sequence was the following:
    !wget https://developer.nvidia.com/compute/cuda/9.2/Prod/local_installers/cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64 -O cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64.deb !dpkg -i cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64.deb !apt-key add /var/cuda-repo-9-2-local/7fa2af80.pub !apt-get update !apt-get install cuda
  8. Now finally install mxnet. As cuda version I installed above is 9.2 I had to slighly change your command: !pip install mxnet-cu92
  9. Successfully installed graphviz-0.8.3 mxnet-cu92-1.2.0



回答3:


Cuda is not showing on your notebook because you have not enabled GPU in Colab.

The Google Colab comes with both options GPU or without GPU. You can enable or disable GPU in runtime settings

Go to Menu > Runtime > Change runtime.

Change hardware acceleration to GPU.

To check if GPU is running or not, run following command

!nvidia-smi

If output is like following image it means your GPU and cuda is working. You can see cuda version also.

After that to check if PyTorch is capable of using GPU, run the following code.

import torch
torch.cuda.is_available()
# Output would be True if Pytorch is using GPU otherwise it would be False.

To check if TensorFlow is capable of using GPU, run the following code.

import tensorflow as tf
tf.test.gpu_device_name()
# Standard output is '/device:GPU:0'



回答4:


If you switch to using GPU then CUDA will be available on your VM. Basically what you need to do is to match MXNet's version with installed CUDA version.

Here's what I used to install MXNet on Colab:

First check the CUDA version

!cat /usr/local/lib/python3.6/dist-packages/external/local_config_cuda/cuda/cuda/cuda_config.h |\
grep TF_CUDA_VERSION

For me it outputted #define TF_CUDA_VERSION "8.0"

Then I installed MXNet with

!pip install mxnet-cu80



回答5:


I think the easiest way here is to install mxnet-cu80. Just use the following code:

!pip install mxnet-cu80
import mxnet as mx

And you could check whether it works by:

a = mx.nd.ones((2, 3), mx.gpu())
b = a * 2 + 1
b.asnumpy()

I think colab right now just support cu80 and higher versions won't work.

For more information, you could see the following two websites:

Google Colab Free GPU Tutorial

Installing mxnet

Happy Coding :D




回答6:


To run in Colab, you need CUDA 8 (mxnet 1.1.0 for cuda 9+ is broken). But Google Colab runs now 9.2. There is, however the way to uninstall 9.2, install 8.0 and then install mxnet 1.1.0 cu80.

The complete jupyter code is here : Medium




回答7:


There is a guide which clearly explains that how to enable Cuda in Colab.



来源:https://stackoverflow.com/questions/50560395/how-to-install-cuda-in-google-colab-gpus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!