in step8_pipeline_parallel_1f1b/utils.py [0:0]
def to_readable_format(num, precision=3):
num_str = str(num)
length = len(num_str)
def format_with_precision(main, decimal, suffix):
if precision == 0:
return f"{main}{suffix}"
return f"{main}.{decimal[:precision]}{suffix}"
if length > 12: # Trillions
return format_with_precision(num_str[:-12], num_str[-12:], 'T')
elif length > 9: # Billions
return format_with_precision(num_str[:-9], num_str[-9:], 'B')
elif length > 6: # Millions
return format_with_precision(num_str[:-6], num_str[-6:], 'M')
elif length > 3: # Thousands
return format_with_precision(num_str[:-3], num_str[-3:], 'K')
else:
return num_str