|
12 | 12 | from ads.aqua.common.enums import Tags |
13 | 13 | from ads.aqua.common.errors import AquaValueError |
14 | 14 | from ads.aqua.config.utils.serializer import Serializable |
15 | | -from ads.aqua.constants import UNKNOWN_DICT |
| 15 | +from ads.aqua.constants import ( |
| 16 | + AQUA_FINE_TUNE_MODEL_VERSION, |
| 17 | + INCLUDE_BASE_MODEL, |
| 18 | + UNKNOWN_DICT, |
| 19 | +) |
16 | 20 | from ads.aqua.data import AquaResourceIdentifier |
17 | 21 | from ads.aqua.finetuning.constants import FineTuneCustomMetadata |
18 | 22 | from ads.aqua.modeldeployment.config_loader import ( |
@@ -509,11 +513,13 @@ def validate_multimodel_deployment_feasibility( |
509 | 513 |
|
510 | 514 | def validate_input_models(self, model_details: Dict[str, DataScienceModel]) -> None: |
511 | 515 | """ |
512 | | - Validates the input models for a multi-model deployment configuration. |
| 516 | + Validates the input models for a stacked-model or multi-model deployment configuration. |
513 | 517 |
|
514 | 518 | Validation Criteria: |
515 | 519 | - The base model must be explicitly provided. |
516 | 520 | - The base model must be in 'ACTIVE' state. |
| 521 | + - Fine-tuned models must have a tag 'fine_tune_model_version' as v2 to be supported. |
| 522 | + - Fine-tuned models must not have custom metadata 'include_base_model_artifact' as 1. |
517 | 523 | - Fine-tuned model IDs must refer to valid, tagged fine-tuned models. |
518 | 524 | - Fine-tuned models must refer back to the same base model. |
519 | 525 | - All model names (including fine-tuned variants) must be unique. |
@@ -609,6 +615,8 @@ def validate_input_models(self, model_details: Dict[str, DataScienceModel]) -> N |
609 | 615 | f"Invalid fine-tuned model ID '{ft_model_id}': missing tag '{Tags.AQUA_FINE_TUNED_MODEL_TAG}'." |
610 | 616 | ) |
611 | 617 |
|
| 618 | + self.validate_ft_model_v2(model=ft_model) |
| 619 | + |
612 | 620 | ft_base_model_id = ft_model.custom_metadata_list.get( |
613 | 621 | FineTuneCustomMetadata.FINE_TUNE_SOURCE, |
614 | 622 | ModelCustomMetadataItem( |
@@ -650,6 +658,61 @@ def validate_input_models(self, model_details: Dict[str, DataScienceModel]) -> N |
650 | 658 | f"{', '.join(sorted(duplicate_names))}. Model names must be unique for proper routing in multi-model deployments." |
651 | 659 | ) |
652 | 660 |
|
| 661 | + def validate_ft_model_v2( |
| 662 | + self, model_id: Optional[str] = None, model: Optional[DataScienceModel] = None |
| 663 | + ) -> None: |
| 664 | + """ |
| 665 | + Validates the input fine tuned model for model deployment configuration. |
| 666 | +
|
| 667 | + Validation Criteria: |
| 668 | + - Fine-tuned models must have a tag 'fine_tune_model_version' as v2 to be supported. |
| 669 | + - Fine-tuned models must not have custom metadata 'include_base_model_artifact' as '1'. |
| 670 | +
|
| 671 | + Parameters |
| 672 | + ---------- |
| 673 | + model_id : str |
| 674 | + The OCID of DataScienceModel instance. |
| 675 | + model : DataScienceModel |
| 676 | + The DataScienceModel instance. |
| 677 | +
|
| 678 | + Raises |
| 679 | + ------ |
| 680 | + ConfigValidationError |
| 681 | + If any of the above conditions are violated. |
| 682 | + """ |
| 683 | + base_model = DataScienceModel.from_id(model_id) if model_id else model |
| 684 | + if Tags.AQUA_FINE_TUNED_MODEL_TAG in base_model.freeform_tags: |
| 685 | + if ( |
| 686 | + base_model.freeform_tags.get( |
| 687 | + Tags.AQUA_FINE_TUNE_MODEL_VERSION, UNKNOWN |
| 688 | + ).lower() |
| 689 | + != AQUA_FINE_TUNE_MODEL_VERSION |
| 690 | + ): |
| 691 | + logger.error( |
| 692 | + "Validation failed: Fine-tuned model ID '%s' is not supported for model deployment.", |
| 693 | + base_model.id, |
| 694 | + ) |
| 695 | + raise ConfigValidationError( |
| 696 | + f"Invalid fine-tuned model ID '{base_model.id}': only fine tune model {AQUA_FINE_TUNE_MODEL_VERSION} is supported for model deployment. " |
| 697 | + f"Run 'ads aqua model convert_fine_tune --model_id {base_model.id}' to convert legacy AQUA fine tuned model to version {AQUA_FINE_TUNE_MODEL_VERSION} for deployment." |
| 698 | + ) |
| 699 | + |
| 700 | + include_base_model_artifact = base_model.custom_metadata_list.get( |
| 701 | + FineTuneCustomMetadata.FINE_TUNE_INCLUDE_BASE_MODEL_ARTIFACT, |
| 702 | + ModelCustomMetadataItem( |
| 703 | + key=FineTuneCustomMetadata.FINE_TUNE_INCLUDE_BASE_MODEL_ARTIFACT |
| 704 | + ), |
| 705 | + ).value |
| 706 | + |
| 707 | + if include_base_model_artifact == INCLUDE_BASE_MODEL: |
| 708 | + logger.error( |
| 709 | + "Validation failed: Fine-tuned model ID '%s' is not supported for model deployment.", |
| 710 | + base_model.id, |
| 711 | + ) |
| 712 | + raise ConfigValidationError( |
| 713 | + f"Invalid fine-tuned model ID '{base_model.id}': for fine tuned models like Phi4, the deployment is not supported. " |
| 714 | + ) |
| 715 | + |
653 | 716 | class Config: |
654 | 717 | extra = "allow" |
655 | 718 | protected_namespaces = () |
0 commit comments