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

[DRCC][Ready to Merge] AQUA MS Enhancements #1058

Open
wants to merge 99 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
5fdf8dd
Adding support for list models and getdefined metadata
NitinMore7 Jan 20, 2025
1080a04
Adding support for list models and getdefined metadata
NitinMore7 Jan 21, 2025
c76fb7d
resolving conflicts and rebasing to feature/aqua_ms_changes_2
NitinMore7 Feb 4, 2025
fde423c
add exception for other models in automlx mode and enable test for au…
codeloop Dec 16, 2024
91ee523
move automlx explaination to subclass
codeloop Dec 16, 2024
4502d9f
skip check for global explanations, exception handling
codeloop Jan 8, 2025
075f8ab
adding additional check for listing models to check if category is pa…
NitinMore7 Jan 28, 2025
1ac9e1c
adding additional check on arguments to check if category is passed i…
NitinMore7 Feb 4, 2025
f4106db
list models bugfix
kumar-shivam-ranjan Feb 5, 2025
a2d00f0
Merge branch 'feature/aqua_ms_changes_2' into aqua/ADS_MS_changes
kumar-shivam-ranjan Feb 10, 2025
1536afc
Rebasing
kumar-shivam-ranjan Feb 18, 2025
e6eddaa
Fixing get HF tokenizer config
kumar-shivam-ranjan Feb 18, 2025
bd5ecc2
adding test cases
NitinMore7 Feb 19, 2025
fc3e9eb
adding test cases
NitinMore7 Feb 19, 2025
1e7b356
Adding get defined metadata handler
kumar-shivam-ranjan Feb 21, 2025
8d880eb
Adding AQUA handler for defined metadata artifact
kumar-shivam-ranjan Feb 25, 2025
196e679
Updating defined metadata artifact handler
kumar-shivam-ranjan Feb 25, 2025
223018b
adding delete model metadata
NitinMore7 Feb 26, 2025
675eeb0
Adding create model defined metadata artifact handler
kumar-shivam-ranjan Mar 3, 2025
1ee344f
Adding create model defined metadata artifact handler
kumar-shivam-ranjan Mar 3, 2025
4cd473c
Adding defined metadata artifact while model registration
kumar-shivam-ranjan Mar 3, 2025
47ffda8
Adding readme for unverified model registration flow
kumar-shivam-ranjan Mar 3, 2025
f55b777
Adding unverified flow registration for defined metadata artifact
kumar-shivam-ranjan Mar 3, 2025
b2577fa
Fixing delete model logic
kumar-shivam-ranjan Mar 3, 2025
17322e6
Adding Updating model taxonomy metadata of ADS to include has_artifact
kumar-shivam-ranjan Mar 4, 2025
0d8a0b5
Rebasing
kumar-shivam-ranjan Mar 4, 2025
181ff77
Rebasing
kumar-shivam-ranjan Mar 4, 2025
ec0e27c
Merge branch 'feature/aqua_ms_changes_2' into aqua/ADS_MS_changes
kumar-shivam-ranjan Mar 4, 2025
f9df3ca
Fixing conflicts
kumar-shivam-ranjan Mar 4, 2025
9ed0ed0
Merge branch 'feature/aqua_ms_changes_2' into aqua/ADS_MS_changes
kumar-shivam-ranjan Mar 4, 2025
af2037e
Adding docstring
kumar-shivam-ranjan Mar 5, 2025
ed6d17a
Adding smc container listing api
kumar-shivam-ranjan Mar 6, 2025
bd5893c
Rebasing
kumar-shivam-ranjan Mar 6, 2025
c18124e
Updating websocket message handler
kumar-shivam-ranjan Mar 6, 2025
4896a87
Fixing readme decoding utf-8
kumar-shivam-ranjan Mar 6, 2025
e844b8c
fixing license content decoding
kumar-shivam-ranjan Mar 6, 2025
ba99328
Addressing review comments
kumar-shivam-ranjan Mar 10, 2025
c1600c6
Removing hardcoding of smc containers in config_parser
kumar-shivam-ranjan Mar 10, 2025
03d63c6
Adding default for category
kumar-shivam-ranjan Mar 11, 2025
864d592
Updating get config to maintain backward compatibility
kumar-shivam-ranjan Mar 11, 2025
666e933
Merge branch 'feature/aqua_ms_changes_2' into aqua/ADS_MS_changes
kumar-shivam-ranjan Mar 11, 2025
46d05a6
Maintaining backward compatibility
kumar-shivam-ranjan Mar 11, 2025
c0ecbe4
Removing print statements
kumar-shivam-ranjan Mar 11, 2025
a170cba
Adding backward compatibility code
kumar-shivam-ranjan Mar 11, 2025
5165649
changing eval download report to handle files instead of zip
NitinMore7 Mar 11, 2025
2fd1c35
changing file name in download report
NitinMore7 Mar 12, 2025
1c501c0
Eval bugfixes
kumar-shivam-ranjan Mar 12, 2025
26b9b19
Rebasing
kumar-shivam-ranjan Mar 13, 2025
6b2477a
Rebasing
kumar-shivam-ranjan Mar 14, 2025
1072c7b
Addressing review comments draft 1
kumar-shivam-ranjan Mar 14, 2025
3722356
Addressing review comments
kumar-shivam-ranjan Mar 14, 2025
5708629
Addressing review comments
kumar-shivam-ranjan Mar 14, 2025
386de0e
Adding seperate API for readme
kumar-shivam-ranjan Mar 14, 2025
b559851
Merge branch 'main' into aqua/ADS_MS_changes
mrDzurb Mar 15, 2025
8c2a3be
Removed config_parser logic
kumar-shivam-ranjan Mar 15, 2025
a6d37b8
Merge branch 'aqua/ADS_MS_changes' of https://github.com/oracle/accel…
kumar-shivam-ranjan Mar 15, 2025
97d6bda
Removing const evaluation config
kumar-shivam-ranjan Mar 15, 2025
e1d3d04
Caching SMC List api call
kumar-shivam-ranjan Mar 15, 2025
97436f1
Removing aquapp call in utils
kumar-shivam-ranjan Mar 15, 2025
bbeee70
Fixing UTs
kumar-shivam-ranjan Mar 15, 2025
64ebeff
Addressing review comments
kumar-shivam-ranjan Mar 17, 2025
ed10e7f
Addressing review comments
kumar-shivam-ranjan Mar 17, 2025
54c4fb9
Fixing UTs
kumar-shivam-ranjan Mar 17, 2025
a44fec3
Addressing review comments
kumar-shivam-ranjan Mar 19, 2025
ecee485
Merge branch 'main' into aqua/ADS_MS_changes
kumar-shivam-ranjan Mar 19, 2025
6114143
Addressing review comments
kumar-shivam-ranjan Mar 19, 2025
48d586d
Fixing UTs
kumar-shivam-ranjan Mar 19, 2025
eef1c64
fixing unverified flow registration bug
kumar-shivam-ranjan Mar 20, 2025
eb8dda9
Removing print statement
kumar-shivam-ranjan Mar 20, 2025
6714621
Updating key val pairs for MD env vars
kumar-shivam-ranjan Mar 20, 2025
1f73ab6
Adding evaluation_configuration in AquaContainerConfigSpec
kumar-shivam-ranjan Mar 20, 2025
5b2e541
Fixing UTs
kumar-shivam-ranjan Mar 20, 2025
b196549
Addressing review comments
kumar-shivam-ranjan Mar 20, 2025
eb7b580
Error handling for uploading readme and license
kumar-shivam-ranjan Mar 23, 2025
13dfad0
Deployment fix for TEI container
kumar-shivam-ranjan Mar 23, 2025
eb5fb40
Fixing UTs
kumar-shivam-ranjan Mar 24, 2025
8e94b6d
Merge branch 'main' into aqua/ADS_MS_changes
kumar-shivam-ranjan Mar 24, 2025
d49a88d
Updating if_model_custom_metadata_artifact_exist in evaluation
kumar-shivam-ranjan Mar 24, 2025
c248ad5
Merge branch 'fix/metadata-api-changes' into aqua/ADS_MS_changes
kumar-shivam-ranjan Mar 24, 2025
ec98228
Removing model_card field from AquaModel
kumar-shivam-ranjan Mar 24, 2025
38e0838
Adding logging in update metrics
kumar-shivam-ranjan Mar 25, 2025
741067d
Merge branch 'main' into aqua/ADS_MS_changes
kumar-shivam-ranjan Mar 25, 2025
0cf4aa2
Merge branch 'main' into aqua/ADS_MS_changes
kumar-shivam-ranjan Mar 25, 2025
2fed3dc
Removing print statements
kumar-shivam-ranjan Mar 26, 2025
55a52a7
Merge branch 'main' into aqua/ADS_MS_changes
kumar-shivam-ranjan Mar 27, 2025
c16889b
Addressing review comments
kumar-shivam-ranjan Mar 27, 2025
5616f90
Adding logs for fetching model config
kumar-shivam-ranjan Mar 27, 2025
1b5bbd1
Merge branch 'main' into aqua/ADS_MS_changes
kumar-shivam-ranjan Mar 27, 2025
d1e9608
Updating edit registered model flow
kumar-shivam-ranjan Mar 28, 2025
ce46cf7
Resolving merge conflicts
kumar-shivam-ranjan Apr 1, 2025
b890243
Fixing UTs
kumar-shivam-ranjan Apr 1, 2025
cc18bcf
Rebasing and Fixing UTs
kumar-shivam-ranjan Apr 3, 2025
631b666
Merge branch 'main' into aqua/ADS_MS_changes
kumar-shivam-ranjan Apr 3, 2025
82ecf64
Addressing review comments
kumar-shivam-ranjan Apr 3, 2025
8fd603e
Merge branch 'aqua/ADS_MS_changes' of https://github.com/oracle/accel…
kumar-shivam-ranjan Apr 3, 2025
e9267de
Adding AquaFineTuningConfig
kumar-shivam-ranjan Apr 3, 2025
1861f25
Updating fetch evaluation report flow
kumar-shivam-ranjan Apr 4, 2025
9cefbb7
Adding return type and type hinting for create_defined_metadata_artifact
kumar-shivam-ranjan Apr 4, 2025
642e8f9
Merge branch 'main' into aqua/ADS_MS_changes
kumar-shivam-ranjan Apr 4, 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
153 changes: 133 additions & 20 deletions ads/aqua/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
import traceback
from dataclasses import fields
from datetime import datetime, timedelta
from typing import Any, Dict, Optional, Union
from itertools import chain
from typing import Any, Dict, List, Optional, Union

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

from ads import set_auth
from ads.aqua import logger
Expand All @@ -24,6 +29,11 @@
is_valid_ocid,
load_config,
)
from ads.aqua.config.container_config import (
AquaContainerConfig,
AquaContainerConfigItem,
)
from ads.aqua.constants import SERVICE_MANAGED_CONTAINER_URI_SCHEME
from ads.common import oci_client as oc
from ads.common.auth import default_signer
from ads.common.utils import UNKNOWN, extract_region, is_path_exists
Expand Down Expand Up @@ -240,7 +250,9 @@ def create_model_catalog(
.with_custom_metadata_list(model_custom_metadata)
.with_defined_metadata_list(model_taxonomy_metadata)
.with_provenance_metadata(ModelProvenanceMetadata(training_id=UNKNOWN))
.with_defined_tags(**(defined_tags or {})) # Create defined tags when a model is created.
.with_defined_tags(
**(defined_tags or {})
) # Create defined tags when a model is created.
.create(
**kwargs,
)
Expand Down Expand Up @@ -271,6 +283,43 @@ def if_artifact_exist(self, model_id: str, **kwargs) -> bool:
logger.info(f"Artifact not found in model {model_id}.")
return False

def get_config_from_metadata(
self, model_id: str, metadata_key: str
) -> ModelConfigResult:
"""Gets the config for the given Aqua model from model catalog metadata content.

Parameters
----------
model_id: str
The OCID of the Aqua model.
metadata_key: str
The metadata key name where artifact content is stored
Returns
-------
ModelConfigResult
A Pydantic model containing the model_details (extracted from OCI) and the config dictionary.
"""
config = {}
oci_model = self.ds_client.get_model(model_id).data
try:
config = self.ds_client.get_model_defined_metadatum_artifact_content(
model_id, metadata_key
).data.content.decode("utf-8")
return ModelConfigResult(config=json.loads(config), model_details=oci_model)
except UnicodeDecodeError as ex:
logger.error(
f"Failed to decode content for '{metadata_key}' in defined metadata for model '{model_id}' : {ex}"
)
except json.JSONDecodeError as ex:
logger.error(
f"Invalid JSON format for '{metadata_key}' in defined metadata for model '{model_id}' : {ex}"
)
except Exception as ex:
logger.error(
f"Failed to retrieve defined metadata key '{metadata_key}' for model '{model_id}': {ex}"
)
return ModelConfigResult(config=config, model_details=oci_model)

@cached(cache=TTLCache(maxsize=1, ttl=timedelta(minutes=1), timer=datetime.now))
def get_config(
self,
Expand Down Expand Up @@ -310,22 +359,7 @@ def get_config(
raise AquaRuntimeError(f"Target model {oci_model.id} is not an Aqua model.")

config: Dict[str, Any] = {}

# if the current model has a service model tag, then
if Tags.AQUA_SERVICE_MODEL_TAG in oci_model.freeform_tags:
base_model_ocid = oci_model.freeform_tags[Tags.AQUA_SERVICE_MODEL_TAG]
logger.info(
f"Base model found for the model: {oci_model.id}. "
f"Loading {config_file_name} for base model {base_model_ocid}."
)
if config_folder == ConfigFolder.ARTIFACT:
artifact_path = get_artifact_path(oci_model.custom_metadata_list)
else:
base_model = self.ds_client.get_model(base_model_ocid).data
artifact_path = get_artifact_path(base_model.custom_metadata_list)
else:
logger.info(f"Loading {config_file_name} for model {oci_model.id}...")
artifact_path = get_artifact_path(oci_model.custom_metadata_list)
artifact_path = get_artifact_path(oci_model.custom_metadata_list)
if not artifact_path:
logger.debug(
f"Failed to get artifact path from custom metadata for the model: {model_id}"
Expand All @@ -340,7 +374,7 @@ def get_config(
config_file_path = os.path.join(config_path, config_file_name)
if is_path_exists(config_file_path):
try:
logger.debug(
logger.info(
f"Loading config: `{config_file_name}` from `{config_path}`"
)
config = load_config(
Expand All @@ -361,6 +395,85 @@ def get_config(

return ModelConfigResult(config=config, model_details=oci_model)

def get_container_image(self, container_type: str = None) -> str:
"""
Gets the latest smc container complete image name from the given container type.

Parameters
----------
container_type: str
type of container, can be either odsc-vllm-serving, odsc-llm-fine-tuning, odsc-llm-evaluate

Returns
-------
str:
A complete container name along with version. ex: dsmc://odsc-vllm-serving:0.7.4.1
"""

containers = self.list_service_containers()
container = next(
(c for c in containers if c.is_latest and c.family_name == container_type),
None,
)
if not container:
raise AquaValueError(f"Invalid container type : {container_type}")
container_image = (
SERVICE_MANAGED_CONTAINER_URI_SCHEME
+ container.container_name
+ ":"
+ container.tag
)
return container_image

@cached(cache=TTLCache(maxsize=20, ttl=timedelta(minutes=30), timer=datetime.now))
def list_service_containers(self) -> List[ContainerSummary]:
"""
List containers from containers.conf in OCI Datascience control plane
"""
containers = self.ds_client.list_containers().data
return containers

def get_container_config(self) -> AquaContainerConfig:
"""
Fetches latest containers from containers.conf in OCI Datascience control plane

Returns
-------
AquaContainerConfig
An Object that contains latest container info for the given container family

"""
return AquaContainerConfig.from_service_config(
service_containers=self.list_service_containers()
)

def get_container_config_item(
self, container_family: str
) -> AquaContainerConfigItem:
"""
Fetches latest container for given container_family_name from containers.conf in OCI Datascience control plane

Returns
-------
AquaContainerConfigItem
An Object that contains latest container info for the given container family

"""

aqua_container_config = self.get_container_config()
inference_config = aqua_container_config.inference.values()
ft_config = aqua_container_config.finetune.values()
eval_config = aqua_container_config.evaluate.values()
container = next(
(
container
for container in chain(inference_config, ft_config, eval_config)
if container.family.lower() == container_family.lower()
),
None,
)
return container

@property
def telemetry(self):
if not self._telemetry:
Expand Down
63 changes: 12 additions & 51 deletions ads/aqua/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@
COMPARTMENT_MAPPING_KEY,
CONSOLE_LINK_RESOURCE_TYPE_MAPPING,
CONTAINER_INDEX,
DEPLOYMENT_CONFIG,
FINE_TUNING_CONFIG,
HF_LOGIN_DEFAULT_TIMEOUT,
LICENSE,
MAXIMUM_ALLOWED_DATASET_IN_BYTE,
MODEL_BY_REFERENCE_OSS_PATH_KEY,
README,
SERVICE_MANAGED_CONTAINER_URI_SCHEME,
SUPPORTED_FILE_FORMATS,
TEI_CONTAINER_DEFAULT_HOST,
Expand Down Expand Up @@ -88,6 +92,14 @@
logger = logging.getLogger("ads.aqua")


DEFINED_METADATA_TO_FILE_MAP = {
"readme": README,
"license": LICENSE,
"finetuneconfiguration": FINE_TUNING_CONFIG,
"deploymentconfiguration": DEPLOYMENT_CONFIG,
}


class LifecycleStatus(ExtendedEnum):
UNKNOWN = ""

Expand Down Expand Up @@ -552,57 +564,6 @@ def service_config_path():
return f"oci://{AQUA_SERVICE_MODELS_BUCKET}@{CONDA_BUCKET_NS}/service_models/config"


@cached(cache=TTLCache(maxsize=1, ttl=timedelta(minutes=10), timer=datetime.now))
def get_container_config():
config = load_config(
file_path=service_config_path(),
config_file_name=CONTAINER_INDEX,
)

return config


def get_container_image(
config_file_name: str = None, container_type: str = None
) -> str:
"""Gets the image name from the given model and container type.
Parameters
----------
config_file_name: str
name of the config file
container_type: str
type of container, can be either deployment-container, finetune-container, evaluation-container

Returns
-------
Dict:
A dict of allowed configs.
"""

container_image = UNKNOWN
config = config_file_name or get_container_config()
config_file_name = service_config_path()

if container_type not in config:
return UNKNOWN

mapping = config[container_type]
versions = [obj["version"] for obj in mapping]
# assumes numbered versions, update if `latest` is used
latest = get_max_version(versions)
for obj in mapping:
if obj["version"] == str(latest):
container_image = f"{obj['name']}:{obj['version']}"
break

if not container_image:
raise AquaValueError(
f"{config_file_name} is missing name and/or version details."
)

return container_image


def fetch_service_compartment() -> Union[str, None]:
"""
Loads the compartment mapping json from service bucket.
Expand Down
31 changes: 0 additions & 31 deletions ads/aqua/config/config.py

This file was deleted.

Loading