Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
FinancialSupport
commited on
Commit
β’
5adaf8f
1
Parent(s):
b9d03b8
Update src/display/utils.py
Browse files- src/display/utils.py +135 -135
src/display/utils.py
CHANGED
@@ -1,135 +1,135 @@
|
|
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="π’")
|
66 |
-
FT = ModelDetails(name="fine-tuned", symbol="πΆ")
|
67 |
-
IFT = ModelDetails(name="instruction-tuned", symbol="β")
|
68 |
-
RL = ModelDetails(name="RL-tuned", symbol="π¦")
|
69 |
-
Unknown = ModelDetails(name="", symbol="?")
|
70 |
-
|
71 |
-
def to_str(self, separator=" "):
|
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 "
|
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 |
-
float32 = ModelDetails("float32")
|
95 |
-
#qt_8bit = ModelDetails("8bit")
|
96 |
-
#qt_4bit = ModelDetails("4bit")
|
97 |
-
#qt_GPTQ = ModelDetails("GPTQ")
|
98 |
-
Unknown = ModelDetails("?")
|
99 |
-
|
100 |
-
def from_str(precision):
|
101 |
-
if precision in ["torch.float16", "float16"]:
|
102 |
-
return Precision.float16
|
103 |
-
if precision in ["torch.bfloat16", "bfloat16"]:
|
104 |
-
return Precision.bfloat16
|
105 |
-
if precision in ["float32"]:
|
106 |
-
return Precision.float32
|
107 |
-
#if precision in ["8bit"]:
|
108 |
-
# return Precision.qt_8bit
|
109 |
-
#if precision in ["4bit"]:
|
110 |
-
# return Precision.qt_4bit
|
111 |
-
#if precision in ["GPTQ", "None"]:
|
112 |
-
# return Precision.qt_GPTQ
|
113 |
-
return Precision.Unknown
|
114 |
-
|
115 |
-
# Column selection
|
116 |
-
COLS = [c.name for c in fields(AutoEvalColumn) if not c.hidden]
|
117 |
-
TYPES = [c.type for c in fields(AutoEvalColumn) if not c.hidden]
|
118 |
-
COLS_LITE = [c.name for c in fields(AutoEvalColumn) if c.displayed_by_default and not c.hidden]
|
119 |
-
TYPES_LITE = [c.type for c in fields(AutoEvalColumn) if c.displayed_by_default and not c.hidden]
|
120 |
-
|
121 |
-
EVAL_COLS = [c.name for c in fields(EvalQueueColumn)]
|
122 |
-
EVAL_TYPES = [c.type for c in fields(EvalQueueColumn)]
|
123 |
-
|
124 |
-
BENCHMARK_COLS = [t.value.col_name for t in Tasks]
|
125 |
-
|
126 |
-
NUMERIC_INTERVALS = {
|
127 |
-
"?": pd.Interval(-1, 0, closed="right"),
|
128 |
-
"~1.5": pd.Interval(0, 2, closed="right"),
|
129 |
-
"~3": pd.Interval(2, 4, closed="right"),
|
130 |
-
"~7": pd.Interval(4, 9, closed="right"),
|
131 |
-
"~13": pd.Interval(9, 20, closed="right"),
|
132 |
-
"~35": pd.Interval(20, 45, closed="right"),
|
133 |
-
"~60": pd.Interval(45, 70, closed="right"),
|
134 |
-
"70+": pd.Interval(70, 10000, closed="right"),
|
135 |
-
}
|
|
|
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="π’")
|
66 |
+
FT = ModelDetails(name="fine-tuned", symbol="πΆ")
|
67 |
+
IFT = ModelDetails(name="instruction-tuned", symbol="β")
|
68 |
+
RL = ModelDetails(name="RL-tuned", symbol="π¦")
|
69 |
+
Unknown = ModelDetails(name="", symbol="?")
|
70 |
+
|
71 |
+
def to_str(self, separator=" "):
|
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 "merged" 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 |
+
float32 = ModelDetails("float32")
|
95 |
+
#qt_8bit = ModelDetails("8bit")
|
96 |
+
#qt_4bit = ModelDetails("4bit")
|
97 |
+
#qt_GPTQ = ModelDetails("GPTQ")
|
98 |
+
Unknown = ModelDetails("?")
|
99 |
+
|
100 |
+
def from_str(precision):
|
101 |
+
if precision in ["torch.float16", "float16"]:
|
102 |
+
return Precision.float16
|
103 |
+
if precision in ["torch.bfloat16", "bfloat16"]:
|
104 |
+
return Precision.bfloat16
|
105 |
+
if precision in ["float32"]:
|
106 |
+
return Precision.float32
|
107 |
+
#if precision in ["8bit"]:
|
108 |
+
# return Precision.qt_8bit
|
109 |
+
#if precision in ["4bit"]:
|
110 |
+
# return Precision.qt_4bit
|
111 |
+
#if precision in ["GPTQ", "None"]:
|
112 |
+
# return Precision.qt_GPTQ
|
113 |
+
return Precision.Unknown
|
114 |
+
|
115 |
+
# Column selection
|
116 |
+
COLS = [c.name for c in fields(AutoEvalColumn) if not c.hidden]
|
117 |
+
TYPES = [c.type for c in fields(AutoEvalColumn) if not c.hidden]
|
118 |
+
COLS_LITE = [c.name for c in fields(AutoEvalColumn) if c.displayed_by_default and not c.hidden]
|
119 |
+
TYPES_LITE = [c.type for c in fields(AutoEvalColumn) if c.displayed_by_default and not c.hidden]
|
120 |
+
|
121 |
+
EVAL_COLS = [c.name for c in fields(EvalQueueColumn)]
|
122 |
+
EVAL_TYPES = [c.type for c in fields(EvalQueueColumn)]
|
123 |
+
|
124 |
+
BENCHMARK_COLS = [t.value.col_name for t in Tasks]
|
125 |
+
|
126 |
+
NUMERIC_INTERVALS = {
|
127 |
+
"?": pd.Interval(-1, 0, closed="right"),
|
128 |
+
"~1.5": pd.Interval(0, 2, closed="right"),
|
129 |
+
"~3": pd.Interval(2, 4, closed="right"),
|
130 |
+
"~7": pd.Interval(4, 9, closed="right"),
|
131 |
+
"~13": pd.Interval(9, 20, closed="right"),
|
132 |
+
"~35": pd.Interval(20, 45, closed="right"),
|
133 |
+
"~60": pd.Interval(45, 70, closed="right"),
|
134 |
+
"70+": pd.Interval(70, 10000, closed="right"),
|
135 |
+
}
|