From f9a018882c465611bf9477cef0c125fed9998053 Mon Sep 17 00:00:00 2001 From: Vinay Damodaran Date: Thu, 12 Feb 2026 16:22:33 -0800 Subject: [PATCH 1/2] Change unit to GiB for accuracy --- src/hf_mem/print.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/hf_mem/print.py b/src/hf_mem/print.py index 3dd40f3..e6898c1 100644 --- a/src/hf_mem/print.py +++ b/src/hf_mem/print.py @@ -105,7 +105,7 @@ def _format_short_number(n: float) -> str: return f"{n:.2f}P" -def _bytes_to_gb(nbytes: int) -> float: +def _bytes_to_gib(nbytes: int) -> float: return nbytes / (1024**3) @@ -127,33 +127,33 @@ def print_report( for name, nested_metadata in metadata.components.items(): if len(metadata.components) > 1: centered_rows.append( - f"{name.upper()} ({_format_short_number(nested_metadata.param_count)} PARAMS, {_bytes_to_gb(nested_metadata.bytes_count):.2f} GB)" + f"{name.upper()} ({_format_short_number(nested_metadata.param_count)} PARAMS, {_bytes_to_gib(nested_metadata.bytes_count):.2f} GiB)" ) elif cache: centered_rows.append( - f"MODEL ({_format_short_number(nested_metadata.param_count)} PARAMS, {_bytes_to_gb(nested_metadata.bytes_count):.2f} GB)" + f"MODEL ({_format_short_number(nested_metadata.param_count)} PARAMS, {_bytes_to_gib(nested_metadata.bytes_count):.2f} GiB)" ) if cache: centered_rows.append( - f"KV CACHE ({cache['max_model_len'] * cache['batch_size']} TOKENS, {_bytes_to_gb(cache['cache_size']):.2f} GB)" + f"KV CACHE ({cache['max_model_len'] * cache['batch_size']} TOKENS, {_bytes_to_gib(cache['cache_size']):.2f} GiB)" ) data_rows = [] if cache: data_rows.append( - f"{_bytes_to_gb(combined_total):.2f} GB ({_format_short_number(metadata.param_count)} PARAMS + KV CACHE)" + f"{_bytes_to_gib(combined_total):.2f} GiB ({_format_short_number(metadata.param_count)} PARAMS + KV CACHE)" ) else: data_rows.append( - f"{_bytes_to_gb(metadata.bytes_count):.2f} GB ({_format_short_number(metadata.param_count)} PARAMS)" + f"{_bytes_to_gib(metadata.bytes_count):.2f} GiB ({_format_short_number(metadata.param_count)} PARAMS)" ) for _, nested_metadata in metadata.components.items(): for dtype, dtype_metadata in nested_metadata.dtypes.items(): data_rows.append( - f"{_bytes_to_gb(dtype_metadata.bytes_count):.2f} / {_bytes_to_gb(combined_total):.2f} GB" + f"{_bytes_to_gib(dtype_metadata.bytes_count):.2f} / {_bytes_to_gib(combined_total):.2f} GiB" ) if cache: - data_rows.append(f"{_bytes_to_gb(cache['cache_size']):.2f} / {_bytes_to_gb(combined_total):.2f} GB") + data_rows.append(f"{_bytes_to_gib(cache['cache_size']):.2f} / {_bytes_to_gib(combined_total):.2f} GiB") max_centered_len = max(len(r) for r in centered_rows) max_data_len = max(len(r) for r in data_rows) @@ -180,13 +180,13 @@ def print_report( _print_divider(data_col_width + 1, "top") if cache: - total_text = f"{_bytes_to_gb(combined_total):.2f} GB ({_format_short_number(metadata.param_count)} PARAMS + KV CACHE)" + total_text = f"{_bytes_to_gib(combined_total):.2f} GiB ({_format_short_number(metadata.param_count)} PARAMS + KV CACHE)" total_bar = _make_bar(combined_total, combined_total, data_col_width) _print_row("TOTAL MEMORY", total_text, data_col_width) _print_row("REQUIREMENTS", total_bar, data_col_width) else: model_text = ( - f"{_bytes_to_gb(metadata.bytes_count):.2f} GB ({_format_short_number(metadata.param_count)} PARAMS)" + f"{_bytes_to_gib(metadata.bytes_count):.2f} GiB ({_format_short_number(metadata.param_count)} PARAMS)" ) model_bar = _make_bar(metadata.bytes_count, metadata.bytes_count, data_col_width) _print_row("TOTAL MEMORY", model_text, data_col_width) @@ -196,14 +196,14 @@ def print_report( if len(metadata.components) > 1: _print_divider(data_col_width + 1, "top-continue") _print_centered( - f"{key.upper()} ({_format_short_number(value.param_count)} PARAMS, {_bytes_to_gb(value.bytes_count):.2f} GB)", + f"{key.upper()} ({_format_short_number(value.param_count)} PARAMS, {_bytes_to_gib(value.bytes_count):.2f} GiB)", current_len, ) _print_divider(data_col_width + 1, "top") elif cache: _print_divider(data_col_width + 1, "top-continue") _print_centered( - f"MODEL ({_format_short_number(value.param_count)} PARAMS, {_bytes_to_gb(value.bytes_count):.2f} GB)", + f"MODEL ({_format_short_number(value.param_count)} PARAMS, {_bytes_to_gib(value.bytes_count):.2f} GiB)", current_len, ) _print_divider(data_col_width + 1, "top") @@ -217,16 +217,16 @@ def print_report( ] ) for idx, (dtype, dtype_metadata) in enumerate(value.dtypes.items()): - gb_text = f"{_bytes_to_gb(dtype_metadata.bytes_count):.2f} / {_bytes_to_gb(combined_total):.2f} GB" + gib_text = f"{_bytes_to_gib(dtype_metadata.bytes_count):.2f} / {_bytes_to_gib(combined_total):.2f} GiB" _print_row( dtype.upper() + " " * (max_length - len(dtype)), - gb_text, + gib_text, data_col_width, ) bar = _make_bar( - _bytes_to_gb(dtype_metadata.bytes_count), - _bytes_to_gb(combined_total), + _bytes_to_gib(dtype_metadata.bytes_count), + _bytes_to_gib(combined_total), data_col_width, ) _print_row( @@ -241,12 +241,12 @@ def print_report( if cache: _print_divider(data_col_width + 1, "top-continue") _print_centered( - f"KV CACHE ({cache['max_model_len'] * cache['batch_size']} TOKENS, {_bytes_to_gb(cache['cache_size']):.2f} GB)", + f"KV CACHE ({cache['max_model_len'] * cache['batch_size']} TOKENS, {_bytes_to_gib(cache['cache_size']):.2f} GiB)", current_len, ) _print_divider(data_col_width + 1, "top") - kv_text = f"{_bytes_to_gb(cache['cache_size']):.2f} / {_bytes_to_gb(combined_total):.2f} GB" + kv_text = f"{_bytes_to_gib(cache['cache_size']):.2f} / {_bytes_to_gib(combined_total):.2f} GiB" _print_row( cache["cache_dtype"].upper() + " " * (max_length - len(cache["cache_dtype"])), # type: ignore kv_text, From 254de6bf99e6996091dd85c5119510463e3729c2 Mon Sep 17 00:00:00 2001 From: Vinay Damodaran Date: Tue, 17 Feb 2026 10:56:24 -0800 Subject: [PATCH 2/2] run pre-commit --- src/hf_mem/print.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hf_mem/print.py b/src/hf_mem/print.py index e6898c1..bcd83f8 100644 --- a/src/hf_mem/print.py +++ b/src/hf_mem/print.py @@ -185,9 +185,7 @@ def print_report( _print_row("TOTAL MEMORY", total_text, data_col_width) _print_row("REQUIREMENTS", total_bar, data_col_width) else: - model_text = ( - f"{_bytes_to_gib(metadata.bytes_count):.2f} GiB ({_format_short_number(metadata.param_count)} PARAMS)" - ) + model_text = f"{_bytes_to_gib(metadata.bytes_count):.2f} GiB ({_format_short_number(metadata.param_count)} PARAMS)" model_bar = _make_bar(metadata.bytes_count, metadata.bytes_count, data_col_width) _print_row("TOTAL MEMORY", model_text, data_col_width) _print_row("REQUIREMENTS", model_bar, data_col_width) @@ -217,7 +215,9 @@ def print_report( ] ) for idx, (dtype, dtype_metadata) in enumerate(value.dtypes.items()): - gib_text = f"{_bytes_to_gib(dtype_metadata.bytes_count):.2f} / {_bytes_to_gib(combined_total):.2f} GiB" + gib_text = ( + f"{_bytes_to_gib(dtype_metadata.bytes_count):.2f} / {_bytes_to_gib(combined_total):.2f} GiB" + ) _print_row( dtype.upper() + " " * (max_length - len(dtype)), gib_text,