phate334 commited on
Commit
6160b72
1 Parent(s): 1a8deb0

[modify] simplify table

Browse files
Files changed (4) hide show
  1. app/models.py +0 -2
  2. app/tables.py +38 -0
  3. app/utils.py +5 -5
  4. main.py +7 -13
app/models.py CHANGED
@@ -1,5 +1,3 @@
1
- from typing import Optional
2
-
3
  from pydantic import BaseModel, Field
4
 
5
 
 
 
 
1
  from pydantic import BaseModel, Field
2
 
3
 
app/tables.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+
3
+ from app.models import Architecture, Estimate, Metadata, Tokenizer
4
+ from app.utils import abbreviate_number, human_readable_size
5
+
6
+
7
+ def get_model_info_df(
8
+ metadata: Metadata, architecture: Architecture, tokenizer: Tokenizer
9
+ ):
10
+ return pd.DataFrame(
11
+ [
12
+ {
13
+ "Type": metadata.type_,
14
+ "Name": metadata.name,
15
+ "Architecture": metadata.architecture,
16
+ "File Size": human_readable_size(metadata.file_size),
17
+ "Parameters": abbreviate_number(metadata.parameters),
18
+ "Bits Per Weight": round(metadata.bits_per_weight, 2),
19
+ "Maximum Context Length": architecture.maximum_context_length,
20
+ "Vocabulary Length": architecture.vocabulary_length,
21
+ "Tokenizer Model": tokenizer.model,
22
+ "Tokens Size": human_readable_size(tokenizer.tokens_size),
23
+ }
24
+ ]
25
+ )
26
+
27
+
28
+ def get_estimate_df(estimate: Estimate):
29
+ return pd.DataFrame(
30
+ [
31
+ {
32
+ "Context Size": estimate.context_size,
33
+ "Flash Attention": estimate.flash_attention,
34
+ "Logical Batch Size": estimate.logical_batch_size,
35
+ "Physical Batch Size": estimate.physical_batch_size,
36
+ }
37
+ ]
38
+ )
app/utils.py CHANGED
@@ -1,15 +1,15 @@
1
  def human_readable_size(size_in_bytes: int) -> str:
2
- # 將檔案大小轉換為人類可讀的格式
3
  for unit in ["B", "KB", "MB", "GB", "TB", "PB"]:
4
  if size_in_bytes < 1024:
5
- return f"{size_in_bytes:.2f}{unit}"
6
  size_in_bytes /= 1024
7
- return f"{size_in_bytes:.2f}EB"
8
 
9
 
10
  def abbreviate_number(number: int) -> str:
11
- # 將大數字轉換為縮寫格式
12
  for unit, threshold in [("B", 1e9), ("M", 1e6), ("K", 1e3)]:
13
  if number >= threshold:
14
- return f"{number/threshold:.2f}{unit}"
15
  return str(number)
 
1
  def human_readable_size(size_in_bytes: int) -> str:
2
+ # Convert file size to a human-readable format
3
  for unit in ["B", "KB", "MB", "GB", "TB", "PB"]:
4
  if size_in_bytes < 1024:
5
+ return f"{size_in_bytes:.2f} {unit}"
6
  size_in_bytes /= 1024
7
+ return f"{size_in_bytes:.2f} EB"
8
 
9
 
10
  def abbreviate_number(number: int) -> str:
11
+ # Convert large numbers to abbreviated format
12
  for unit, threshold in [("B", 1e9), ("M", 1e6), ("K", 1e3)]:
13
  if number >= threshold:
14
+ return f"{number/threshold:.2f} {unit}"
15
  return str(number)
main.py CHANGED
@@ -6,6 +6,7 @@ import gradio as gr
6
  import pandas as pd
7
 
8
  from app.models import GgufParser
 
9
 
10
  GGUF_PARSER_VERSION = os.getenv("GGUF_PARSER_VERSION", "v0.12.0")
11
  gguf_parser = Path("gguf-parser-linux-amd64")
@@ -19,19 +20,14 @@ def process_url(url, context_length):
19
  f"./{gguf_parser} --ctx-size={context_length} -url {url} --json"
20
  ).read()
21
  parser_result = GgufParser.model_validate_json(res)
22
- # data = json.loads(res)
23
 
24
- metadata_df = pd.DataFrame([parser_result.metadata.model_dump()])
25
-
26
- architecture_df = pd.DataFrame([parser_result.architecture.model_dump()])
27
-
28
- tokenizer_df = pd.DataFrame([parser_result.tokenizer.model_dump()])
29
-
30
- estimate_df = pd.DataFrame(
31
- [parser_result.estimate.model_dump(exclude_none=True)]
32
  )
33
 
34
- return metadata_df, architecture_df, tokenizer_df, estimate_df
 
 
35
  except Exception as e:
36
  return e
37
 
@@ -52,9 +48,7 @@ if __name__ == "__main__":
52
  fn=process_url,
53
  inputs=[url_input, context_length],
54
  outputs=[
55
- gr.DataFrame(label="METADATA"),
56
- gr.DataFrame(label="ARCHITECTURE"),
57
- gr.DataFrame(label="TOKENIZER"),
58
  gr.DataFrame(label="ESTIMATE"),
59
  ],
60
  )
 
6
  import pandas as pd
7
 
8
  from app.models import GgufParser
9
+ from app.tables import get_estimate_df, get_model_info_df
10
 
11
  GGUF_PARSER_VERSION = os.getenv("GGUF_PARSER_VERSION", "v0.12.0")
12
  gguf_parser = Path("gguf-parser-linux-amd64")
 
20
  f"./{gguf_parser} --ctx-size={context_length} -url {url} --json"
21
  ).read()
22
  parser_result = GgufParser.model_validate_json(res)
 
23
 
24
+ model_info = get_model_info_df(
25
+ parser_result.metadata, parser_result.architecture, parser_result.tokenizer
 
 
 
 
 
 
26
  )
27
 
28
+ estimate_df = get_estimate_df(parser_result.estimate)
29
+
30
+ return model_info, estimate_df
31
  except Exception as e:
32
  return e
33
 
 
48
  fn=process_url,
49
  inputs=[url_input, context_length],
50
  outputs=[
51
+ gr.DataFrame(label="Model Info"),
 
 
52
  gr.DataFrame(label="ESTIMATE"),
53
  ],
54
  )