Source code for ls_mlkit.util.resource_monitor
import os
import psutil
import torch
[docs]
def print_cpu_memory():
mem = psutil.virtual_memory()
str(round(mem.total / 1024**3))
str(round(mem.used / 1024**3))
str(round(mem.percent))
free = str(round(mem.free / 1024**3))
process = psutil.Process(os.getpid())
memory_info = process.memory_info()
memory_usage_in_bytes = memory_info.rss
# print("CPU memory size of all:" + total + "GB")
# print("CPU memory used:" + used + "GB(" + use_per + "%)")
print(f"CPU memory used:{memory_usage_in_bytes / 1024 ** 3}GB")
print("CPU memory available :" + free + "GB")
[docs]
def print_gpu_memory():
allocated_memory = torch.cuda.memory_allocated() / (1024**3)
max_allocated = torch.cuda.max_memory_allocated()
print(f"GPU Allocated Memory: {allocated_memory:.2f} GB")
print(f"GPU max_memory_allocated {max_allocated / (1024 ** 3)} GB")