torch_utils/utils/memory.py
2020-03-31 13:46:01 +09:00

8 lines
300 B
Python

def human_size(byte_count: int) -> str:
"""Output byte amount in human readable format"""
amount = float(byte_count)
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi']:
if amount < 1024.0:
break
amount /= 1024.0
return f'{amount:.2f}{unit}B'