Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
alozowski
commited on
Commit
•
ebdd31b
1
Parent(s):
0c1e1e3
size checker depends on model precision
Browse files- src/submission/submit.py +48 -13
src/submission/submit.py
CHANGED
@@ -2,6 +2,9 @@ import json
|
|
2 |
import os
|
3 |
from datetime import datetime, timezone
|
4 |
|
|
|
|
|
|
|
5 |
from src.display.formatting import styled_error, styled_message, styled_warning
|
6 |
from src.envs import (
|
7 |
API,
|
@@ -23,6 +26,30 @@ from src.submission.check_validity import (
|
|
23 |
REQUESTED_MODELS = None
|
24 |
USERS_TO_SUBMISSION_DATES = None
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def add_new_eval(
|
28 |
model: str,
|
@@ -72,12 +99,20 @@ def add_new_eval(
|
|
72 |
|
73 |
# Check model size early
|
74 |
model_size = get_model_size(model_info=model_info, precision=precision)
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
architecture = "?"
|
83 |
# Is the model on the hub?
|
@@ -134,13 +169,13 @@ def add_new_eval(
|
|
134 |
f.write(json.dumps(eval_entry))
|
135 |
|
136 |
print("Uploading eval file")
|
137 |
-
API.upload_file(
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
)
|
144 |
|
145 |
# Remove the local file
|
146 |
os.remove(out_path)
|
|
|
2 |
import os
|
3 |
from datetime import datetime, timezone
|
4 |
|
5 |
+
from dataclasses import dataclass
|
6 |
+
from transformers import AutoConfig
|
7 |
+
|
8 |
from src.display.formatting import styled_error, styled_message, styled_warning
|
9 |
from src.envs import (
|
10 |
API,
|
|
|
26 |
REQUESTED_MODELS = None
|
27 |
USERS_TO_SUBMISSION_DATES = None
|
28 |
|
29 |
+
@dataclass
|
30 |
+
class ModelSizeChecker:
|
31 |
+
model: str
|
32 |
+
precision: str
|
33 |
+
model_size_in_b: float
|
34 |
+
|
35 |
+
def get_precision_factor(self):
|
36 |
+
if self.precision in ["float16", "bfloat16"]:
|
37 |
+
return 1
|
38 |
+
elif self.precision == "8bit":
|
39 |
+
return 2
|
40 |
+
elif self.precision == "4bit":
|
41 |
+
return 4
|
42 |
+
elif self.precision == "GPTQ":
|
43 |
+
config = AutoConfig.from_pretrained(self.model)
|
44 |
+
num_bits = int(config.quantization_config["bits"])
|
45 |
+
bits_to_precision_factor = {2: 8, 3: 6, 4: 4, 8: 2}
|
46 |
+
return bits_to_precision_factor.get(num_bits, 1)
|
47 |
+
else:
|
48 |
+
raise Exception(f"Unknown precision {self.precision}.")
|
49 |
+
|
50 |
+
def can_evaluate(self):
|
51 |
+
precision_factor = self.get_precision_factor()
|
52 |
+
return self.model_size_in_b <= 140 * precision_factor
|
53 |
|
54 |
def add_new_eval(
|
55 |
model: str,
|
|
|
99 |
|
100 |
# Check model size early
|
101 |
model_size = get_model_size(model_info=model_info, precision=precision)
|
102 |
+
|
103 |
+
# First check: Absolute size limit for float16 and bfloat16
|
104 |
+
if precision in ["float16", "bfloat16"] and model_size > 100:
|
105 |
+
return styled_error(f"Sadly, models larger than 100B parameters cannot be submitted in {precision} precision at this time. "
|
106 |
+
f"Your model size: {model_size:.2f}B parameters.")
|
107 |
+
|
108 |
+
# Second check: Precision-adjusted size limit
|
109 |
+
size_checker = ModelSizeChecker(model=model, precision=precision, model_size_in_b=model_size)
|
110 |
+
|
111 |
+
if not size_checker.can_evaluate():
|
112 |
+
precision_factor = size_checker.get_precision_factor()
|
113 |
+
max_size = 140 * precision_factor
|
114 |
+
return styled_error(f"Sadly, models this big ({model_size:.2f}B parameters) cannot be evaluated automatically "
|
115 |
+
f"at the moment on our cluster. The maximum size for {precision} precision is {max_size:.2f}B parameters.")
|
116 |
|
117 |
architecture = "?"
|
118 |
# Is the model on the hub?
|
|
|
169 |
f.write(json.dumps(eval_entry))
|
170 |
|
171 |
print("Uploading eval file")
|
172 |
+
# API.upload_file(
|
173 |
+
# path_or_fileobj=out_path,
|
174 |
+
# path_in_repo=out_path.split("eval-queue/")[1],
|
175 |
+
# repo_id=QUEUE_REPO,
|
176 |
+
# repo_type="dataset",
|
177 |
+
# commit_message=f"Add {model} to eval queue",
|
178 |
+
# )
|
179 |
|
180 |
# Remove the local file
|
181 |
os.remove(out_path)
|