Skip to content

Commit 2e09071

Browse files
committed
Fixes the multi-model evaluation validator
1 parent f1f8f42 commit 2e09071

File tree

2 files changed

+53
-35
lines changed

2 files changed

+53
-35
lines changed

ads/aqua/config/container_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
from typing import Dict, List, Optional
66

7-
from common.extended_enum import ExtendedEnum
87
from pydantic import Field
98

109
from ads.aqua.common.entities import ContainerSpec
1110
from ads.aqua.config.utils.serializer import Serializable
11+
from ads.common.extended_enum import ExtendedEnum
1212

1313

1414
class Usage(ExtendedEnum):

ads/aqua/evaluation/evaluation.py

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -575,64 +575,82 @@ def validate_model_name(
575575
create_aqua_evaluation_details: CreateAquaEvaluationDetails,
576576
) -> None:
577577
"""
578-
Validates the user input of the model name when creating an Aqua evaluation.
578+
Validates the user input for the model name when creating an Aqua evaluation.
579+
580+
This function verifies that:
581+
- The model group is not empty.
582+
- The user provided a non-empty model name.
583+
- The provided model name exists in the DataScienceModel metadata.
584+
- The deployment configuration contains core metadata required for validation.
579585
580586
Parameters
581587
----------
582-
evaluation_source: DataScienceModel
583-
The DataScienceModel Object which contains all metadata
584-
about each model in a single and multi model deployment.
585-
create_aqua_evaluation_details: CreateAquaEvaluationDetails
586-
The CreateAquaEvaluationDetails data class which contains all
587-
required and optional fields to create the aqua evaluation.
588+
evaluation_source : DataScienceModel
589+
The DataScienceModel object containing metadata about each model in the deployment.
590+
create_aqua_evaluation_details : CreateAquaEvaluationDetails
591+
Contains required and optional fields for creating the Aqua evaluation.
588592
589593
Raises
590-
-------
591-
AquaValueError:
592-
- When the user fails to specify any input for the model name.
593-
- When the user supplies a model name that does not match the model name set in the DataScienceModel metadata.
594-
- When the DataScienceModel metadata lacks core attributes for validating the name"""
594+
------
595+
AquaValueError
596+
If the user fails to provide a model name or if the provided model name does not match
597+
any of the valid model names in the deployment metadata.
598+
AquaRuntimeError
599+
If the metadata is missing the model group count or if the model group count is invalid.
600+
"""
595601
user_model_parameters = create_aqua_evaluation_details.model_parameters
596-
597602
custom_metadata_list = evaluation_source.custom_metadata_list
598603
user_model_name = user_model_parameters.get("model")
599604

605+
# Ensure that a non-empty model name was provided.
606+
if not user_model_name:
607+
error_message = (
608+
"No model name was provided for evaluation. For multi-model deployment, "
609+
"a model must be specified in the model parameters."
610+
)
611+
logger.debug(error_message)
612+
raise AquaValueError(error_message)
613+
614+
# Retrieve and convert the model group count from metadata.
600615
model_count = custom_metadata_list.get(
601616
ModelCustomMetadataFields.MULTIMODEL_GROUP_COUNT
602617
)
603-
604-
if model_count and custom_metadata_list:
618+
try:
605619
model_group_count = int(model_count.value)
606-
else:
607-
logger.debug(
608-
f"The ModelCustomMetadataFields.MULTIMODEL_GROUP_COUNT or custom_metadata_list (ModelCustomMetadata) is missing from the metadata in evaluation source ID: {create_aqua_evaluation_details.evaluation_source_id}"
620+
except Exception as ex:
621+
error_message = (
622+
"Missing or invalid `MULTIMODEL_GROUP_COUNT` "
623+
f"in custom metadata for evaluation source ID '{create_aqua_evaluation_details.evaluation_source_id}'. "
624+
f"Details: {ex}"
625+
)
626+
logger.error(error_message)
627+
628+
if model_group_count < 1:
629+
error_message = (
630+
f"Invalid model group count: {model_group_count} for evaluation source ID "
631+
f"'{create_aqua_evaluation_details.evaluation_source_id}'. A valid multi-model deployment "
632+
f"requires at least one model."
609633
)
634+
logger.error(error_message)
610635
raise AquaRuntimeError(
611-
"Recreate the model deployment and retry the evaluation. An issue occured when initalizing the model group during deployment."
636+
f"Cannot extract details about the multi-model deployment to evaluate. A valid multi-model deployment requires at least one model, however the provided evaluation source ID '{create_aqua_evaluation_details.evaluation_source_id}' doesn't contain details about the deployed models."
612637
)
613638

639+
# Build the list of valid model names from custom metadata.
614640
model_names = [
615641
custom_metadata_list.get(f"model-name-{idx}").value
616642
for idx in range(model_group_count)
617643
]
618644

619-
valid_model_names = ", ".join(name for name in model_names if name is not None)
620-
621-
if "model" not in user_model_parameters:
622-
logger.debug(
623-
f"User did not input model name for multi model deployment evaluation with evaluation source ID: {create_aqua_evaluation_details.evaluation_source_id}"
624-
)
625-
raise AquaValueError(
626-
f"Provide the model name. For evaluation, a single model needs to be targeted using the name in the multi model deployment. The valid model names for this Model Deployment are {valid_model_names}."
627-
)
628-
645+
# Check if the provided model name is among the valid names.
629646
if user_model_name not in model_names:
630-
logger.debug(
631-
f"User input for model name was {user_model_name}, expected {valid_model_names} evaluation source ID: {create_aqua_evaluation_details.evaluation_source_id}"
632-
)
633-
raise AquaValueError(
634-
f"Provide the correct model name. The valid model names for this Model Deployment are {valid_model_names}."
647+
error_message = (
648+
f"Provided model name '{user_model_name}' does not match any valid model names {model_names} "
649+
f"for evaluation source ID '{create_aqua_evaluation_details.evaluation_source_id}'. "
650+
"Please provide the correct model name."
635651
)
652+
logger.debug(error_message)
653+
raise AquaValueError(error_message)
636654

637655
def _build_evaluation_runtime(
638656
self,

0 commit comments

Comments
 (0)