Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update src/submission/submit.py
Browse files- src/submission/submit.py +122 -119
src/submission/submit.py
CHANGED
|
@@ -1,119 +1,122 @@
|
|
| 1 |
-
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 API, EVAL_REQUESTS_PATH, TOKEN, QUEUE_REPO
|
| 7 |
-
from src.submission.check_validity import (
|
| 8 |
-
already_submitted_models,
|
| 9 |
-
check_model_card,
|
| 10 |
-
get_model_size,
|
| 11 |
-
is_model_on_hub,
|
| 12 |
-
)
|
| 13 |
-
|
| 14 |
-
REQUESTED_MODELS = None
|
| 15 |
-
USERS_TO_SUBMISSION_DATES = None
|
| 16 |
-
|
| 17 |
-
def add_new_eval(
|
| 18 |
-
model: str,
|
| 19 |
-
base_model: str,
|
| 20 |
-
revision: str,
|
| 21 |
-
precision: str,
|
| 22 |
-
weight_type: str,
|
| 23 |
-
model_type: str,
|
| 24 |
-
):
|
| 25 |
-
global REQUESTED_MODELS
|
| 26 |
-
global USERS_TO_SUBMISSION_DATES
|
| 27 |
-
if not REQUESTED_MODELS:
|
| 28 |
-
REQUESTED_MODELS, USERS_TO_SUBMISSION_DATES = already_submitted_models(EVAL_REQUESTS_PATH)
|
| 29 |
-
|
| 30 |
-
user_name = ""
|
| 31 |
-
model_path = model
|
| 32 |
-
if "/" in model:
|
| 33 |
-
user_name = model.split("/")[0]
|
| 34 |
-
model_path = model.split("/")[1]
|
| 35 |
-
|
| 36 |
-
precision = precision.split(" ")[0]
|
| 37 |
-
current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 38 |
-
|
| 39 |
-
if model_type is None or model_type == "":
|
| 40 |
-
return styled_error("Please select a model type.")
|
| 41 |
-
|
| 42 |
-
# Does the model actually exist?
|
| 43 |
-
if revision == "":
|
| 44 |
-
revision = "main"
|
| 45 |
-
|
| 46 |
-
# Is the model on the hub?
|
| 47 |
-
if weight_type in ["Delta", "Adapter"]:
|
| 48 |
-
base_model_on_hub, error, _ = is_model_on_hub(model_name=base_model, revision=revision, token=TOKEN, test_tokenizer=True)
|
| 49 |
-
if not base_model_on_hub:
|
| 50 |
-
return styled_error(f'Base model "{base_model}" {error}')
|
| 51 |
-
|
| 52 |
-
if not weight_type == "Adapter":
|
| 53 |
-
model_on_hub, error, _ = is_model_on_hub(model_name=model, revision=revision, token=TOKEN, test_tokenizer=True)
|
| 54 |
-
if not model_on_hub:
|
| 55 |
-
return styled_error(f'Model "{model}" {error}')
|
| 56 |
-
|
| 57 |
-
# Is the model info correctly filled?
|
| 58 |
-
try:
|
| 59 |
-
model_info = API.model_info(repo_id=model, revision=revision)
|
| 60 |
-
except Exception:
|
| 61 |
-
return styled_error("Could not get your model information. Please fill it up properly.")
|
| 62 |
-
|
| 63 |
-
model_size = get_model_size(model_info=model_info, precision=precision)
|
| 64 |
-
|
| 65 |
-
# Were the model card and license filled?
|
| 66 |
-
try:
|
| 67 |
-
license = model_info.cardData["license"]
|
| 68 |
-
except Exception:
|
| 69 |
-
return styled_error("Please select a license for your model")
|
| 70 |
-
|
| 71 |
-
modelcard_OK, error_msg = check_model_card(model)
|
| 72 |
-
if not modelcard_OK:
|
| 73 |
-
return styled_error(error_msg)
|
| 74 |
-
|
| 75 |
-
# Seems good, creating the eval
|
| 76 |
-
print("Adding new eval")
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
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 API, EVAL_REQUESTS_PATH, TOKEN, QUEUE_REPO
|
| 7 |
+
from src.submission.check_validity import (
|
| 8 |
+
already_submitted_models,
|
| 9 |
+
check_model_card,
|
| 10 |
+
get_model_size,
|
| 11 |
+
is_model_on_hub,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
REQUESTED_MODELS = None
|
| 15 |
+
USERS_TO_SUBMISSION_DATES = None
|
| 16 |
+
|
| 17 |
+
def add_new_eval(
|
| 18 |
+
model: str,
|
| 19 |
+
base_model: str,
|
| 20 |
+
revision: str,
|
| 21 |
+
precision: str,
|
| 22 |
+
weight_type: str,
|
| 23 |
+
model_type: str,
|
| 24 |
+
):
|
| 25 |
+
global REQUESTED_MODELS
|
| 26 |
+
global USERS_TO_SUBMISSION_DATES
|
| 27 |
+
if not REQUESTED_MODELS:
|
| 28 |
+
REQUESTED_MODELS, USERS_TO_SUBMISSION_DATES = already_submitted_models(EVAL_REQUESTS_PATH)
|
| 29 |
+
|
| 30 |
+
user_name = ""
|
| 31 |
+
model_path = model
|
| 32 |
+
if "/" in model:
|
| 33 |
+
user_name = model.split("/")[0]
|
| 34 |
+
model_path = model.split("/")[1]
|
| 35 |
+
|
| 36 |
+
precision = precision.split(" ")[0]
|
| 37 |
+
current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 38 |
+
|
| 39 |
+
if model_type is None or model_type == "":
|
| 40 |
+
return styled_error("Please select a model type.")
|
| 41 |
+
|
| 42 |
+
# Does the model actually exist?
|
| 43 |
+
if revision == "":
|
| 44 |
+
revision = "main"
|
| 45 |
+
|
| 46 |
+
# Is the model on the hub?
|
| 47 |
+
if weight_type in ["Delta", "Adapter"]:
|
| 48 |
+
base_model_on_hub, error, _ = is_model_on_hub(model_name=base_model, revision=revision, token=TOKEN, test_tokenizer=True)
|
| 49 |
+
if not base_model_on_hub:
|
| 50 |
+
return styled_error(f'Base model "{base_model}" {error}')
|
| 51 |
+
|
| 52 |
+
if not weight_type == "Adapter":
|
| 53 |
+
model_on_hub, error, _ = is_model_on_hub(model_name=model, revision=revision, token=TOKEN, test_tokenizer=True)
|
| 54 |
+
if not model_on_hub:
|
| 55 |
+
return styled_error(f'Model "{model}" {error}')
|
| 56 |
+
|
| 57 |
+
# Is the model info correctly filled?
|
| 58 |
+
try:
|
| 59 |
+
model_info = API.model_info(repo_id=model, revision=revision)
|
| 60 |
+
except Exception:
|
| 61 |
+
return styled_error("Could not get your model information. Please fill it up properly.")
|
| 62 |
+
|
| 63 |
+
model_size = get_model_size(model_info=model_info, precision=precision)
|
| 64 |
+
|
| 65 |
+
# Were the model card and license filled?
|
| 66 |
+
try:
|
| 67 |
+
license = model_info.cardData["license"]
|
| 68 |
+
except Exception:
|
| 69 |
+
return styled_error("Please select a license for your model")
|
| 70 |
+
|
| 71 |
+
modelcard_OK, error_msg = check_model_card(model)
|
| 72 |
+
if not modelcard_OK:
|
| 73 |
+
return styled_error(error_msg)
|
| 74 |
+
|
| 75 |
+
# Seems good, creating the eval
|
| 76 |
+
print("Adding new eval")
|
| 77 |
+
|
| 78 |
+
# Parsing emoji : pretrained from model type
|
| 79 |
+
model_type = model_type.split(":")[-1].strip() if ":" in model_type else model_type
|
| 80 |
+
|
| 81 |
+
eval_entry = {
|
| 82 |
+
"model": model,
|
| 83 |
+
"base_model": base_model,
|
| 84 |
+
"revision": revision,
|
| 85 |
+
"precision": precision,
|
| 86 |
+
"weight_type": weight_type,
|
| 87 |
+
"status": "PENDING",
|
| 88 |
+
"submitted_time": current_time,
|
| 89 |
+
"model_type": model_type,
|
| 90 |
+
"likes": model_info.likes,
|
| 91 |
+
"params": model_size,
|
| 92 |
+
"license": license,
|
| 93 |
+
"private": False,
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
# Check for duplicate submission
|
| 97 |
+
if f"{model}_{revision}_{precision}" in REQUESTED_MODELS:
|
| 98 |
+
return styled_warning("This model has been already submitted.")
|
| 99 |
+
|
| 100 |
+
print("Creating eval file")
|
| 101 |
+
OUT_DIR = f"{EVAL_REQUESTS_PATH}/{user_name}"
|
| 102 |
+
os.makedirs(OUT_DIR, exist_ok=True)
|
| 103 |
+
out_path = f"{OUT_DIR}/{model_path}_eval_request_False_{precision}_{weight_type}.json"
|
| 104 |
+
|
| 105 |
+
with open(out_path, "w") as f:
|
| 106 |
+
f.write(json.dumps(eval_entry))
|
| 107 |
+
|
| 108 |
+
print("Uploading eval file")
|
| 109 |
+
API.upload_file(
|
| 110 |
+
path_or_fileobj=out_path,
|
| 111 |
+
path_in_repo=out_path.split("eval-queue/")[1],
|
| 112 |
+
repo_id=QUEUE_REPO,
|
| 113 |
+
repo_type="dataset",
|
| 114 |
+
commit_message=f"Add {model} to eval queue",
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
# Remove the local file
|
| 118 |
+
os.remove(out_path)
|
| 119 |
+
|
| 120 |
+
return styled_message(
|
| 121 |
+
"Your request has been submitted to the evaluation queue!\nPlease wait for up to an hour for the model to show in the PENDING list."
|
| 122 |
+
)
|