INNER CODE UNIT · Python
_format_bytes
cubist38/mlx-openai-server · app/main.py:44
def _format_bytes(n: int) -> str:
"""Render a byte count in a human-friendly unit.
The prompt-cache byte budget defaults to ``1 << 63`` as a sentinel for
"unbounded", which reads as a 19-digit integer in the startup banner.
This helper turns that (and more ordinary values) into something a human
can read at a glance.
"""
if n >= (1 << 60):
return "unbounded"
gib = n / (1024**3)
if gib >= 1:
return f"{gib:.2f} GiB"
mib = n / (1024**2)
if mib >= 1:
return f"{mib:.2f} MiB"
return f"{n} B"