Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display GPU Usage While Code is Running in Colab

I have a program running on Google Colab in which I need to monitor GPU usage while it is running. I am aware that usually you would use nvidia-smi in a command line to display GPU usage, but since Colab only allows one cell to run at once at any one time, this isn't an option. Currently, I am using GPUtil and monitoring GPU and VRAM usage with GPUtil.getGPUs()[0].load and GPUtil.getGPUs()[0].memoryUsed but I can't find a way for those pieces of code to execute at the same time as the rest of my code, thus the usage numbers are much lower than they actually should be. Is there any way to print the GPU usage while other code is running?

like image 297
Matthew So Avatar asked Jun 28 '20 08:06

Matthew So


People also ask

How many hours of GPU is free in Colab?

Click on “Notebook settings” and select “GPU”. That's it. You have a free 12GB NVIDIA Tesla K80 GPU to run up to 12 hours continuously for free. It is worth mentioning both Google Colab and Kaggle offer awesome GPU power.

How much GPU does colab use?

Colab Pro and Pro+ are unavailable to residents of all but a few countries. Colab Pro and Pro+ limits GPU to NVIDIA P100 or T4. Colab Pro limits RAM to 32 GB while Pro+ limits RAM to 52 GB.

Does TensorFlow automatically use GPU in Colab?

If a TensorFlow operation has both CPU and GPU implementations, by default, the GPU device is prioritized when the operation is assigned. For example, tf. matmul has both CPU and GPU kernels and on a system with devices CPU:0 and GPU:0 , the GPU:0 device is selected to run tf.


1 Answers

Used wandb to log system metrics:

!pip install wandb
import wandb
wandb.init()

Which outputs a URL in which you can view various graphs of different system metrics.

like image 78
Matthew So Avatar answered Sep 18 '22 17:09

Matthew So