Search code examples
pythongpugoogle-colaboratory

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?


Solution

  • 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.