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

Feature/aqua ms changes #1019

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Feature/aqua ms changes #1019

wants to merge 7 commits into from

Conversation

vikasray0208
Copy link
Member

This Pull Request is for adding/updating API for listing SMM ,Model custom and defined metadata artifact in DataScienceModel in ADS.

This PR will enable following changes

  • Service Model Listing: Enable the listing of service models without requiring the service compartment ID and cross-tenancy access.
  • Metadata Storage: Enable additional metadata store , such as license content, README.md, deployment config, manifest.yaml, and fine-tuning config. Also, implement a search functionality for the license and keys from the README via RQS.

API Spec :- https://confluence.oci.oraclecorp.com/pages/viewpage.action?spaceKey=ODSC&title=API+changes+for+Model+store+for+Aqua
Design Doc :- https://confluence.oci.oraclecorp.com/display/ODSC/Model+Store+Enhancements+For+AQUA+-+Design

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Dec 5, 2024
Copy link

github-actions bot commented Dec 5, 2024

📌 Cov diff with main:

Coverage-26%

📌 Overall coverage:

Coverage-20.14%

@vikasray0208
Copy link
Member Author

Model API test to List SMM and query parameter category changes

Screenshot 2024-12-05 at 1 43 44 PM Screenshot 2024-12-05 at 1 45 06 PM Screenshot 2024-12-05 at 1 45 41 PM

Model Version Set API test to List SMM and query parameter category changes

Screenshot 2024-12-05 at 1 48 20 PM Screenshot 2024-12-05 at 1 56 37 PM Screenshot 2024-12-05 at 1 55 39 PM

Custom Metadata API Test

Screenshot 2024-12-05 at 1 37 17 PM Screenshot 2024-12-05 at 1 37 50 PM

Defined Metadata API Test

Screenshot 2024-12-05 at 1 41 21 PM Screenshot 2024-12-05 at 1 41 26 PM

Copy link

github-actions bot commented Dec 6, 2024

📌 Cov diff with main:

Coverage-26%

📌 Overall coverage:

Coverage-20.14%

@@ -454,14 +454,16 @@ def kind(self) -> str:
return "modelVersionSet"

@classmethod
def list(cls, compartment_id: str = None, **kwargs) -> List["ModelVersionSet"]:
def list(cls, compartment_id: str = None, category: str = "USER", **kwargs) -> List["ModelVersionSet"]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move category to constants.

class ModelCategory (str, metaclass=ExtendedEnumMeta):
    USER = "USER"
    SERVICE = "SERVICE"

This variable is used across many modules.

@@ -1571,7 +1573,7 @@ def delete(

@classmethod
def list(
cls, compartment_id: str = None, project_id: str = None, **kwargs
cls, compartment_id: str = None, project_id: str = None, category: str = "USER", **kwargs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move category to constants.

class ModelCategory (str, metaclass=ExtendedEnumMeta):
    USER = "USER"
    SERVICE = "SERVICE"

This variable is used across many modules.

)
]

@classmethod
def list_df(
cls, compartment_id: str = None, project_id: str = None, **kwargs
cls, compartment_id: str = None, project_id: str = None, category: str = "USER", **kwargs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you install a pre-commit hook and validate the changed files with it. Internally we use ruff formatter.

@@ -2193,3 +2199,249 @@ def find_model_idx():
else:
# model found case
self.model_file_description["models"].pop(modelSearchIdx)

def create_custom_metadata_artifact(self, model_ocid: str, metadata_key_name: str, artifact_path: str) -> dict:
"""Creates model custom metadata artifact for specified model.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more description for this model. For example when this method needs to be used. Also check the parameters section, looks like there is some formatting issue.
Also it would be better if instead of dict we return some dataclass or pydentic class.

from ads.common.serializer import DataClassSerializable

@dataclass
class MyClass():

    attr1: Optional[str] = None
    attr2: Optional[str] = None

OR

from pydantic import BaseModel

class MyClass(BaseModel):

    attr1: Optional[str] = None
    attr2: Optional[str] = None

artifact_path=artifact_path)


def create_defined_metadata_artifact(self, model_ocid: str, metadata_key_name: str, artifact_path: str) -> dict:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we have a one method and pass artifact type as a param?

def create_defined_metadata_artifact(..., type: str):
       return self.dsc_model.create_defined_metadata_artifact(...)

metadata_key_name: str
The name of the model metadatum in the metadata.

artifact_path: str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we will support only local paths, not OS bucket paths? If so, that needs to be mentioned in the pydocs.

artifact_file_path = os.path.join(
target_dir, f"{metadata_key_name}"
)
with open(artifact_file_path, "wb") as _file:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the file with the given name already exists? We should allow user to override existing files and fail if they didn't set override param to True, by default it should be false.

@@ -454,14 +454,16 @@ def kind(self) -> str:
return "modelVersionSet"

@classmethod
def list(cls, compartment_id: str = None, **kwargs) -> List["ModelVersionSet"]:
def list(cls, compartment_id: str = None, category: str = "USER", **kwargs) -> List["ModelVersionSet"]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create will continue working without changes, right?

@@ -89,6 +92,12 @@ def wrapper(self, *args, **kwargs):
return decorator


def convert_response_to_dict(headers:dict,status:int):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See one of the comments above, it would be better to use dataclass or pydentic class for this.

@@ -596,3 +605,331 @@ def is_model_by_reference(self):
):
return True
return False

def create_custom_metadata_artifact(self, model_ocid: str, metadata_key_name: str, artifact_path: str) -> dict:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See one of the comments above. Why do we need two methods for creating artifacts? Custom and Defined can be combined?

@mrDzurb
Copy link
Member

mrDzurb commented Dec 13, 2024

Please use pre-commit hook to format changed files. Also we use ruff plugin to autoformat and validate code.

Copy link

📌 Cov diff with main:

Coverage-26%

📌 Overall coverage:

Coverage-20.13%

)
with open(artifact_file_path, "wb") as _file:
_file.write(file_content)
print(f"Artifact downloaded to location - {artifact_file_path}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use logger instead of print throughout the PR


Parameters
----------
model_ocid: str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to accept model_ocid as input for these functions, can we use the self.id property instead?

contents = f.read()
print(contents)

response = self.client.create_model_custom_metadatum_artifact(model_ocid, metadata_key_name, contents,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do some validation of contents here to avoid incorrect values/data resulting in service errors?

try:
return self.client.get_model_custom_metadatum_artifact_content(model_ocid, metadata_key_name).data.content
except ServiceError as ex:
if ex.status == 404:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we log error here and return the message as well with ModelMetadataArtifactNotFoundError?

@VipulMascarenhas
Copy link
Member

@vikasray0208 can you update the screenshots and hide/obfuscate the ocids and namespaces?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants