Unverified Commit 7f03282c authored by Stas Bekman's avatar Stas Bekman Committed by GitHub
Browse files

[debug utils] see_memory_usage fixes (#890)

* see_memory_usage fixes

* didn't expect pt-1.2

* fix the order of things

* fix the order of things
parent 22d5a1f3
......@@ -8,6 +8,7 @@ Helper functions and classes from multiple sources.
import os
import psutil
import gc
from math import ceil
from math import floor
from bisect import bisect_left, bisect_right
......@@ -551,6 +552,9 @@ def see_memory_usage(message, force=False):
if torch.distributed.is_initialized() and not torch.distributed.get_rank() == 0:
return
# python doesn't do real-time garbage collection so do it explicitly to get the correct RAM reports
gc.collect()
# Print message except when distributed but not rank 0
logger.info(message)
logger.info(
......@@ -564,6 +568,10 @@ def see_memory_usage(message, force=False):
logger.info(
f'CPU Virtual Memory: used = {used_GB} GB, percent = {vm_stats.percent}%')
# get the peak memory to report correct data, so reset the counter for the next call
if hasattr(torch.cuda, "reset_peak_memory_stats"): # pytorch 1.4+
torch.cuda.reset_peak_memory_stats()
def call_to_str(base, *args, **kwargs):
"""Construct a string representation of a call.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment