Given a model parameter count and a numerical dtype, return the bytes of memory the weights occupy.
Signature: def weight_memory_bytes(n_params: int, dtype: str) -> int
Supported dtypes and their bytes-per-parameter:
'fp32' -> 4'fp16' -> 2'bf16' -> 2'int8' -> 1'int4' -> 0.5 (round down via integer math)Example: A 7B parameter model in fp16 needs 7e9 * 2 = 1.4e10 = 14_000_000_000 bytes (~14 GB).
For int4, return n_params // 2 (we round down — int4 packs two values per byte).
Math
Asked at
Test Results