|
12 | 12 |
|
13 | 13 | from ads.aqua.app import AquaApp
|
14 | 14 | from ads.aqua.common.entities import ComputeShapeSummary, ModelConfigResult
|
| 15 | +from ads.aqua.common.enums import Tags |
| 16 | +from ads.aqua.finetuning.constants import FineTuneCustomMetadata |
15 | 17 | from ads.aqua.model.constants import AquaModelMetadataKeys
|
16 | 18 | from ads.aqua.modeldeployment.entities import (
|
17 | 19 | AquaDeploymentConfig,
|
@@ -194,24 +196,95 @@ def _fetch_deployment_configs_concurrently(
|
194 | 196 | }
|
195 | 197 |
|
196 | 198 | def _fetch_deployment_config_from_metadata_and_oss(
|
197 |
| - self, model_id |
| 199 | + self, model_id: str |
198 | 200 | ) -> ModelConfigResult:
|
| 201 | + """ |
| 202 | + Attempts to retrieve the deployment configuration for a given model. |
| 203 | +
|
| 204 | + This method first checks whether the model is a fine-tuned model by inspecting its tags. |
| 205 | + If so, it tries to extract the base model ID from the custom metadata and fetch configuration |
| 206 | + from the base model instead. |
| 207 | +
|
| 208 | + It tries two sources in the following order: |
| 209 | + 1. Model metadata (custom metadata key) |
| 210 | + 2. Object Storage fallback (for backward compatibility or large configs) |
| 211 | +
|
| 212 | + Parameters |
| 213 | + ---------- |
| 214 | + model_id : str |
| 215 | + The OCID of the model in the Model Catalog. |
| 216 | +
|
| 217 | + Returns |
| 218 | + ------- |
| 219 | + ModelConfigResult |
| 220 | + The configuration and model details, possibly empty if no config found. |
| 221 | + """ |
| 222 | + # Get model details from Model Catalog |
| 223 | + oci_model = self.deployment_app.ds_client.get_model(model_id).data |
| 224 | + |
| 225 | + # Check if the model is fine-tuned |
| 226 | + is_fine_tuned_model = Tags.AQUA_FINE_TUNED_MODEL_TAG in oci_model.freeform_tags |
| 227 | + if is_fine_tuned_model: |
| 228 | + logger.info( |
| 229 | + "Model '%s' is marked as fine-tuned. Attempting to retrieve base model ID.", |
| 230 | + model_id, |
| 231 | + ) |
| 232 | + |
| 233 | + base_model_id = next( |
| 234 | + ( |
| 235 | + item.value |
| 236 | + for item in oci_model.custom_metadata_list |
| 237 | + if item.key == FineTuneCustomMetadata.FINE_TUNE_SOURCE |
| 238 | + ), |
| 239 | + None, |
| 240 | + ) |
| 241 | + |
| 242 | + if not base_model_id: |
| 243 | + logger.warning( |
| 244 | + "Base model reference not found in custom metadata for fine-tuned model '%s'.", |
| 245 | + model_id, |
| 246 | + ) |
| 247 | + return ModelConfigResult(config={}, model_details=oci_model) |
| 248 | + |
| 249 | + logger.info( |
| 250 | + "Base model for fine-tuned model '%s' is '%s'. Using base model for config extraction.", |
| 251 | + model_id, |
| 252 | + base_model_id, |
| 253 | + ) |
| 254 | + model_id = base_model_id |
| 255 | + |
| 256 | + # Attempt to retrieve config from metadata |
| 257 | + metadata_key = AquaModelMetadataKeys.DEPLOYMENT_CONFIGURATION |
199 | 258 | config = self.deployment_app.get_config_from_metadata(
|
200 |
| - model_id, AquaModelMetadataKeys.DEPLOYMENT_CONFIGURATION |
| 259 | + model_id=model_id, metadata_key=metadata_key |
201 | 260 | )
|
202 |
| - if config: |
| 261 | + |
| 262 | + if config and config.config: |
203 | 263 | logger.info(
|
204 |
| - f"Fetched metadata key '{AquaModelMetadataKeys.DEPLOYMENT_CONFIGURATION}' from defined metadata for model '{model_id}'" |
| 264 | + "Deployment configuration '%s' successfully retrieved from model metadata for model '%s'.", |
| 265 | + metadata_key, |
| 266 | + model_id, |
205 | 267 | )
|
206 | 268 | return config
|
207 |
| - else: |
| 269 | + |
| 270 | + # Attempt to retrieve config from Object Storage |
| 271 | + logger.info( |
| 272 | + "Deployment configuration '%s' not found in metadata for model '%s'. Falling back to Object Storage.", |
| 273 | + metadata_key, |
| 274 | + model_id, |
| 275 | + ) |
| 276 | + config = self.deployment_app.get_config( |
| 277 | + model_id=model_id, config_file_name=AQUA_MODEL_DEPLOYMENT_CONFIG |
| 278 | + ) |
| 279 | + |
| 280 | + if config and config.config: |
208 | 281 | logger.info(
|
209 |
| - f"Fetching '{AquaModelMetadataKeys.DEPLOYMENT_CONFIGURATION}' from object storage bucket for {model_id}'" |
210 |
| - ) |
211 |
| - return self.deployment_app.get_config( |
212 |
| - model_id, AQUA_MODEL_DEPLOYMENT_CONFIG |
| 282 | + "Successfully retrieved deployment configuration from Object Storage for model '%s'.", |
| 283 | + model_id, |
213 | 284 | )
|
214 | 285 |
|
| 286 | + return config or ModelConfigResult() |
| 287 | + |
215 | 288 | def _extract_model_shape_gpu(
|
216 | 289 | self,
|
217 | 290 | deployment_configs: Dict[str, AquaDeploymentConfig],
|
|
0 commit comments