11#!/usr/bin/env python
2- # Copyright (c) 2024 Oracle and/or its affiliates.
2+ # Copyright (c) 2024, 2025 Oracle and/or its affiliates.
33# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
44
55import json
66import os
7- from dataclasses import MISSING , asdict , fields
7+ from dataclasses import asdict , fields
88from typing import Dict
99
1010from oci .data_science .models import (
2020from ads .aqua .common .utils import (
2121 get_container_image ,
2222 upload_local_to_os ,
23+ validate_dataclass_params ,
2324)
2425from ads .aqua .constants import (
2526 DEFAULT_FT_BATCH_SIZE ,
@@ -102,26 +103,10 @@ def create(
102103 The instance of AquaFineTuningSummary.
103104 """
104105 if not create_fine_tuning_details :
105- try :
106- create_fine_tuning_details = CreateFineTuningDetails (** kwargs )
107- except Exception as ex :
108- allowed_create_fine_tuning_details = ", " .join (
109- field .name for field in fields (CreateFineTuningDetails )
110- ).rstrip ()
111- raise AquaValueError (
112- "Invalid create fine tuning parameters. Allowable parameters are: "
113- f"{ allowed_create_fine_tuning_details } ."
114- ) from ex
106+ validate_dataclass_params (CreateFineTuningDetails , ** kwargs )
115107
116108 source = self .get_source (create_fine_tuning_details .ft_source_id )
117109
118- # todo: revisit validation for fine tuned models
119- # if source.compartment_id != ODSC_MODEL_COMPARTMENT_OCID:
120- # raise AquaValueError(
121- # f"Fine tuning is only supported for Aqua service models in {ODSC_MODEL_COMPARTMENT_OCID}. "
122- # "Use a valid Aqua service model id instead."
123- # )
124-
125110 target_compartment = (
126111 create_fine_tuning_details .compartment_id or COMPARTMENT_OCID
127112 )
@@ -401,13 +386,19 @@ def create(
401386 defined_tags = model_defined_tags ,
402387 ),
403388 )
389+ logger .debug (
390+ f"Successfully updated model custom metadata list and freeform tags for the model { ft_model .id } ."
391+ )
404392
405393 self .update_model_provenance (
406394 model_id = ft_model .id ,
407395 update_model_provenance_details = UpdateModelProvenanceDetails (
408396 training_id = ft_job_run .id
409397 ),
410398 )
399+ logger .debug (
400+ f"Successfully updated model provenance for the model { ft_model .id } ."
401+ )
411402
412403 # tracks the shape and replica used for fine-tuning the service models
413404 telemetry_kwargs = (
@@ -587,7 +578,7 @@ def get_finetuning_config(self, model_id: str) -> Dict:
587578 config = self .get_config (model_id , AQUA_MODEL_FINETUNING_CONFIG )
588579 if not config :
589580 logger .debug (
590- f"Fine-tuning config for custom model: { model_id } is not available."
581+ f"Fine-tuning config for custom model: { model_id } is not available. Use defaults. "
591582 )
592583 return config
593584
@@ -622,7 +613,8 @@ def get_finetuning_default_params(self, model_id: str) -> Dict:
622613
623614 return default_params
624615
625- def validate_finetuning_params (self , params : Dict = None ) -> Dict :
616+ @staticmethod
617+ def validate_finetuning_params (params : Dict = None ) -> Dict :
626618 """Validate if the fine-tuning parameters passed by the user can be overridden. Parameter values are not
627619 validated, only param keys are validated.
628620
@@ -633,21 +625,7 @@ def validate_finetuning_params(self, params: Dict = None) -> Dict:
633625
634626 Returns
635627 -------
636- Return a list of restricted params .
628+ Return a dict with value true if valid, else raises AquaValueError .
637629 """
638- try :
639- AquaFineTuningParams (
640- ** params ,
641- )
642- except Exception as e :
643- logger .debug (str (e ))
644- allowed_fine_tuning_parameters = ", " .join (
645- f"{ field .name } (required)" if field .default is MISSING else field .name
646- for field in fields (AquaFineTuningParams )
647- ).rstrip ()
648- raise AquaValueError (
649- f"Invalid fine tuning parameters. Allowable parameters are: "
650- f"{ allowed_fine_tuning_parameters } ."
651- ) from e
652-
630+ validate_dataclass_params (AquaFineTuningParams , ** (params or {}))
653631 return {"valid" : True }
0 commit comments