Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Alina Lozovskaya
commited on
Commit
·
0e60add
1
Parent(s):
f6dd42c
Refactor model validation logic
Browse files- backend/app/services/models.py +32 -22
backend/app/services/models.py
CHANGED
|
@@ -382,26 +382,6 @@ class ModelService(HuggingFaceService):
|
|
| 382 |
if field not in model_data:
|
| 383 |
raise ValueError(f"Missing required field: {field}")
|
| 384 |
|
| 385 |
-
# Check if model already exists in the system
|
| 386 |
-
try:
|
| 387 |
-
logger.info(LogFormatter.subsection("CHECKING EXISTING SUBMISSIONS"))
|
| 388 |
-
existing_models = await self.get_models()
|
| 389 |
-
|
| 390 |
-
# Check in all statuses (pending, evaluating, finished)
|
| 391 |
-
for status, models in existing_models.items():
|
| 392 |
-
for model in models:
|
| 393 |
-
if model["name"] == model_data["model_id"]:
|
| 394 |
-
error_msg = f"Model {model_data['model_id']} is already in the system with status: {status}"
|
| 395 |
-
logger.error(LogFormatter.error("Submission rejected", error_msg))
|
| 396 |
-
raise ValueError(error_msg)
|
| 397 |
-
|
| 398 |
-
logger.info(LogFormatter.success("No existing submission found"))
|
| 399 |
-
except ValueError:
|
| 400 |
-
raise
|
| 401 |
-
except Exception as e:
|
| 402 |
-
logger.error(LogFormatter.error("Failed to check existing submissions", e))
|
| 403 |
-
raise
|
| 404 |
-
|
| 405 |
# Get model info and validate it exists on HuggingFace
|
| 406 |
try:
|
| 407 |
logger.info(LogFormatter.subsection("MODEL VALIDATION"))
|
|
@@ -412,6 +392,7 @@ class ModelService(HuggingFaceService):
|
|
| 412 |
revision=model_data["revision"],
|
| 413 |
token=self.token
|
| 414 |
)
|
|
|
|
| 415 |
if not model_info:
|
| 416 |
raise Exception(f"Model {model_data['model_id']} not found on HuggingFace Hub")
|
| 417 |
|
|
@@ -420,6 +401,29 @@ class ModelService(HuggingFaceService):
|
|
| 420 |
except Exception as e:
|
| 421 |
logger.error(LogFormatter.error("Model validation failed", e))
|
| 422 |
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
|
| 424 |
# Validate model card
|
| 425 |
valid, error, model_card = await self.validator.check_model_card(
|
|
@@ -434,7 +438,8 @@ class ModelService(HuggingFaceService):
|
|
| 434 |
model_size, error = await self.validator.get_model_size(
|
| 435 |
model_info,
|
| 436 |
model_data["precision"],
|
| 437 |
-
model_data["base_model"]
|
|
|
|
| 438 |
)
|
| 439 |
if model_size is None:
|
| 440 |
logger.error(LogFormatter.error("Model size validation failed", error))
|
|
@@ -458,6 +463,11 @@ class ModelService(HuggingFaceService):
|
|
| 458 |
raise Exception(error)
|
| 459 |
logger.info(LogFormatter.success("Chat template validation passed"))
|
| 460 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 461 |
# Create eval entry
|
| 462 |
eval_entry = {
|
| 463 |
"model": model_data["model_id"],
|
|
@@ -465,7 +475,7 @@ class ModelService(HuggingFaceService):
|
|
| 465 |
"revision": model_info.sha,
|
| 466 |
"precision": model_data["precision"],
|
| 467 |
"params": model_size,
|
| 468 |
-
"architectures":
|
| 469 |
"weight_type": model_data["weight_type"],
|
| 470 |
"status": "PENDING",
|
| 471 |
"submitted_time": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
|
|
| 382 |
if field not in model_data:
|
| 383 |
raise ValueError(f"Missing required field: {field}")
|
| 384 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
# Get model info and validate it exists on HuggingFace
|
| 386 |
try:
|
| 387 |
logger.info(LogFormatter.subsection("MODEL VALIDATION"))
|
|
|
|
| 392 |
revision=model_data["revision"],
|
| 393 |
token=self.token
|
| 394 |
)
|
| 395 |
+
|
| 396 |
if not model_info:
|
| 397 |
raise Exception(f"Model {model_data['model_id']} not found on HuggingFace Hub")
|
| 398 |
|
|
|
|
| 401 |
except Exception as e:
|
| 402 |
logger.error(LogFormatter.error("Model validation failed", e))
|
| 403 |
raise
|
| 404 |
+
|
| 405 |
+
# Update model revision with commit sha
|
| 406 |
+
model_data["revision"] = model_info.sha
|
| 407 |
+
|
| 408 |
+
# Check if model already exists in the system
|
| 409 |
+
try:
|
| 410 |
+
logger.info(LogFormatter.subsection("CHECKING EXISTING SUBMISSIONS"))
|
| 411 |
+
existing_models = await self.get_models()
|
| 412 |
+
|
| 413 |
+
# Check in all statuses (pending, evaluating, finished)
|
| 414 |
+
for status, models in existing_models.items():
|
| 415 |
+
for model in models:
|
| 416 |
+
if model["name"] == model_data["model_id"] and model["revision"] == model_data["revision"]:
|
| 417 |
+
error_msg = f"Model {model_data['model_id']} revision {model_data["revision"]} is already in the system with status: {status}"
|
| 418 |
+
logger.error(LogFormatter.error("Submission rejected", error_msg))
|
| 419 |
+
raise ValueError(error_msg)
|
| 420 |
+
|
| 421 |
+
logger.info(LogFormatter.success("No existing submission found"))
|
| 422 |
+
except ValueError:
|
| 423 |
+
raise
|
| 424 |
+
except Exception as e:
|
| 425 |
+
logger.error(LogFormatter.error("Failed to check existing submissions", e))
|
| 426 |
+
raise
|
| 427 |
|
| 428 |
# Validate model card
|
| 429 |
valid, error, model_card = await self.validator.check_model_card(
|
|
|
|
| 438 |
model_size, error = await self.validator.get_model_size(
|
| 439 |
model_info,
|
| 440 |
model_data["precision"],
|
| 441 |
+
model_data["base_model"],
|
| 442 |
+
revision=model_data["revision"]
|
| 443 |
)
|
| 444 |
if model_size is None:
|
| 445 |
logger.error(LogFormatter.error("Model size validation failed", error))
|
|
|
|
| 463 |
raise Exception(error)
|
| 464 |
logger.info(LogFormatter.success("Chat template validation passed"))
|
| 465 |
|
| 466 |
+
|
| 467 |
+
architectures = model_info.config.get("architectures", "")
|
| 468 |
+
if architectures:
|
| 469 |
+
architectures = ";".join(architectures)
|
| 470 |
+
|
| 471 |
# Create eval entry
|
| 472 |
eval_entry = {
|
| 473 |
"model": model_data["model_id"],
|
|
|
|
| 475 |
"revision": model_info.sha,
|
| 476 |
"precision": model_data["precision"],
|
| 477 |
"params": model_size,
|
| 478 |
+
"architectures": architectures,
|
| 479 |
"weight_type": model_data["weight_type"],
|
| 480 |
"status": "PENDING",
|
| 481 |
"submitted_time": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|