Spaces:
Running
Running
File size: 563 Bytes
1a1e2eb 3a67739 8359204 29b5c59 1a1e2eb 3a67739 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # Thunder/utils/human_readable.py
from Thunder.utils.logger import logger
_UNITS = ('', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
def humanbytes(size: int, decimal_places: int = 2) -> str:
try:
if not size:
return "0 B"
n = 0
while size >= 1024 and n < len(_UNITS) - 1:
size /= 1024
n += 1
return f"{round(size, decimal_places)} {_UNITS[n]}B"
except Exception as e:
logger.error(f"Error in humanbytes for size {size}: {e}", exc_info=True)
return "N/A"
|