ads.model.service package

Submodules

ads.model.service.oci_datascience_model module

exception ads.model.service.oci_datascience_model.ModelArtifactNotFoundError[source]

Bases: Exception

exception ads.model.service.oci_datascience_model.ModelNotSavedError[source]

Bases: Exception

exception ads.model.service.oci_datascience_model.ModelProvenanceNotFoundError[source]

Bases: Exception

exception ads.model.service.oci_datascience_model.ModelWithActiveDeploymentError[source]

Bases: Exception

class ads.model.service.oci_datascience_model.OCIDataScienceModel(config: dict | None = None, signer: Signer | None = None, client_kwargs: dict | None = None, **kwargs)[source]

Bases: OCIDataScienceMixin, OCIWorkRequestMixin, Model

Represents an OCI Data Science Model. This class contains all attributes of the oci.data_science.models.Model. The main purpose of this class is to link the oci.data_science.models.Model and the related client methods. Linking the Model (payload) to Create/Update/Get/List/Delete methods.

The OCIDataScienceModel can be initialized by unpacking the properties stored in a dictionary:

properties = {
    "compartment_id": "<compartment_ocid>",
    "name": "<model_name>",
    "description": "<model_description>",
}
ds_model = OCIDataScienceModel(**properties)

The properties can also be OCI REST API payload, in which the keys are in camel format.

payload = {
    "compartmentId": "<compartment_ocid>",
    "name": "<model_name>",
    "description": "<model_description>",
}
ds_model = OCIDataScienceModel(**payload)
create(self) 'OCIDataScienceModel'[source]

Creates datascience model in model catalog.

create_model_provenance(self, model_provenance: ModelProvenance) oci.data_science.models.ModelProvenance:[source]

Creates model provenance metadata.

def update_model_provenance(self, ModelProvenance) -> oci.data_science.models.ModelProvenance:

Updates model provenance metadata.

get_model_provenance(self) oci.data_science.models.ModelProvenance:[source]

Gets model provenance metadata.

get_artifact_info(self) Dict:[source]

Gets model artifact attachment information.

def get_model_artifact_content(self) -> BytesIO:

Gets model artifact content.

create_model_artifact(self, bytes_content: BytesIO) None:[source]

Creates model artifact for specified model.

import_model_artifact(self, bucket_uri: str, region: str = None) None:[source]

Imports model artifact content from the model catalog.

export_model_artifact(self, bucket_uri: str, region: str = None):

Exports model artifact to the model catalog.

update(self) "OCIDataScienceModel":[source]

Updates datascience Model.

delete(self, delete_associated_model_deployment: bool | None = False) "OCIDataScienceModel":[source]

Deletes detascience Model.

model_deployment(self, ...) List:[source]

Gets the list of model deployments by model ID across the compartments.

from_id(cls, ocid: str) "OCIDataScienceModel":[source]

Gets model by OCID.

Examples

>>> oci_model = OCIDataScienceModel.from_id(<model_ocid>)
>>> oci_model.model_deployment()
>>> oci_model.get_model_provenance()
>>> oci_model.description = "A brand new description"
... oci_model.update()
>>> oci_model.sync()
>>> oci_model.get_artifact_info()

Initializes a service/resource with OCI client as a property. If config or signer is specified, it will be used to initialize the OCI client. If neither of them is specified, the client will be initialized with ads.common.auth.default_signer. If both of them are specified, both of them will be passed into the OCI client,

and the authentication will be determined by OCI Python SDK.

Parameters:
  • config (dict, optional) – OCI API key config dictionary, by default None.

  • signer (oci.signer.Signer, optional) – OCI authentication signer, by default None.

  • client_kwargs (dict, optional) – Additional keyword arguments for initializing the OCI client.

create() OCIDataScienceModel[source]

Creates datascience model in model catalog.

Returns:

The OCIDataScienceModel instance (self), which allows chaining additional method.

Return type:

OCIDataScienceModel

create_model_artifact(bytes_content: BytesIO, extension: str = None) None[source]

Creates model artifact for specified model.

Parameters:
  • bytes_content (BytesIO) – Model artifacts to upload.

  • extension (str) – File extension, defaults to zip

create_model_provenance(model_provenance: ModelProvenance) ModelProvenance[source]

Creates model provenance metadata.

Parameters:

model_provenance (oci.data_science.models.ModelProvenance) – OCI model provenance metadata.

Returns:

The OCI model provenance object.

Return type:

oci.data_science.models.ModelProvenance

delete(delete_associated_model_deployment: bool | None = False) OCIDataScienceModel[source]

Deletes detascience Model.

Parameters:

delete_associated_model_deployment ((bool, optional). Defaults to False.) – Whether associated model deployments need to be deleted or not.

Returns:

The OCIDataScienceModel instance (self).

Return type:

OCIDataScienceModel

Raises:

ModelWithActiveDeploymentError – If model has active deployments and delete_associated_model_deployment set to False.

export_model_artifact(bucket_uri: str, region: str = None)[source]

Exports model artifact to the model catalog. Can be used for any model artifact. Requires to provide an Object Storage bucket, for transitional saving artifacts. For the small artifacts use create_model_artifact method.

Parameters:
  • bucket_uri (str) – The OCI Object Storage URI where model artifacts will be copied to. The bucket_uri is only necessary for downloading large artifacts which size is greater than 2GB. Example: oci://<bucket_name>@<namespace>/prefix/.

  • region ((str, optional). Defaults to None.) – The destination Object Storage bucket region. By default the value will be extracted from the OCI_REGION_METADATA environment variables.

Return type:

None

classmethod from_id(ocid: str) OCIDataScienceModel[source]

Gets model by OCID.

Parameters:

ocid (str) – The OCID of the datascience model.

Returns:

An instance of OCIDataScienceModel.

Return type:

OCIDataScienceModel

get_artifact_info() Dict[source]

Gets model artifact attachment information.

Returns:

The model artifact attachement info. Example: {

’Date’: ‘Sun, 13 Nov 2022 06:01:27 GMT’, ‘opc-request-id’: ‘E4F7’, ‘ETag’: ‘77156317-8bb9-4c4a-882b-0d85f8140d93’, ‘Content-Disposition’: ‘attachment; filename=artifact.zip’, ‘Last-Modified’: ‘Sun, 09 Oct 2022 16:50:14 GMT’, ‘Content-Type’: ‘application/json’, ‘Content-MD5’: ‘orMy3Gs386GZLjYWATJWuA==’, ‘X-Content-Type-Options’: ‘nosniff’, ‘Content-Length’: ‘4029958’

}

Return type:

Dict

Raises:

ModelArtifactNotFoundError – If model artifact attchment not found.

get_model_artifact_content() BytesIO[source]

Gets model artifact content. Can only be used to the small artifacts, which size is less than 2GB. For the large artifacts needs to be used a import_model_artifact method.

Returns:

Object with data of type stream.

Return type:

BytesIO

Raises:

ModelArtifactNotFoundError – If model artifact not found.

get_model_provenance() ModelProvenance[source]

Gets model provenance metadata.

Returns:

OCI model provenance metadata.

Return type:

oci.data_science.models.ModelProvenance

Raises:

ModelProvenanceNotFoundError – If model provenance not found.

import_model_artifact(bucket_uri: str, region: str = None) None[source]

Imports model artifact content from the model catalog. Requires to provide an Object Storage bucket for transitional saving artifacts. This method can be used either for small or large artifacts.

Parameters:
  • bucket_uri (str) – The OCI Object Storage URI where model artifacts will be copied to. The bucket_uri is only necessary for downloading large artifacts which size is greater than 2GB. Example: oci://<bucket_name>@<namespace>/prefix/.

  • region ((str, optional). Defaults to None.) – The destination Object Storage bucket region. By default the value will be extracted from the OCI_REGION_METADATA environment variable.

Return type:

None

Raises:

ModelArtifactNotFoundError – If model artifact not found.

is_model_by_reference()[source]

Checks if model is created by reference :rtype: bool flag denoting whether model was created by reference.

model_deployment(config: Dict | None = None, tenant_id: str | None = None, limit: int | None = 500, page: str | None = None, **kwargs: Dict) List[source]

Gets the list of model deployments by model ID across the compartments.

Parameters:
  • model_id (str) – The model ID.

  • config ((Dict, optional). Defaults to None.) – Configuration keys and values as per SDK and Tool Configuration. The from_file() method can be used to load configuration from a file. Alternatively, a dict can be passed. You can validate_config the dict using validate_config(). Defaults to None.

  • tenant_id ((str, optional). Defaults to None.) – The tenancy ID, which can be used to specify a different tenancy (for cross-tenancy authorization) when searching for resources in a different tenancy. Defaults to None.

  • limit ((int, optional). Defaults to None.) – The maximum number of items to return. The value must be between 1 and 1000. Defaults to 500.

  • page ((str, optional). Defaults to None.) – The page at which to start retrieving results.

Return type:

The list of model deployments associated with given model ID.

update() OCIDataScienceModel[source]

Updates datascience Model.

Returns:

The OCIDataScienceModel instance (self).

Return type:

OCIDataScienceModel

update_model_provenance(model_provenance: ModelProvenance) ModelProvenance[source]

Updates model provenance metadata.

Parameters:

model_provenance (oci.data_science.models.ModelProvenance) – OCI model provenance metadata.

Returns:

The OCI model provenance object.

Return type:

oci.data_science.models.ModelProvenance

ads.model.service.oci_datascience_model.check_for_model_id(msg: str = 'Model needs to be saved to the Model Catalog before it can be accessed.')[source]

The decorator helping to check if the ID attribute sepcified for a datascience model.

Parameters:

msg (str) – The message that will be thrown.

Raises:

ModelNotSavedError – In case if the ID attribute not specified.

Examples

>>> @check_for_id(msg="Some message.")
... def test_function(self, name: str, last_name: str)
...     pass

ads.model.service.oci_datascience_model_version_set module

class ads.model.service.oci_datascience_model_version_set.DataScienceModelVersionSet(config: dict | None = None, signer: Signer | None = None, client_kwargs: dict | None = None, **kwargs)[source]

Bases: OCIDataScienceMixin, OCIModelWithNameMixin, OCIWorkRequestMixin, ModelVersionSet

Represents an OCI Data Science Model Version Set This class contains all attributes of the oci.data_science.models.ModelVersionSet The main purpose of this class is to link the oci.data_science.models.ModelVersionSet model and the related client methods. Mainly, linking the ModelVersionSet model (payload) to Create/Update/Get/List/Delete methods.

A DataScienceModelVersionSet can be initialized by unpacking the properties stored in a dictionary (payload):

properties = {
    "name": "experiment1",
    "description": "my experiment"
}
experiment = DataScienceModelVersionSet(**properties)

The properties can also be OCI REST API payload, in which the keys are in camel format.

payload = {
    "Id": "<model_version_set_ocid>",
    "compartmentId": "<compartment_ocid>",
    "Name": "<model_version_set_name>",
}
experiment = DataScienceModelVersionSet(**payload)

Initializes a service/resource with OCI client as a property. If config or signer is specified, it will be used to initialize the OCI client. If neither of them is specified, the client will be initialized with ads.common.auth.default_signer. If both of them are specified, both of them will be passed into the OCI client,

and the authentication will be determined by OCI Python SDK.

Parameters:
  • config (dict, optional) – OCI API key config dictionary, by default None.

  • signer (oci.signer.Signer, optional) – OCI authentication signer, by default None.

  • client_kwargs (dict, optional) – Additional keyword arguments for initializing the OCI client.

create() DataScienceModelVersionSet[source]

Creates model version set on OCI Data Science platform

Returns:

The DataScienceModelVersionSet instance (self), which allows chaining additional method.

Return type:

DataScienceModelVersionSet

delete(delete_model: bool | None = False) DataScienceModelVersionSet[source]

Deletes the model version set.

Parameters:

delete_model ((bool, optional). Defaults to False.) – By default, this parameter is false. A model version set can only be deleted if all the models associate with it are already in the DELETED state. You can optionally specify the deleteRelatedModels boolean query parameters to true, which deletes all associated models for you.

Returns:

The DataScienceModelVersionSet instance (self), which allows chaining additional method.

Return type:

DataScienceModelVersionSet

classmethod from_name(name: str, compartment_id: str | None = None) DataScienceModelVersionSet[source]

Gets a Model Version Set by name.

Parameters:
  • compartment_id ((str, optional). Defaults to None.) – Compartment OCID of the OCI resources. If compartment_id is not specified, the value will be taken from environment variables.

  • name (str) – The name of the model version set.

Returns:

An instance of DataScienceModelVersionSet.

Return type:

DataScienceModelVersionSet

classmethod from_ocid(ocid: str) DataScienceModelVersionSet[source]

Gets a Model Version Set by OCID.

Parameters:

ocid (str) – The OCID of the model version set.

Returns:

An instance of DataScienceModelVersionSet.

Return type:

DataScienceModelVersionSet

update() DataScienceModelVersionSet[source]

Updates the Data Science Model Version Set.

exception ads.model.service.oci_datascience_model_version_set.ModelVersionSetNotExists[source]

Bases: Exception

exception ads.model.service.oci_datascience_model_version_set.ModelVersionSetNotSaved[source]

Bases: Exception

Module contents