3

I'm a biginner in torch and python,

I was experimenting with some codes in machine learning that I found online using Google COlab and I got the following error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-4-d4b0db6cedae> in <module>()
    295                         input_dropout=input_dropout, hidden_dropout1=hidden_dropout1,
    296                         hidden_dropout2= hidden_dropout2, label_smoothing= label_smoothing)
--> 297 experiment.train_and_eval()
    298 
    299 

2 frames
/usr/local/lib/python3.6/dist-packages/torch/cuda/__init__.py in _lazy_init()
    195                 "Cannot re-initialize CUDA in forked subprocess. " + msg)
    196         _check_driver()
--> 197         torch._C._cuda_init()
    198         _cudart = _load_cudart()
    199         _cudart.cudaGetErrorName.restype = ctypes.c_char_p

RuntimeError: cuda runtime error (100) : no CUDA-capable device is detected at /pytorch/aten/src/THC/THCGeneral.cpp:50

I understand that cude is for GPU processing? So how can I fix the problem? I was experimenting with codes in this link:

Community
  • 1
  • 1
user42493
  • 813
  • 4
  • 14
  • 34
  • Does this answer your question? [How to install CUDA in Google Colab GPU's](https://stackoverflow.com/questions/50560395/how-to-install-cuda-in-google-colab-gpus) – Ahwar Aug 10 '20 at 16:49

2 Answers2

16

Have you tried the following?

Go to Menu > Runtime > Change runtime.

Change hardware acceleration to GPU.

How to install CUDA in Google Colab GPU's

oittaa
  • 599
  • 3
  • 16
  • Ok I tried but there was a message saying that to make the most out of colab, I should try to avoid using GPU? Also, is there a way to alter the code to not use GPU? – user42493 Apr 14 '20 at 14:38
  • As far as I know, your code remains the same regardless you choose CPU or GPU. Once you choose GPU, you code will run with GPU without any code changes. So, if you want CPU only, the easiest way is still, change it back to CPU in the dropdown. – dgg32 Apr 15 '20 at 14:36
  • 1
    Colab is free and GPU cost resources. That is why Google Cclaboratory is saying that only enable GPU when you have the use of them otherwise use CPU for all computation. – Ahwar Sep 23 '20 at 09:25
2

In addtion to the above answer, you can use Google's TPU too. If you are Colab Pro, there is a catch: avoid using them unless you really need to, because Google will lower your priority to use the resource next time:

From their official description page

Resources in Colab Pro are prioritized for subscribers who have recently used less resources, in order to prevent the monopolization of limited resources by a small number of users. To get the most out of Colab Pro, consider closing your Colab tabs when you are done with your work, and avoid opting for GPUs or extra memory when it is not needed for your work. This will make it less likely that you will run into usage limits within Colab Pro.

I am not sure whether it is true for normal users. But based on my own experience, GPU and TPU are not always available. And if they become in-available in the middle of your coding and running, all the previous run/finished cells become "unrun" again. So a small risk you would take.

dgg32
  • 1,409
  • 1
  • 13
  • 33