Skip to content

Instantly share code, notes, and snippets.

@jojonki
Created November 24, 2017 03:25
Show Gist options
  • Save jojonki/fc09a065513bda8ab564f7d85c687d36 to your computer and use it in GitHub Desktop.
Save jojonki/fc09a065513bda8ab564f7d85c687d36 to your computer and use it in GitHub Desktop.
print memory usage in python
# https://discuss.pytorch.org/t/how-pytorch-releases-variable-garbage/7277/2
def memReport():
for obj in gc.get_objects():
if torch.is_tensor(obj) or (hasattr(obj, 'data') and torch.is_tensor(obj.data)):
print(type(obj), obj.size())
def cpuStats():
print(sys.version)
print(psutil.cpu_percent())
print(psutil.virtual_memory()) # physical memory usage
pid = os.getpid()
py = psutil.Process(pid)
memoryUse = py.memory_info()[0] / 2. ** 30 # memory use in GB...I think
print('memory GB:', memoryUse)
cpuStats()
memReport()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment