Skip to content

Commit 57ad81b

Browse files
authored
Add version display on table and JSON output (#36)
1 parent 158d77e commit 57ad81b

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/hf_mem/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from importlib.metadata import version
2+
3+
__version__ = version("hf-mem")

src/hf_mem/cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import httpx
1313

14+
from hf_mem import __version__
1415
from hf_mem.metadata import parse_safetensors_metadata
1516
from hf_mem.print import print_report
1617
from hf_mem.types import TorchDtypes, get_safetensors_dtype_bytes, torch_dtype_to_safetensors_dtype
@@ -364,12 +365,15 @@ async def fetch_with_semaphore(url: str) -> Dict[str, Any]:
364365
cache_size *= batch_size
365366

366367
if json_output:
367-
out = {"model_id": model_id, "revision": revision, **asdict(metadata)}
368+
from hf_mem import __version__
369+
370+
out = {"version": __version__, "model_id": model_id, "revision": revision, **asdict(metadata)}
368371
if experimental and cache_size:
369372
out["max_model_len"] = max_model_len
370373
out["batch_size"] = batch_size
371374
out["cache_size"] = cache_size
372375
out["cache_dtype"] = cache_dtype # type: ignore
376+
373377
print(json.dumps(out))
374378
else:
375379
# TODO: Use a `KvCache` dataclass instead and make sure that the JSON output is aligned

src/hf_mem/print.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import warnings
22
from typing import Any, Dict, Literal, Optional
33

4+
from hf_mem import __version__
45
from hf_mem.metadata import SafetensorsMetadata
56

67
MIN_NAME_LEN = 5
@@ -179,6 +180,9 @@ def print_report(
179180
)
180181
_print_divider(data_col_width + 1, "top")
181182

183+
_print_row("VERSION", f"hf-mem {__version__}", data_col_width)
184+
_print_divider(data_col_width + 1)
185+
182186
if cache:
183187
total_text = f"{_bytes_to_gib(combined_total):.2f} GiB ({_format_short_number(metadata.param_count)} PARAMS + KV CACHE)"
184188
total_bar = _make_bar(combined_total, combined_total, data_col_width)

0 commit comments

Comments
 (0)