Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ready To Merge][AQUA] Mutli-Model Deployment #1061

Merged
merged 197 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
197 commits
Select commit Hold shift + click to select a range
1446ea0
Added get multi model deployment config.
lu-ohai Feb 4, 2025
c925ec4
Updated pr.
lu-ohai Feb 4, 2025
3187e2b
Merge branch 'main' of https://github.com/oracle/accelerated-data-sci…
lu-ohai Feb 4, 2025
25afd80
Updated pr.
lu-ohai Feb 4, 2025
07eb59d
inital AQUA API code changes in get_deployment_default_params
elizjo Feb 5, 2025
5cb74b3
Update to pydantic models
VipulMascarenhas Feb 5, 2025
cbd27c9
Create method to support pydantic model inputs
VipulMascarenhas Feb 5, 2025
d0d9b17
Update handler for post method
VipulMascarenhas Feb 5, 2025
a546668
Update unit tests
VipulMascarenhas Feb 5, 2025
895d2f3
Fix params input
VipulMascarenhas Feb 5, 2025
050f13f
Remove newline from err message for handler
VipulMascarenhas Feb 5, 2025
86e9c33
Updated pr.
lu-ohai Feb 5, 2025
170f7a5
simplify var init
VipulMascarenhas Feb 5, 2025
02fe829
combined multimodel and normal model unit tests for test_get_deployme…
elizjo Feb 5, 2025
4fb0923
Review comments
VipulMascarenhas Feb 5, 2025
f5c3697
[ODSC-56699] Update MD entities to pydantic models (#1059)
VipulMascarenhas Feb 5, 2025
d097ac8
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Feb 5, 2025
8d51a8b
Updated pr.
lu-ohai Feb 5, 2025
c91472f
Merge branch 'feature/multi_model_deployment' of https://github.com/o…
lu-ohai Feb 5, 2025
32b73f3
Updated pr.
lu-ohai Feb 5, 2025
bc2e0b7
ODSC 68320: Modify the AQUA API to Accept GPU Count as an Optional In…
VipulMascarenhas Feb 6, 2025
1e418db
Resolve merge conflicts and ruff update
VipulMascarenhas Feb 6, 2025
0f08a64
Added API to get multi model deployment config (#1055)
VipulMascarenhas Feb 6, 2025
fbd77d5
ODSC-68526:Optimize Multi-Model Configuration Retrieval Using Paralle…
mrDzurb Feb 7, 2025
de211f2
Create multimodel catalog entry
VipulMascarenhas Feb 7, 2025
e533c14
Optimize Multi-Model Configuration Retrieval Using Parallel Execution…
lu-ohai Feb 7, 2025
05e329b
add custom metdata to multimodel
VipulMascarenhas Feb 7, 2025
a49afa2
add metadata and tests
VipulMascarenhas Feb 7, 2025
1f79762
Enhance aqua deployment handler
mrDzurb Feb 8, 2025
910f90c
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Feb 10, 2025
ee3d65d
Enhances the functionality for creating multi-model entities.
mrDzurb Feb 10, 2025
5109d54
Merge branch 'feature/multi_model_deployment' into ODSC-68321/create_…
mrDzurb Feb 10, 2025
c25a3de
[ODSC-68321] Create grouped model with multiple verified models (#1064)
mrDzurb Feb 10, 2025
b9c22a3
Modify get deployment config to pydantic class.
lu-ohai Feb 10, 2025
e324467
Merge branch 'feature/multi_model_deployment' of https://github.com/o…
lu-ohai Feb 10, 2025
d0b0704
Updated pr.
lu-ohai Feb 10, 2025
bddfc41
Fixed unit tests.
lu-ohai Feb 10, 2025
63667f4
Fixed unit test.
lu-ohai Feb 10, 2025
bc3978c
Updated name.
lu-ohai Feb 10, 2025
2ea68b4
Modify get deployment config as pydantic (#1066)
mrDzurb Feb 10, 2025
04a4636
added validation method
elizjo Feb 11, 2025
1c6cd61
moved CreateModelDeploymentDetails
elizjo Feb 11, 2025
8082934
Enhances error messages for loading multi-model configurations.
mrDzurb Feb 11, 2025
0edb0ae
Enhances the multi-model config retriever.
mrDzurb Feb 12, 2025
c5c6774
Enhances the multi-model configuration retrieval process. (#1067)
lu-ohai Feb 12, 2025
df0b119
removed circular import
elizjo Feb 12, 2025
57b3ffa
fixed validate_config call in deployment.py
elizjo Feb 12, 2025
c15fb25
fixed type validation in validate_config
elizjo Feb 12, 2025
a9e372e
Merge branch 'feature/multi_model_deployment' into ODSC-68333/multi_m…
mrDzurb Feb 13, 2025
fc246d3
Added support to create multi model deployment.
lu-ohai Feb 13, 2025
48a1bef
Updated pr.
lu-ohai Feb 13, 2025
9352ca5
Updated pr.
lu-ohai Feb 13, 2025
2068c3d
finished unit tests for validate method
elizjo Feb 14, 2025
eb0c93e
removed test_multi notebook
elizjo Feb 14, 2025
9ffb897
fixed imports on unit test file
elizjo Feb 14, 2025
c85302e
removed old unit test method
elizjo Feb 14, 2025
4953615
Updated pr.
lu-ohai Feb 14, 2025
6a893b6
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Feb 17, 2025
3566fe9
Added validator for deployment container.
lu-ohai Feb 18, 2025
dce825e
Updated tag.
lu-ohai Feb 19, 2025
c04445d
Added models to response.
lu-ohai Feb 19, 2025
4524271
addressed code review comments
elizjo Feb 20, 2025
3a8a57d
Added get multi deployment details.
lu-ohai Feb 20, 2025
9958da0
fixed code review 2nd round of comments
elizjo Feb 20, 2025
78d3e3e
Updated pr.
lu-ohai Feb 20, 2025
02a3ce5
ODSC-68333: Adds Config Validation for Multi-Model Deployment (#1068)
mrDzurb Feb 20, 2025
cb31632
Updated pr.
lu-ohai Feb 20, 2025
9864e93
Updated pr.
lu-ohai Feb 20, 2025
2c803e6
Updated pr.
lu-ohai Feb 21, 2025
941796f
Added support to create multi model deployment. (#1072)
lu-ohai Feb 21, 2025
f58c95f
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Feb 21, 2025
cb4e874
Merge branch 'feature/multi_model_deployment' of https://github.com/o…
lu-ohai Feb 21, 2025
9c1513a
Added unit tests.
lu-ohai Feb 21, 2025
1878093
Updated pr.
lu-ohai Feb 21, 2025
7bbdb98
Get multi model deployment details (#1079)
lu-ohai Feb 21, 2025
6689440
Fixes unit tests
mrDzurb Feb 21, 2025
a2adbf6
Fix unit tests
mrDzurb Feb 22, 2025
309e02f
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Feb 23, 2025
220a97a
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Feb 25, 2025
fd292ab
added unit tests and finished validation method in evaluation.py
elizjo Feb 25, 2025
a4e2da0
fixed model parameter name
elizjo Feb 26, 2025
b25fa2e
added docstring, fixed PR comments
elizjo Feb 26, 2025
7e9d46e
fixed PR comments
elizjo Feb 26, 2025
67c6891
ODSC 68580- Update Evaluation SDK to Support Multi-Model Deployment (…
elizjo Feb 26, 2025
ce44b27
Fixed service model name
lu-ohai Feb 26, 2025
5c37747
Fixed service model name (#1087)
mrDzurb Feb 27, 2025
454af08
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Feb 27, 2025
82d8d53
Adds more debug statements
mrDzurb Feb 28, 2025
a0aa1ef
Collect shape from configuration entry.
lu-ohai Feb 28, 2025
d0bdf70
Collect shape from configuration entry. (#1089)
mrDzurb Feb 28, 2025
f7e7c2e
Fixes GPU allocation validation
mrDzurb Feb 28, 2025
7b0eed3
Merge branch 'feature/multi_model_deployment' of https://github.com/o…
lu-ohai Feb 28, 2025
8efb221
Extract Available GPU Count from list_model_deployment_shapes API for…
mrDzurb Mar 1, 2025
f8e4870
Fixes validator
mrDzurb Mar 1, 2025
1f186a1
Fixes tests
mrDzurb Mar 1, 2025
86c75a4
Relax validation for the service models.
mrDzurb Mar 1, 2025
798d1ef
Fixes validation on text generation models.
mrDzurb Mar 1, 2025
af2dfa4
Enhance container family validation for multi-model deployment
mrDzurb Mar 2, 2025
28b2ab2
Adds more GPU shapes
mrDzurb Mar 3, 2025
ecbe944
Extract Available GPU Count from list_model_deployment_shapes API for…
mrDzurb Mar 3, 2025
8bc12ed
Merge branch 'feature/multi_model_deployment' of https://github.com/o…
lu-ohai Mar 3, 2025
1035203
Improved to support custom model.
lu-ohai Mar 4, 2025
84474fa
Update deployment.py
lu-ohai Mar 4, 2025
24b30d7
Update deployment.py
lu-ohai Mar 4, 2025
1a4661f
Added support to calculate gpu allocations for custom models.
lu-ohai Mar 4, 2025
ad76346
Merge branch 'feature/multi_model_deployment' of https://github.com/o…
lu-ohai Mar 4, 2025
55836f0
Merge branch 'main' of https://github.com/oracle/accelerated-data-sci…
lu-ohai Mar 4, 2025
162dc74
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 4, 2025
37be0de
Merge branch 'feature/multi_model_deployment' of https://github.com/o…
lu-ohai Mar 4, 2025
6251251
Updated pr.
lu-ohai Mar 4, 2025
95d810b
Moves the GPU shapes into index json.
mrDzurb Mar 5, 2025
024c016
Fixes the import error.
mrDzurb Mar 5, 2025
18d987b
Fixes tests
mrDzurb Mar 6, 2025
ce36613
Moves the GPU shapes into index json. (#1098)
mrDzurb Mar 6, 2025
578aff1
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 6, 2025
fb16dbd
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 6, 2025
d51c444
Fixes merging conflicts
mrDzurb Mar 6, 2025
b2811b2
Adds extra validation for the container family.
mrDzurb Mar 6, 2025
8fbd7b2
Merge branch 'feature/multi_model_deployment' of https://github.com/o…
lu-ohai Mar 6, 2025
bdb4de2
Added validation for custom model.
lu-ohai Mar 6, 2025
462753a
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 7, 2025
d6b20d5
Support deploy single model for multi deployment.
lu-ohai Mar 7, 2025
1b1268b
Updated pr.
lu-ohai Mar 7, 2025
ca835e4
Updated pr.
lu-ohai Mar 7, 2025
ab52eca
Support deploy multi custom models (#1095)
lu-ohai Mar 7, 2025
b1e91cd
Merge branch 'feature/multi_model_deployment' of https://github.com/o…
lu-ohai Mar 7, 2025
106300e
Enhances the MMD validation
mrDzurb Mar 7, 2025
307d60b
Merge branch 'feature/multi_model_deployment' into ODSC-69901/support…
mrDzurb Mar 8, 2025
2230837
Switch Multi-Model deployment container validation to usage-based tag
mrDzurb Mar 8, 2025
2553228
Merge branch 'feature/multi_model_deployment' of https://github.com/o…
lu-ohai Mar 9, 2025
080a251
Added unit test.
lu-ohai Mar 9, 2025
bfc0f15
Merge branch 'ODSC-69901/support_multi_deployment_single_model' of ht…
lu-ohai Mar 9, 2025
5041e69
Updated pr.
lu-ohai Mar 10, 2025
cab22b0
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 10, 2025
3dec8bc
Switch Multi-Model deployment container validation to usage-based tag…
mrDzurb Mar 10, 2025
76cc18a
Updated pr.
lu-ohai Mar 10, 2025
f1f8f42
Fixes the multi-model evaluation
mrDzurb Mar 10, 2025
2e09071
Fixes the multi-model evaluation validator
mrDzurb Mar 10, 2025
688b5ab
Fixes the multi-model evaluation validator
mrDzurb Mar 10, 2025
8a12e6e
Support deploy single model for multi deployment. (#1101)
mrDzurb Mar 10, 2025
afbd3f6
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 10, 2025
d92467e
Minor fixes of the error messages.
mrDzurb Mar 10, 2025
d9c6de3
Brings the MultiModelSupportedTaskType enum
mrDzurb Mar 11, 2025
b3e434f
Fixed unit tests.
lu-ohai Mar 11, 2025
60fd4f7
Fixed unit tests. (#1108)
lu-ohai Mar 11, 2025
3bff7ce
Update test_ui.py
lu-ohai Mar 11, 2025
9a36a1d
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 11, 2025
d79ea3f
Fixes the merging conflicts with the main branch
mrDzurb Mar 11, 2025
2e531d2
Adds more pydocs and comments
mrDzurb Mar 11, 2025
9c817e2
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 12, 2025
7506e2c
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 12, 2025
402db52
Changed multi model metadata storage.
lu-ohai Mar 12, 2025
3dc9977
Updated pr.
lu-ohai Mar 12, 2025
0313967
Fixes merging conflicts
mrDzurb Mar 12, 2025
53c2695
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 12, 2025
a524924
Merge branch 'feature/multi_model_deployment' of https://github.com/o…
lu-ohai Mar 12, 2025
b321d5c
Updated pr.
lu-ohai Mar 12, 2025
f9a3064
Updated pr.
lu-ohai Mar 12, 2025
740bf3d
Updated pr.
lu-ohai Mar 12, 2025
5060741
Changed multi model metadata storage. (#1112)
mrDzurb Mar 12, 2025
548664d
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 13, 2025
d245278
Added validation for single model.
lu-ohai Mar 13, 2025
f6f2c71
Merge branch 'feature/multi_model_deployment' of https://github.com/o…
lu-ohai Mar 13, 2025
c0daafd
Added validation single model (#1115)
mrDzurb Mar 13, 2025
b6d9d07
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 13, 2025
547eeba
Enhances create evaluation with adding the container_index_uri attribute
mrDzurb Mar 14, 2025
9e0a9ba
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 15, 2025
125ec6f
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 18, 2025
212f799
fixed docstrings to include links and kwargs for pydantic objects
elizjo Mar 18, 2025
427ea38
Minor fixes to pydocs
mrDzurb Mar 18, 2025
c3dbc6e
Additional CLI Support for AQUA with Pydantic Objects (#1126)
mrDzurb Mar 18, 2025
8203b31
added error message for invalid shape
elizjo Mar 19, 2025
0f703ba
Added Error Message for Unavailable Shape in Region (#1127)
mrDzurb Mar 19, 2025
eb9f5e1
Fixes unit tests
mrDzurb Mar 21, 2025
6408add
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 21, 2025
1c1702b
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 22, 2025
4713874
Extends Shape Validation for a single model deployment.
mrDzurb Mar 24, 2025
e3839f9
Update deployment_handler.py
mrDzurb Mar 25, 2025
314d819
Update deployment_handler.py
mrDzurb Mar 25, 2025
5eeed91
Make the validation strict.
mrDzurb Mar 26, 2025
c4248b6
Fix unit tests
mrDzurb Mar 26, 2025
44bb51d
Fixes edge case with the shapes.
mrDzurb Mar 26, 2025
02cb225
Merge branch 'feature/multi_model_deployment' of https://github.com/o…
lu-ohai Mar 26, 2025
00d3d41
Merge branch 'extends_shape_validation' of https://github.com/oracle/…
lu-ohai Mar 26, 2025
66fb84d
Added while loop in _verify_compatibility
lu-ohai Mar 26, 2025
a552456
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 26, 2025
8a01083
Merge branch 'feature/multi_model_deployment' of https://github.com/o…
lu-ohai Mar 26, 2025
2ac7dcf
Extends Shape Validation for a single model deployment. (#1134)
mrDzurb Mar 26, 2025
21c2a65
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 26, 2025
8e386af
Fixes unit tests
mrDzurb Mar 27, 2025
303a0ee
Covers the exceptional case of GPU allocation for the phi-4 models
mrDzurb Mar 27, 2025
35cc316
Adds BM.GPU.B4.8 shape
mrDzurb Mar 27, 2025
11cb745
Enhance params extracting logic
mrDzurb Mar 27, 2025
bc8dbc1
Merge branch 'main' into feature/multi_model_deployment
mrDzurb Mar 27, 2025
5176050
Fixes by comments
mrDzurb Mar 28, 2025
c797d95
Update model.py to fix format
lu-ohai Mar 28, 2025
a8ed99a
Fixes docs link
mrDzurb Mar 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ All the unit tests can be found [here](https://github.com/oracle/accelerated-dat
The following commands detail how the unit tests can be run.
```
# Run all tests in AQUA project
python -m pytest -q tests/unitary/with_extras/aqua/test_deployment.py
python -m pytest -q tests/unitary/with_extras/aqua/*

# Run all tests specific to a module within in AQUA project (ex. test_deployment.py, test_model.py, etc.)
python -m pytest -q tests/unitary/with_extras/aqua/test_deployment.py
Expand Down
6 changes: 6 additions & 0 deletions ads/aqua/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import os
import traceback
from dataclasses import fields
from datetime import datetime, timedelta
from typing import Any, Dict, Optional, Union

import oci
from cachetools import TTLCache, cached
from oci.data_science.models import UpdateModelDetails, UpdateModelProvenanceDetails

from ads import set_auth
Expand Down Expand Up @@ -269,6 +271,7 @@ def if_artifact_exist(self, model_id: str, **kwargs) -> bool:
logger.info(f"Artifact not found in model {model_id}.")
return False

@cached(cache=TTLCache(maxsize=1, ttl=timedelta(minutes=1), timer=datetime.now))
def get_config(
self,
model_id: str,
Expand Down Expand Up @@ -337,6 +340,9 @@ def get_config(
config_file_path = os.path.join(config_path, config_file_name)
if is_path_exists(config_file_path):
try:
logger.debug(
f"Loading config: `{config_file_name}` from `{config_path}`"
)
config = load_config(
config_path,
config_file_name=config_file_name,
Expand Down
226 changes: 224 additions & 2 deletions ads/aqua/common/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
# Copyright (c) 2024, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

import re
from typing import Any, Dict, Optional

from oci.data_science.models import Model
from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, model_validator

from ads.aqua import logger
from ads.aqua.config.utils.serializer import Serializable


class ContainerSpec:
Expand All @@ -25,7 +29,6 @@ class ContainerSpec:
class ModelConfigResult(BaseModel):
"""
Represents the result of getting the AQUA model configuration.

Attributes:
model_details (Dict[str, Any]): A dictionary containing model details extracted from OCI.
config (Dict[str, Any]): A dictionary of the loaded configuration.
Expand All @@ -42,3 +45,222 @@ class Config:
extra = "ignore"
arbitrary_types_allowed = True
protected_namespaces = ()


class GPUSpecs(Serializable):
"""
Represents the GPU specifications for a compute instance.
"""

gpu_memory_in_gbs: Optional[int] = Field(
default=None, description="The amount of GPU memory available (in GB)."
)
gpu_count: Optional[int] = Field(
default=None, description="The number of GPUs available."
)
gpu_type: Optional[str] = Field(
default=None, description="The type of GPU (e.g., 'V100, A100, H100')."
)


class GPUShapesIndex(Serializable):
"""
Represents the index of GPU shapes.

Attributes
----------
shapes (Dict[str, GPUSpecs]): A mapping of compute shape names to their GPU specifications.
"""

shapes: Dict[str, GPUSpecs] = Field(
default_factory=dict,
description="Mapping of shape names to GPU specifications.",
)


class ComputeShapeSummary(Serializable):
"""
Represents the specifications of a compute instance's shape.
"""

core_count: Optional[int] = Field(
default=None, description="The number of CPU cores available."
)
memory_in_gbs: Optional[int] = Field(
default=None, description="The amount of memory (in GB) available."
)
name: Optional[str] = Field(
default=None, description="The name identifier of the compute shape."
)
shape_series: Optional[str] = Field(
default=None, description="The series or category of the compute shape."
)
gpu_specs: Optional[GPUSpecs] = Field(
default=None,
description="The GPU specifications associated with the compute shape.",
)

@model_validator(mode="after")
@classmethod
def set_gpu_specs(cls, model: "ComputeShapeSummary") -> "ComputeShapeSummary":
"""
Validates and populates GPU specifications if the shape_series indicates a GPU-based shape.

- If the shape_series contains "GPU", the validator first checks if the shape name exists
in the GPU_SPECS dictionary. If found, it creates a GPUSpecs instance with the corresponding data.
- If the shape is not found in the GPU_SPECS, it attempts to extract the GPU count from the shape name
using a regex pattern (looking for a number following a dot at the end of the name).

The information about shapes is taken from: https://docs.oracle.com/en-us/iaas/data-science/using/supported-shapes.htm

Returns:
ComputeShapeSummary: The updated instance with gpu_specs populated if applicable.
"""
try:
if (
model.shape_series
and "GPU" in model.shape_series.upper()
and model.name
and not model.gpu_specs
):
# Try to extract gpu_count from the shape name using a regex (e.g., "VM.GPU3.2" -> gpu_count=2)
match = re.search(r"\.(\d+)$", model.name)
if match:
gpu_count = int(match.group(1))
model.gpu_specs = GPUSpecs(gpu_count=gpu_count)
except Exception as err:
logger.debug(
f"Error occurred in attempt to extract GPU specification for the f{model.name}. "
f"Details: {err}"
)
return model


class AquaMultiModelRef(Serializable):
"""
Lightweight model descriptor used for multi-model deployment.

This class only contains essential details
required to fetch complete model metadata and deploy models.

Attributes
----------
model_id : str
The unique identifier of the model.
model_name : Optional[str]
The name of the model.
gpu_count : Optional[int]
Number of GPUs required for deployment.
env_var : Optional[Dict[str, Any]]
Optional environment variables to override during deployment.
artifact_location : Optional[str]
Artifact path of model in the multimodel group.
"""

model_id: str = Field(..., description="The model OCID to deploy.")
model_name: Optional[str] = Field(None, description="The name of model.")
gpu_count: Optional[int] = Field(
None, description="The gpu count allocation for the model."
)
env_var: Optional[dict] = Field(
default_factory=dict, description="The environment variables of the model."
)
artifact_location: Optional[str] = Field(
None, description="Artifact path of model in the multimodel group."
)

class Config:
extra = "ignore"
protected_namespaces = ()


class ContainerPath(Serializable):
"""
Represents a parsed container path, extracting the path, name, and version.

This model is designed to parse a container path string of the format
'<image_path>:<version>'. It extracts the following components:
- `path`: The full path up to the version.
- `name`: The last segment of the path, representing the image name.
- `version`: The version number following the final colon.

Example Usage:
--------------
>>> container = ContainerPath(full_path="iad.ocir.io/ociodscdev/odsc-llm-evaluate:0.1.2.9")
>>> container.path
'iad.ocir.io/ociodscdev/odsc-llm-evaluate'
>>> container.name
'odsc-llm-evaluate'
>>> container.version
'0.1.2.9'

>>> container = ContainerPath(full_path="custom-scheme://path/to/versioned-model:2.5.1")
>>> container.path
'custom-scheme://path/to/versioned-model'
>>> container.name
'versioned-model'
>>> container.version
'2.5.1'

Attributes
----------
full_path : str
The complete container path string to be parsed.
path : Optional[str]
The full path up to the version (e.g., 'iad.ocir.io/ociodscdev/odsc-llm-evaluate').
name : Optional[str]
The image name, which is the last segment of `path` (e.g., 'odsc-llm-evaluate').
version : Optional[str]
The version number following the final colon in the path (e.g., '0.1.2.9').

Methods
-------
validate(values: Any) -> Any
Validates and parses the `full_path`, extracting `path`, `name`, and `version`.
"""

full_path: str
path: Optional[str] = None
name: Optional[str] = None
version: Optional[str] = None

@model_validator(mode="before")
@classmethod
def validate(cls, values: Any) -> Any:
"""
Validates and parses the full container path, extracting the image path, image name, and version.

Parameters
----------
values : dict
The dictionary of values being validated, containing 'full_path'.

Returns
-------
dict
Updated values dictionary with extracted 'path', 'name', and 'version'.
"""
full_path = values.get("full_path", "").strip()

# Regex to parse <image_path>:<version>
match = re.match(
r"^(?P<image_path>.+?)(?::(?P<image_version>[\w\.]+))?$", full_path
)

if not match:
raise ValueError(
"Invalid container path format. Expected format: '<image_path>:<version>'"
)

# Extract image_path and version
values["path"] = match.group("image_path")
values["version"] = match.group("image_version")

# Extract image_name as the last segment of image_path
values["name"] = values["path"].split("/")[-1]

return values

class Config:
extra = "ignore"
protected_namespaces = ()
3 changes: 3 additions & 0 deletions ads/aqua/common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Tags(ExtendedEnum):
AQUA_TAG = "OCI_AQUA"
AQUA_SERVICE_MODEL_TAG = "aqua_service_model"
AQUA_FINE_TUNED_MODEL_TAG = "aqua_fine_tuned_model"
AQUA_MODEL_ID_TAG = "aqua_model_id"
AQUA_MODEL_NAME_TAG = "aqua_model_name"
AQUA_EVALUATION = "aqua_evaluation"
AQUA_FINE_TUNING = "aqua_finetuning"
Expand All @@ -34,6 +35,7 @@ class Tags(ExtendedEnum):
AQUA_EVALUATION_MODEL_ID = "evaluation_model_id"
MODEL_FORMAT = "model_format"
MODEL_ARTIFACT_FILE = "model_file"
MULTIMODEL_TYPE_TAG = "aqua_multimodel"


class InferenceContainerType(ExtendedEnum):
Expand All @@ -44,6 +46,7 @@ class InferenceContainerType(ExtendedEnum):

class InferenceContainerTypeFamily(ExtendedEnum):
AQUA_VLLM_CONTAINER_FAMILY = "odsc-vllm-serving"
AQUA_VLLM_V1_CONTAINER_FAMILY = "odsc-vllm-serving-v1"
AQUA_TGI_CONTAINER_FAMILY = "odsc-tgi-serving"
AQUA_LLAMA_CPP_CONTAINER_FAMILY = "odsc-llama-cpp-serving"

Expand Down
Loading