INNER CODE UNIT · Python
human
FareedKhan-dev/kimi-k3-in-c · tools/budget.py:69
def human(b: float) -> str:
for u in ("B", "KB", "MB", "GB", "TB"):
if abs(b) < 1000.0:
return "%7.2f %s" % (b, u)
b /= 1000.0
return "%7.2f PB" % b
def read_header(path: str) -> dict:
"""Return one shard's tensor index.
A safetensors file starts with an 8-byte little-endian length followed by that many
bytes of JSON. Only those bytes are read, so this touches a few hundred KB of a
17 GB shard.
The length is bounds-checked before it is used as a read size: it comes from a file
that may have been fetched from a mirror, and an absurd value would otherwise turn
into an absurd allocation.