How to check GPU vs CPU percentage?

Let’s say a learning step takes 5 minutes in Kaggle. During this time I can see GPU being used on and off, while the CPU is mostly on. IS there a way to check the stats which would indicate the effifiency of the GPU utilization, the percentage of time spent in CPU vs GPU in Kaggle?

I’m not sure how to get CPU utilization but in this notebook Jeremy uses the following function to view how much GPU memory is used (and to clear memory):

import gc
def report_gpu():
    print(torch.cuda.list_gpu_processes())
    gc.collect()
    torch.cuda.empty_cache()

Also found this Kaggle notebook that runs a custom script in the notebook with subprocess.Popen. Never used such a script so can’t speak to its performance.

1 Like

Hi!

Here’s a CPU part:

import psutil

def monitor_ram_cpu():
    # Get process information
    processes = psutil.process_iter()

    # Display RAM and CPU usage for each process
    for process in processes:
        try:
            memory_info = process.memory_info()
            cpu_percent = process.cpu_percent()
            print(f"Process: {process.name()}")
            print(f"RAM usage: {memory_info.rss / 1024**3:.2f} GB")
            print(f"CPU usage: {cpu_percent:.2f}%")
            print("---")
        except psutil.NoSuchProcess:
            pass

monitor_ram_cpu()

2 Likes