Spaces:
Runtime error
Runtime error
File size: 10,232 Bytes
d83a64f fdde5a7 d83a64f 903cbb7 d83a64f 5f67fb5 903cbb7 d83a64f fdde5a7 903cbb7 d83a64f 903cbb7 2b726be 903cbb7 e74285c 903cbb7 d83a64f e6fd1bf d83a64f fdde5a7 d83a64f 5f67fb5 903cbb7 5f67fb5 7059316 5f67fb5 63377bb 5f67fb5 d83a64f e74285c 5f67fb5 2b726be 5f67fb5 8b491ea 5f67fb5 903cbb7 5f67fb5 903cbb7 5f67fb5 903cbb7 2b726be 903cbb7 2b726be 903cbb7 e74285c 903cbb7 5f67fb5 903cbb7 5f67fb5 63377bb 5f67fb5 e74285c d83a64f 2b726be d83a64f 8b491ea d83a64f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | import json
import os
from datetime import datetime, timezone
from typing import Optional
from src.display.formatting import styled_error, styled_message, styled_warning
from src.envs import API, EVAL_REQUESTS_PATH, TOKEN, QUEUE_REPO
from src.submission.check_validity import (
already_submitted_models,
check_model_card,
get_model_size,
is_model_on_hub,
)
import gradio as gr
REQUESTED_MODELS = None
USERS_TO_SUBMISSION_DATES = None
def add_new_eval_option1(
benchmark: str,
model: str,
base_model: str,
revision: str,
precision: str,
temperature: str,
top_p: str,
top_k: str,
presence_penalty: str,
frequency_penalty: str,
repetition_penalty: str,
vllm_version: str,
user_state: str,
organization_list: list
):
global REQUESTED_MODELS
global USERS_TO_SUBMISSION_DATES
if not REQUESTED_MODELS:
REQUESTED_MODELS, USERS_TO_SUBMISSION_DATES = already_submitted_models(EVAL_REQUESTS_PATH)
user_name = ""
model_path = model
if "/" in model:
user_name = model.split("/")[0]
model_path = model.split("/")[1]
precision = precision.split(" ")[0]
current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S %z")
# Check submitter qualification
if user_name != user_state and user_name not in organization_list:
return styled_error("The submitter does not have submission rights for this model.")
# Does the organization submit more than three times in a day?
submission_times = [item['submitted_time'] for item in USERS_TO_SUBMISSION_DATES[user_name] if item['benchmark'] == benchmark]
submission_cnt = 0
for i in range(len(submission_times)):
hours_diff = (datetime.strptime(current_time, "%Y-%m-%dT%H:%M:%S %z") - datetime.strptime(submission_times[i], "%Y-%m-%dT%H:%M:%S %z")).total_seconds() / 3600
if hours_diff <= 24:
submission_cnt += 1
if submission_cnt > 3:
return styled_error("The organization already submitted three times for this benchmark today.")
# Does the model actually exist?
if revision == "":
revision = "main"
# Is the model info correctly filled?
try:
model_info = API.model_info(repo_id=model, revision=revision)
except Exception:
return styled_error("Could not get your model information. Please fill it up properly.")
model_size = get_model_size(model_info=model_info, precision=precision)
# Were the model card and license filled?
try:
license = model_info.cardData["license"]
except Exception:
return styled_error("Please select a license for your model.")
modelcard_OK, error_msg = check_model_card(model)
if not modelcard_OK:
return styled_error(error_msg)
if temperature == "":
temperature = "1.0"
if top_p == "":
top_p = "1.0"
if top_k == "":
top_k = "-1"
if presence_penalty == "":
presence_penalty = "0.0"
if frequency_penalty == "":
frequency_penalty = "0.0"
if repetition_penalty == "":
repetition_penalty = "1.0"
# Seems good, creating the eval
print("Adding new eval")
eval_entry = {
"benchmark": benchmark,
"model": model,
"base_model": base_model,
"revision": revision,
"precision": precision,
"status": "PENDING",
"submitted_time": current_time,
"likes": model_info.likes,
"params": model_size,
"license": license,
"private": False,
"temperature": float(temperature),
"top_p": float(top_p),
"top_k": float(top_k),
"vllm_version": vllm_version,
"presence_penalty": float(presence_penalty),
"frequency_penalty": float(frequency_penalty),
"repetition_penalty": float(repetition_penalty),
"load_model_code": "None",
"inference_code": "None",
"termination_code": "None",
}
# Check for duplicate submission
submission_times = [item['submitted_time'] for item in USERS_TO_SUBMISSION_DATES[user_name] if item['benchmark'] == benchmark and item['model'] == model]
submission_cnt = 0
for i in range(len(submission_times)):
hours_diff = (datetime.strptime(current_time, "%Y-%m-%dT%H:%M:%S %z") - datetime.strptime(submission_times[i], "%Y-%m-%dT%H:%M:%S %z")).total_seconds() / 3600
if hours_diff <= 24:
submission_cnt += 1
if submission_cnt > 1:
return styled_warning("This model has been already submitted within 24 hours.")
print("Creating eval file")
OUT_DIR = f"{EVAL_REQUESTS_PATH}/{user_name}"
os.makedirs(OUT_DIR, exist_ok=True)
out_path = f"{OUT_DIR}/{benchmark}_{model_path}_eval_request_False.json"
with open(out_path, "w") as f:
f.write(json.dumps(eval_entry))
print("Uploading eval file")
API.upload_file(
path_or_fileobj=out_path,
path_in_repo=out_path.split("eval-queue/")[1],
repo_id=QUEUE_REPO,
repo_type="dataset",
commit_message=f"Add {model} to eval queue",
)
# Remove the local file
os.remove(out_path)
return styled_message(
"Your request has been submitted to the evaluation queue!"
)
def add_new_eval_option2(
benchmark: str,
model: str,
base_model: str,
revision: str,
precision: str,
temperature: str,
top_p: str,
top_k: str,
presence_penalty: str,
frequency_penalty: str,
repetition_penalty: str,
load_model_code: str,
inference_code: str,
termination_code: str,
user_state: str,
organization_list: list
):
global REQUESTED_MODELS
global USERS_TO_SUBMISSION_DATES
if not REQUESTED_MODELS:
REQUESTED_MODELS, USERS_TO_SUBMISSION_DATES = already_submitted_models(EVAL_REQUESTS_PATH)
user_name = ""
model_path = model
if "/" in model:
user_name = model.split("/")[0]
model_path = model.split("/")[1]
precision = precision.split(" ")[0]
current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S %z")
# Check submitter qualification
if user_name != user_state and user_name not in organization_list:
return styled_error("The submitter does not have submission rights for this model.")
# Does the organization submit more than three times in a day?
submission_times = [item['submitted_time'] for item in USERS_TO_SUBMISSION_DATES[user_name] if item['benchmark'] == benchmark]
submission_cnt = 0
for i in range(len(submission_times)):
hours_diff = (datetime.strptime(current_time, "%Y-%m-%dT%H:%M:%S %z") - datetime.strptime(submission_times[i], "%Y-%m-%dT%H:%M:%S %z")).total_seconds() / 3600
if hours_diff <= 24:
submission_cnt += 1
if submission_cnt > 3:
return styled_error("The organization already submitted three times for this benchmark today.")
# Does the model actually exist?
if revision == "":
revision = "main"
# Is the model info correctly filled?
try:
model_info = API.model_info(repo_id=model, revision=revision)
except Exception:
return styled_error("Could not get your model information. Please fill it up properly.")
model_size = get_model_size(model_info=model_info, precision=precision)
# Were the model card and license filled?
try:
license = model_info.cardData["license"]
except Exception:
return styled_error("Please select a license for your model.")
modelcard_OK, error_msg = check_model_card(model)
if not modelcard_OK:
return styled_error(error_msg)
if temperature == "":
temperature = "1.0"
if top_p == "":
top_p = "1.0"
if top_k == "":
top_k = "-1"
if presence_penalty == "":
presence_penalty = "0.0"
if frequency_penalty == "":
frequency_penalty = "0.0"
if repetition_penalty == "":
repetition_penalty = "1.0"
# Seems good, creating the eval
print("Adding new eval")
eval_entry = {
"benchmark": benchmark,
"model": model,
"base_model": base_model,
"revision": revision,
"precision": precision,
"status": "PENDING",
"submitted_time": current_time,
"likes": model_info.likes,
"params": model_size,
"license": license,
"private": False,
"temperature": float(temperature),
"top_p": float(top_p),
"top_k": float(top_k),
"vllm_version": "None",
"presence_penalty": float(presence_penalty),
"frequency_penalty": float(frequency_penalty),
"repetition_penalty": float(repetition_penalty),
"load_model_code": load_model_code,
"inference_code": inference_code,
"termination_code": termination_code
}
# Check for duplicate submission
submission_times = [item['submitted_time'] for item in USERS_TO_SUBMISSION_DATES[user_name] if item['benchmark'] == benchmark and item['model'] == model]
submission_cnt = 0
for i in range(len(submission_times)):
hours_diff = (datetime.strptime(current_time, "%Y-%m-%dT%H:%M:%S %z") - datetime.strptime(submission_times[i], "%Y-%m-%dT%H:%M:%S %z")).total_seconds() / 3600
if hours_diff <= 24:
submission_cnt += 1
if submission_cnt > 1:
return styled_warning("This model has been already submitted within 24 hours.")
print("Creating eval file")
OUT_DIR = f"{EVAL_REQUESTS_PATH}/{user_name}"
os.makedirs(OUT_DIR, exist_ok=True)
out_path = f"{OUT_DIR}/{benchmark}_{model_path}_eval_request_False.json"
with open(out_path, "w") as f:
f.write(json.dumps(eval_entry))
print("Uploading eval file")
API.upload_file(
path_or_fileobj=out_path,
path_in_repo=out_path.split("eval-queue/")[1],
repo_id=QUEUE_REPO,
repo_type="dataset",
commit_message=f"Add {model} to eval queue",
)
# Remove the local file
os.remove(out_path)
return styled_message(
"Your request has been submitted to the evaluation queue!"
)
|