Omartificial-Intelligence-Space
commited on
Commit
•
c1ddcde
1
Parent(s):
14258b4
update utils
Browse files- src/display/utils.py +139 -67
src/display/utils.py
CHANGED
@@ -1,65 +1,145 @@
|
|
1 |
-
|
2 |
-
from enum import Enum
|
3 |
|
4 |
-
|
|
|
|
|
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:
|
19 |
-
|
|
|
20 |
hidden: bool = False
|
|
|
21 |
never_hidden: bool = False
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
for task in Tasks:
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
@dataclass(frozen=True)
|
48 |
-
class EvalQueueColumn:
|
49 |
-
model
|
50 |
-
revision
|
51 |
-
private
|
52 |
-
precision
|
53 |
-
weight_type
|
54 |
-
status
|
|
|
|
|
|
|
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 = ""
|
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(
|
76 |
-
if "fine-tuned" in
|
77 |
return ModelType.FT
|
78 |
-
if "pretrained" in
|
79 |
return ModelType.PT
|
80 |
-
if "RL-tuned" in
|
81 |
return ModelType.RL
|
82 |
-
if "instruction-tuned" in
|
83 |
return ModelType.IFT
|
84 |
return ModelType.Unknown
|
85 |
|
86 |
class WeightType(Enum):
|
87 |
-
Adapter =
|
88 |
-
Original =
|
89 |
-
Delta =
|
90 |
|
91 |
class Precision(Enum):
|
92 |
-
float16 =
|
93 |
-
bfloat16 =
|
94 |
-
Unknown =
|
95 |
|
96 |
-
|
97 |
-
|
|
|
98 |
return Precision.float16
|
99 |
-
if
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|