Commit
c1ddcde
1 Parent(s): 14258b4

update utils

Browse files
Files changed (1) hide show
  1. src/display/utils.py +139 -67
src/display/utils.py CHANGED
@@ -1,65 +1,145 @@
1
- from dataclasses import dataclass, make_dataclass
2
- from enum import Enum
3
 
4
- import pandas as pd
 
 
5
 
6
  from src.about import Tasks
7
 
8
- def fields(raw_class):
9
- return [v for k, v in raw_class.__dict__.items() if k[:2] != "__" and k[-2:] != "__"]
10
-
11
-
12
- # These classes are for user facing column names,
13
- # to avoid having to change them all around the code
14
- # when a modif is needed
15
  @dataclass
16
  class ColumnContent:
17
  name: str
18
- type: str
19
- displayed_by_default: bool
 
20
  hidden: bool = False
 
21
  never_hidden: bool = False
22
 
23
- ## Leaderboard columns
24
- auto_eval_column_dict = []
25
- # Init
26
- auto_eval_column_dict.append(["model_type_symbol", ColumnContent, ColumnContent("T", "str", True, never_hidden=True)])
27
- auto_eval_column_dict.append(["model", ColumnContent, ColumnContent("Model", "markdown", True, never_hidden=True)])
28
- #Scores
29
- auto_eval_column_dict.append(["average", ColumnContent, ColumnContent("Average ⬆️", "number", True)])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  for task in Tasks:
31
- auto_eval_column_dict.append([task.name, ColumnContent, ColumnContent(task.value.col_name, "number", True)])
32
- # Model information
33
- auto_eval_column_dict.append(["model_type", ColumnContent, ColumnContent("Type", "str", False)])
34
- auto_eval_column_dict.append(["architecture", ColumnContent, ColumnContent("Architecture", "str", False)])
35
- auto_eval_column_dict.append(["weight_type", ColumnContent, ColumnContent("Weight type", "str", False, True)])
36
- auto_eval_column_dict.append(["precision", ColumnContent, ColumnContent("Precision", "str", False)])
37
- auto_eval_column_dict.append(["license", ColumnContent, ColumnContent("Hub License", "str", False)])
38
- auto_eval_column_dict.append(["params", ColumnContent, ColumnContent("#Params (B)", "number", False)])
39
- auto_eval_column_dict.append(["likes", ColumnContent, ColumnContent("Hub ❤️", "number", False)])
40
- auto_eval_column_dict.append(["still_on_hub", ColumnContent, ColumnContent("Available on the hub", "bool", False)])
41
- auto_eval_column_dict.append(["revision", ColumnContent, ColumnContent("Model sha", "str", False, False)])
42
-
43
- # We use make dataclass to dynamically fill the scores from Tasks
44
- AutoEvalColumn = make_dataclass("AutoEvalColumn", auto_eval_column_dict, frozen=True)
45
-
46
- ## For the queue columns in the submission tab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  @dataclass(frozen=True)
48
- class EvalQueueColumn: # Queue column
49
- model = ColumnContent("model", "markdown", True)
50
- revision = ColumnContent("revision", "str", True)
51
- private = ColumnContent("private", "bool", True)
52
- precision = ColumnContent("precision", "str", True)
53
- weight_type = ColumnContent("weight_type", "str", "Original")
54
- status = ColumnContent("status", "str", True)
 
 
 
55
 
56
  ## All the model information that we might need
57
  @dataclass
58
  class ModelDetails:
59
  name: str
60
  display_name: str = ""
61
- symbol: str = "" # emoji
62
-
63
 
64
  class ModelType(Enum):
65
  PT = ModelDetails(name="pretrained", symbol="🟢")
@@ -72,39 +152,31 @@ class ModelType(Enum):
72
  return f"{self.value.symbol}{separator}{self.value.name}"
73
 
74
  @staticmethod
75
- def from_str(type):
76
- if "fine-tuned" in type or "🔶" in type:
77
  return ModelType.FT
78
- if "pretrained" in type or "🟢" in type:
79
  return ModelType.PT
80
- if "RL-tuned" in type or "🟦" in type:
81
  return ModelType.RL
82
- if "instruction-tuned" in type or "⭕" in type:
83
  return ModelType.IFT
84
  return ModelType.Unknown
85
 
86
  class WeightType(Enum):
87
- Adapter = ModelDetails("Adapter")
88
- Original = ModelDetails("Original")
89
- Delta = ModelDetails("Delta")
90
 
91
  class Precision(Enum):
92
- float16 = ModelDetails("float16")
93
- bfloat16 = ModelDetails("bfloat16")
94
- Unknown = ModelDetails("?")
95
 
96
- def from_str(precision):
97
- if precision in ["torch.float16", "float16"]:
 
98
  return Precision.float16
99
- if precision in ["torch.bfloat16", "bfloat16"]:
100
  return Precision.bfloat16
101
  return Precision.Unknown
102
-
103
- # Column selection
104
- COLS = [c.name for c in fields(AutoEvalColumn) if not c.hidden]
105
-
106
- EVAL_COLS = [c.name for c in fields(EvalQueueColumn)]
107
- EVAL_TYPES = [c.type for c in fields(EvalQueueColumn)]
108
-
109
- BENCHMARK_COLS = [t.value.col_name for t in Tasks]
110
-
 
1
+ # src/display/utils.py
 
2
 
3
+ from dataclasses import dataclass
4
+ from enum import Enum
5
+ from typing import Any, List
6
 
7
  from src.about import Tasks
8
 
 
 
 
 
 
 
 
9
  @dataclass
10
  class ColumnContent:
11
  name: str
12
+ type: Any
13
+ label: str
14
+ description: str
15
  hidden: bool = False
16
+ displayed_by_default: bool = True
17
  never_hidden: bool = False
18
 
19
+ # Initialize the list of columns for the leaderboard
20
+ COLUMNS: List[ColumnContent] = []
21
+
22
+ # Essential columns
23
+ COLUMNS.append(
24
+ ColumnContent(
25
+ name="model",
26
+ type=str,
27
+ label="Model",
28
+ description="Model name",
29
+ never_hidden=True,
30
+ )
31
+ )
32
+ COLUMNS.append(
33
+ ColumnContent(
34
+ name="average",
35
+ type=float,
36
+ label="Average Accuracy (%)",
37
+ description="Average accuracy across all subjects",
38
+ )
39
+ )
40
+
41
+ # Include per-subject accuracy columns based on your subjects
42
  for task in Tasks:
43
+ COLUMNS.append(
44
+ ColumnContent(
45
+ name=task.value.benchmark,
46
+ type=float,
47
+ label=f"{task.value.col_name} (%)",
48
+ description=f"Accuracy on {task.value.col_name}",
49
+ displayed_by_default=False,
50
+ )
51
+ )
52
+
53
+ # Additional columns
54
+ COLUMNS.extend([
55
+ ColumnContent(
56
+ name="model_type",
57
+ type=str,
58
+ label="Model Type",
59
+ description="Type of the model (e.g., Transformer, RNN, etc.)",
60
+ displayed_by_default=False,
61
+ ),
62
+ ColumnContent(
63
+ name="architecture",
64
+ type=str,
65
+ label="Architecture",
66
+ description="Model architecture",
67
+ displayed_by_default=False,
68
+ ),
69
+ ColumnContent(
70
+ name="weight_type",
71
+ type=str,
72
+ label="Weight Type",
73
+ description="Type of model weights (e.g., Original, Delta, Adapter)",
74
+ displayed_by_default=False,
75
+ ),
76
+ ColumnContent(
77
+ name="precision",
78
+ type=str,
79
+ label="Precision",
80
+ description="Precision of the model weights (e.g., float16)",
81
+ displayed_by_default=False,
82
+ ),
83
+ ColumnContent(
84
+ name="license",
85
+ type=str,
86
+ label="License",
87
+ description="License of the model",
88
+ displayed_by_default=False,
89
+ ),
90
+ ColumnContent(
91
+ name="params",
92
+ type=float,
93
+ label="Parameters (B)",
94
+ description="Number of model parameters in billions",
95
+ displayed_by_default=False,
96
+ ),
97
+ ColumnContent(
98
+ name="likes",
99
+ type=int,
100
+ label="Likes",
101
+ description="Number of likes on the Hugging Face Hub",
102
+ displayed_by_default=False,
103
+ ),
104
+ ColumnContent(
105
+ name="still_on_hub",
106
+ type=bool,
107
+ label="Available on the Hub",
108
+ description="Whether the model is still available on the Hugging Face Hub",
109
+ displayed_by_default=False,
110
+ ),
111
+ ColumnContent(
112
+ name="revision",
113
+ type=str,
114
+ label="Model Revision",
115
+ description="Model revision or commit hash",
116
+ displayed_by_default=False,
117
+ ),
118
+ ])
119
+
120
+ # Now we can create lists of column names for use in the application
121
+ COLS = [col.name for col in COLUMNS]
122
+ BENCHMARK_COLS = [col.name for col in COLUMNS if col.name not in ["model", "average", "model_type", "architecture", "weight_type", "precision", "license", "params", "likes", "still_on_hub", "revision"]]
123
+
124
+ # For the queue columns in the submission tab
125
  @dataclass(frozen=True)
126
+ class EvalQueueColumn:
127
+ model: str
128
+ revision: str
129
+ private: bool
130
+ precision: str
131
+ weight_type: str
132
+ status: str
133
+
134
+ EVAL_COLS = ["model", "revision", "private", "precision", "weight_type", "status"]
135
+ EVAL_TYPES = [str, str, bool, str, str, str]
136
 
137
  ## All the model information that we might need
138
  @dataclass
139
  class ModelDetails:
140
  name: str
141
  display_name: str = ""
142
+ symbol: str = "" # emoji
 
143
 
144
  class ModelType(Enum):
145
  PT = ModelDetails(name="pretrained", symbol="🟢")
 
152
  return f"{self.value.symbol}{separator}{self.value.name}"
153
 
154
  @staticmethod
155
+ def from_str(type_str):
156
+ if "fine-tuned" in type_str or "🔶" in type_str:
157
  return ModelType.FT
158
+ if "pretrained" in type_str or "🟢" in type_str:
159
  return ModelType.PT
160
+ if "RL-tuned" in type_str or "🟦" in type_str:
161
  return ModelType.RL
162
+ if "instruction-tuned" in type_str or "⭕" in type_str:
163
  return ModelType.IFT
164
  return ModelType.Unknown
165
 
166
  class WeightType(Enum):
167
+ Adapter = "Adapter"
168
+ Original = "Original"
169
+ Delta = "Delta"
170
 
171
  class Precision(Enum):
172
+ float16 = "float16"
173
+ bfloat16 = "bfloat16"
174
+ Unknown = "Unknown"
175
 
176
+ @staticmethod
177
+ def from_str(precision_str):
178
+ if precision_str in ["torch.float16", "float16"]:
179
  return Precision.float16
180
+ if precision_str in ["torch.bfloat16", "bfloat16"]:
181
  return Precision.bfloat16
182
  return Precision.Unknown