Created
November 24, 2017 03:25
-
-
Save jojonki/fc09a065513bda8ab564f7d85c687d36 to your computer and use it in GitHub Desktop.
print memory usage in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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