[`refactor`]: Tab & URL syncing; parameter counts as model size; filtering; search

#89
by tomaarsen HF staff - opened
Files changed (6) hide show
  1. .gitignore +1 -0
  2. EXTERNAL_MODEL_RESULTS.json +0 -0
  3. README.md +1 -1
  4. app.py +0 -0
  5. utils/__init__.py +0 -0
  6. utils/model_size.py +40 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ *.pyc
EXTERNAL_MODEL_RESULTS.json CHANGED
The diff for this file is too large to render. See raw diff
 
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🥇
4
  colorFrom: blue
5
  colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 4.0.2
8
  app_file: app.py
9
  pinned: false
10
  tags:
 
4
  colorFrom: blue
5
  colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 4.20.0
8
  app_file: app.py
9
  pinned: false
10
  tags:
app.py CHANGED
The diff for this file is too large to render. See raw diff
 
utils/__init__.py ADDED
File without changes
utils/model_size.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import re
3
+ from huggingface_hub.hf_api import ModelInfo, get_safetensors_metadata, model_info as get_model_info, get_hf_file_metadata, hf_hub_url
4
+ from huggingface_hub import hf_hub_download
5
+
6
+ # Map model IDs to the number of bytes used for one parameter. So, 4 bytes for fp32, 2 bytes for fp16, etc.
7
+ # By default, we assume that the model is stored in fp32.
8
+ KNOWN_BYTES_PER_PARAM = {}
9
+
10
+
11
+ def get_model_parameters_memory(model_info: ModelInfo):
12
+ '''Get the size of the model in million of parameters.'''
13
+ try:
14
+ safetensors = get_safetensors_metadata(model_info.id)
15
+ num_parameters = sum(safetensors.parameter_count.values())
16
+ return round(num_parameters / 1e6), round(num_parameters * 4 / 1024**3, 2)
17
+ except Exception as e:
18
+ pass
19
+
20
+ filenames = [sib.rfilename for sib in model_info.siblings]
21
+ if "pytorch_model.bin" in filenames:
22
+ url = hf_hub_url(model_info.id, filename="pytorch_model.bin")
23
+ meta = get_hf_file_metadata(url)
24
+ bytes_per_param = KNOWN_BYTES_PER_PARAM.get(model_info.id, 4)
25
+ return round(meta.size / bytes_per_param / 1e6), round(meta.size / 1024**3, 2)
26
+
27
+ if "pytorch_model.bin.index.json" in filenames:
28
+ index_path = hf_hub_download(model_info.id, filename="pytorch_model.bin.index.json")
29
+ """
30
+ {
31
+ "metadata": {
32
+ "total_size": 28272820224
33
+ },....
34
+ """
35
+ size = json.load(open(index_path))
36
+ bytes_per_param = KNOWN_BYTES_PER_PARAM.get(model_info.id, 4)
37
+ if ("metadata" in size) and ("total_size" in size["metadata"]):
38
+ return round(size["metadata"]["total_size"] / bytes_per_param / 1e6), round(size["metadata"]["total_size"] / 1024**3, 2)
39
+
40
+ return None, None