ads.model.framework other package
Submodules
ads.model.artifact module
- exception ads.model.artifact.AritfactFolderStructureError(required_files: Tuple[str])
Bases:
Exception
- exception ads.model.artifact.ArtifactNestedFolderError(folder: str)
Bases:
Exception
- exception ads.model.artifact.ArtifactRequiredFilesError(required_files: Tuple[str])
Bases:
Exception
- class ads.model.artifact.ModelArtifact(artifact_dir: str, model_file_name: Optional[str] = None, reload: Optional[bool] = False)
Bases:
object
The class that represents model artifacts. It is designed to help to generate and manage model artifacts.
Initializes a ModelArtifact instance.
- Parameters
artifact_dir (str) – The local artifact folder to store the files needed for deployment.
model_file_name ((str, optional). Defaults to None.) – The file name of the serialized model.
reload ((bool, optional). Defaults to False.) – Determine whether will reload the Model into the env.
- Returns
A ModelArtifact instance.
- Return type
- Raises
ValueError – If artifact_dir not provided.
- classmethod from_uri(uri: str, artifact_dir: str, model_file_name: Optional[str] = None, force_overwrite: Optional[bool] = False, auth: Optional[Dict] = None)
Constructs a ModelArtifact object from the existing model artifacts.
- Parameters
uri (str) – The URI of source artifact folder or achive. Can be local path or OCI object storage URI.
artifact_dir (str) – The local artifact folder to store the files needed for deployment.
model_file_name ((str, optional). Defaults to None) – The file name of the serialized model.
force_overwrite ((bool, optional). Defaults to False.) – Whether to overwrite existing files or not.
auth ((Dict, optional). Defaults to None.) – The default authetication is set using ads.set_auth API. If you need to override the default, use the ads.common.auth.api_keys or ads.common.auth.resource_principal to create appropriate authentication signer and kwargs required to instantiate IdentityClient object.
- Returns
A ModelArtifact instance
- Return type
- Raises
ValueError – If uri is equal to artifact_dir, and it not exists.
- prepare_runtime_yaml(inference_conda_env: str, inference_python_version: Optional[str] = None, training_conda_env: Optional[str] = None, training_python_version: Optional[str] = None, force_overwrite: bool = False, namespace: str = 'id19sfcrra6z', bucketname: str = 'service-conda-packs') None
Generate a runtime yaml file and save it to the artifact directory.
- Parameters
inference_conda_env ((str, optional). Defaults to None.) – The object storage path of conda pack which will be used in deployment. Can be either slug or object storage path of the conda pack. You can only pass in slugs if the conda pack is a service pack.
inference_python_version ((str, optional). Defaults to None.) – The python version which will be used in deployment.
training_conda_env ((str, optional). Defaults to None.) – The object storage path of conda pack used during training. Can be either slug or object storage path of the conda pack. You can only pass in slugs if the conda pack is a service pack.
training_python_version ((str, optional). Defaults to None.) – The python version used during training.
force_overwrite ((bool, optional). Defaults to False.) – Whether to overwrite existing files.
namespace ((str, optional)) – The namespace of region.
bucketname ((str, optional)) – The bucketname of service pack.
- Raises
ValueError – If neither slug or conda_env_uri is provided.
- Returns
A RuntimeInfo instance.
- Return type
- prepare_score_py(jinja_template_filename: str, model_file_name: Optional[str] = None, **kwargs)
Prepares score.py file.
- Parameters
jinja_template_filename (str.) – The jinja template file name.
model_file_name ((str, optional). Defaults to None.) – The file name of the serialized model.
**kwargs ((dict)) – use_torch_script: bool
- Return type
None
- Raises
ValueError – If model_file_name not provided.
- reload()
Syncs the score.py to reload the model and predict function.
- Returns
Nothing
- Return type
None
ads.model.generic_model module
- class ads.model.generic_model.DataScienceModelType
Bases:
str
- MODEL = 'datasciencemodel'
- MODEL_DEPLOYMENT = 'datasciencemodeldeployment'
- class ads.model.generic_model.FrameworkSpecificModel(estimator: Callable, artifact_dir: Optional[str] = None, properties: Optional[ModelProperties] = None, auth: Optional[Dict] = None, serialize: bool = True, **kwargs: dict)
Bases:
GenericModel
GenericModel Constructor.
- Parameters
estimator ((Callable).) – Trained model.
artifact_dir ((str, optional). Defaults to None.) – Artifact directory to store the files needed for deployment.
properties ((ModelProperties, optional). Defaults to None.) – ModelProperties object required to save and deploy model.
auth ((Dict, optional). Defaults to None.) – The default authetication is set using ads.set_auth API. If you need to override the default, use the ads.common.auth.api_keys or ads.common.auth.resource_principal to create appropriate authentication signer and kwargs required to instantiate IdentityClient object.
serialize ((bool, optional). Defaults to True.) – Whether to serialize the model to pkl file by default. If False, you need to serialize the model manually, save it under artifact_dir and update the score.py manually.
- predict(data: Optional[Any] = None, auto_serialize_data: bool = True, **kwargs) Dict[str, Any]
Returns prediction of input data run against the model deployment endpoint.
Examples
>>> uri = "https://github.com/pytorch/hub/raw/master/images/dog.jpg" >>> prediction = model.predict(image=uri)['prediction']
>>> # examples on storage options >>> prediction = model.predict( ... image="oci://<bucket>@<tenancy>/myimage.png", ... storage_options=ads.auth.default_signer() ... )['prediction']
- Parameters
data (Any) – Data for the prediction for onnx models, for local serialization method, data can be the data types that each framework support.
auto_serialize_data (bool.) – Whether to auto serialize input data. Defauls to False for GenericModel, and True for other frameworks. data required to be json serializable if auto_serialize_data=False. If auto_serialize_data set to True, data will be serialized before sending to model deployment endpoint.
kwargs –
content_type: str, used to indicate the media type of the resource. image: PIL.Image Object or uri for the image.
A valid string path for image file can be local path, http(s), oci, s3, gs.
- storage_options: dict
Passed to fsspec.open for a particular storage connection. Please see fsspec (https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.open) for more details.
- Returns
Dictionary with the predicted values.
- Return type
Dict[str, Any]
- Raises
NotActiveDeploymentError – If model deployment process was not started or not finished yet.
ValueError – If data is empty or not JSON serializable.
- verify(data: Optional[Any] = None, reload_artifacts: bool = True, auto_serialize_data: bool = True, **kwargs) Dict[str, Any]
Test if deployment works in local environment.
Examples
>>> uri = "https://github.com/pytorch/hub/raw/master/images/dog.jpg" >>> prediction = model.verify(image=uri)['prediction']
>>> # examples on storage options >>> prediction = model.verify( ... image="oci://<bucket>@<tenancy>/myimage.png", ... storage_options=ads.auth.default_signer() ... )['prediction']
- Parameters
data (Any) – Data used to test if deployment works in local environment.
reload_artifacts (bool. Defaults to True.) – Whether to reload artifacts or not.
auto_serialize_data (bool.) – Whether to auto serialize input data. Defauls to False for GenericModel, and True for other frameworks. data required to be json serializable if auto_serialize_data=False. if auto_serialize_data set to True, data will be serialized before sending to model deployment endpoint.
kwargs –
content_type: str, used to indicate the media type of the resource. image: PIL.Image Object or uri for the image.
A valid string path for image file can be local path, http(s), oci, s3, gs.
- storage_options: dict
Passed to fsspec.open for a particular storage connection. Please see fsspec (https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.open) for more details.
- Returns
A dictionary which contains prediction results.
- Return type
Dict
- class ads.model.generic_model.GenericModel(estimator: Callable, artifact_dir: Optional[str] = None, properties: Optional[ModelProperties] = None, auth: Optional[Dict] = None, serialize: bool = True, **kwargs: dict)
Bases:
MetadataMixin
,Introspectable
Generic Model class which is the base class for all the frameworks including the unsupported frameworks.
- algorithm
The algorithm of the model.
- Type
str
- artifact_dir
Artifact directory to store the files needed for deployment.
- Type
str
- auth
Default authentication is set using the ads.set_auth API. To override the default, use the ads.common.auth.api_keys or ads.common.auth.resource_principal to create an authentication signer to instantiate an IdentityClient object.
- Type
Dict
- estimator
Any model object generated by sklearn framework
- Type
Callable
- framework
The framework of the model.
- Type
str
- hyperparameter
The hyperparameters of the estimator.
- Type
dict
- metadata_custom
The model custom metadata.
- Type
ModelCustomMetadata
- metadata_provenance
The model provenance metadata.
- Type
ModelProvenanceMetadata
- metadata_taxonomy
The model taxonomy metadata.
- Type
ModelTaxonomyMetadata
- model_artifact
This is built by calling prepare.
- Type
- model_deployment
A ModelDeployment instance.
- Type
- model_file_name
Name of the serialized model.
- Type
str
- model_id
The model ID.
- Type
str
- properties
ModelProperties object required to save and deploy model.
- Type
- runtime_info
A RuntimeInfo instance.
- Type
- schema_input
Schema describes the structure of the input data.
- Type
Schema
- schema_output
Schema describes the structure of the output data.
- Type
Schema
- serialize
Whether to serialize the model to pkl file by default. If False, you need to serialize the model manually, save it under artifact_dir and update the score.py manually.
- Type
bool
- version
The framework version of the model.
- Type
str
- delete_deployment(...)
Deletes the current model deployment.
- deploy(..., \*\*kwargs)
Deploys a model.
- from_model_artifact(uri, ..., \*\*kwargs)
Loads model from the specified folder, or zip/tar archive.
- from_model_catalog(model_id, ..., \*\*kwargs)
Loads model from model catalog.
- from_model_deployment(model_deployment_id, ..., \*\*kwargs)
Loads model from model deployment.
- update_deployment(model_deployment_id, ..., \*\*kwargs)
Updates a model deployment.
- from_id(ocid, ..., \*\*kwargs)
Loads model from model OCID or model deployment OCID.
- introspect(...)
Runs model introspection.
- predict(data, ...)
Returns prediction of input data run against the model deployment endpoint.
- prepare(..., \*\*kwargs)
Prepare and save the score.py, serialized model and runtime.yaml file.
- prepare_save_deploy(..., \*\*kwargs)
Shortcut for prepare, save and deploy steps.
- reload(...)
Reloads the model artifact files: score.py and the runtime.yaml.
- save(..., \*\*kwargs)
Saves model artifacts to the model catalog.
- summary_status(...)
Gets a summary table of the current status.
- verify(data, ...)
Tests if deployment works in local environment.
- upload_artifact(...)
Uploads model artifacts to the provided uri.
Examples
>>> import tempfile >>> from ads.model.generic_model import GenericModel
>>> class Toy: ... def predict(self, x): ... return x ** 2 >>> estimator = Toy()
>>> model = GenericModel(estimator=estimator, artifact_dir=tempfile.mkdtemp()) >>> model.summary_status() >>> model.prepare( ... inference_conda_env="dataexpl_p37_cpu_v3", ... inference_python_version="3.7", ... model_file_name="toy_model.pkl", ... training_id=None, ... force_overwrite=True ... ) >>> model.verify(2) >>> model.save() >>> model.deploy() >>> # Update access log id, freeform tags and description for the model deployment >>> model.update_deployment( >>> properties=ModelDeploymentProperties( >>> access_log_id=<log_ocid>, >>> description="Description for Custom Model", >>> freeform_tags={"key": "value"}, >>> ) >>> ) >>> model.predict(2) >>> # Uncomment the line below to delete the model and the associated model deployment >>> # model.delete(delete_associated_model_deployment = True)
GenericModel Constructor.
- Parameters
estimator ((Callable).) – Trained model.
artifact_dir ((str, optional). Defaults to None.) – Artifact directory to store the files needed for deployment.
properties ((ModelProperties, optional). Defaults to None.) – ModelProperties object required to save and deploy model.
auth ((Dict, optional). Defaults to None.) – The default authetication is set using ads.set_auth API. If you need to override the default, use the ads.common.auth.api_keys or ads.common.auth.resource_principal to create appropriate authentication signer and kwargs required to instantiate IdentityClient object.
serialize ((bool, optional). Defaults to True.) – Whether to serialize the model to pkl file by default. If False, you need to serialize the model manually, save it under artifact_dir and update the score.py manually.
- classmethod delete(model_id: Optional[str] = None, delete_associated_model_deployment: Optional[bool] = False, delete_model_artifact: Optional[bool] = False, artifact_dir: Optional[str] = None, **kwargs: Dict) None
Deletes a model from Model Catalog.
- Parameters
model_id ((str, optional). Defaults to None.) – The model OCID to be deleted. If the method called on instance level, then self.model_id will be used.
delete_associated_model_deployment ((bool, optional). Defaults to False.) – Whether associated model deployments need to be deleted or not.
delete_model_artifact ((bool, optional). Defaults to False.) – Whether associated model artifacts need to be deleted or not.
artifact_dir ((str, optional). Defaults to None) – The local path to the model artifacts folder. If the method called on instance level, the self.artifact_dir will be used by default.
- Return type
None
- Raises
ValueError – If model_id not provided.
- delete_deployment(wait_for_completion: bool = True) None
Deletes the current deployment.
- Parameters
wait_for_completion ((bool, optional). Defaults to True.) – Whether to wait till completion.
- Return type
None
- Raises
ValueError – if there is not deployment attached yet.:
- deploy(wait_for_completion: Optional[bool] = True, display_name: Optional[str] = None, description: Optional[str] = None, deployment_instance_shape: Optional[str] = None, deployment_instance_count: Optional[int] = None, deployment_bandwidth_mbps: Optional[int] = None, deployment_log_group_id: Optional[str] = None, deployment_access_log_id: Optional[str] = None, deployment_predict_log_id: Optional[str] = None, deployment_memory_in_gbs: Optional[float] = None, deployment_ocpus: Optional[float] = None, **kwargs: Dict) ModelDeployment
Deploys a model. The model needs to be saved to the model catalog at first.
- Parameters
wait_for_completion ((bool, optional). Defaults to True.) – Flag set for whether to wait for deployment to complete before proceeding.
display_name ((str, optional). Defaults to None.) – The name of the model. If a display_name is not provided in kwargs, a randomly generated easy to remember name with timestamp will be generated, like ‘strange-spider-2022-08-17-23:55.02’.
description ((str, optional). Defaults to None.) – The description of the model.
deployment_instance_shape ((str, optional). Default to VM.Standard2.1.) – The shape of the instance used for deployment.
deployment_instance_count ((int, optional). Defaults to 1.) – The number of instance used for deployment.
deployment_bandwidth_mbps ((int, optional). Defaults to 10.) – The bandwidth limit on the load balancer in Mbps.
deployment_memory_in_gbs ((float, optional). Defaults to None.) – Specifies the size of the memory of the model deployment instance in GBs.
deployment_ocpus ((float, optional). Defaults to None.) – Specifies the ocpus count of the model deployment instance.
deployment_log_group_id ((str, optional). Defaults to None.) – The oci logging group id. The access log and predict log share the same log group.
deployment_access_log_id ((str, optional). Defaults to None.) – The access log OCID for the access logs. https://docs.oracle.com/en-us/iaas/data-science/using/model_dep_using_logging.htm
deployment_predict_log_id ((str, optional). Defaults to None.) – The predict log OCID for the predict logs. https://docs.oracle.com/en-us/iaas/data-science/using/model_dep_using_logging.htm
kwargs –
- project_id: (str, optional).
Project OCID. If not specified, the value will be taken from the environment variables.
- compartment_id(str, optional).
Compartment OCID. If not specified, the value will be taken from the environment variables.
- max_wait_time(int, optional). Defaults to 1200 seconds.
Maximum amount of time to wait in seconds. Negative implies infinite wait time.
- poll_interval(int, optional). Defaults to 60 seconds.
Poll interval in seconds.
- freeform_tags: (Dict[str, str], optional). Defaults to None.
Freeform tags of the model deployment.
- defined_tags: (Dict[str, dict[str, object]], optional). Defaults to None.
Defined tags of the model deployment.
Also can be any keyword argument for initializing the ads.model.deployment.ModelDeploymentProperties. See ads.model.deployment.ModelDeploymentProperties() for details.
- Returns
The ModelDeployment instance.
- Return type
- Raises
ValueError – If model_id is not specified.
- classmethod from_id(ocid: str, model_file_name: Optional[str] = None, artifact_dir: Optional[str] = None, auth: Optional[Dict] = None, force_overwrite: Optional[bool] = False, properties: Optional[Union[ModelProperties, Dict]] = None, bucket_uri: Optional[str] = None, remove_existing_artifact: Optional[bool] = True, **kwargs) GenericModel
Loads model from model OCID or model deployment OCID.
- Parameters
ocid (str) – The model OCID or model deployment OCID.
model_file_name ((str, optional). Defaults to None.) – The name of the serialized model.
artifact_dir ((str, optional). Defaults to None.) – The artifact directory to store the files needed for deployment. Will be created if not exists.
auth ((Dict, optional). Defaults to None.) – The default authetication is set using ads.set_auth API. If you need to override the default, use the ads.common.auth.api_keys or ads.common.auth.resource_principal to create appropriate authentication signer and kwargs required to instantiate IdentityClient object.
force_overwrite ((bool, optional). Defaults to False.) – Whether to overwrite existing files or not.
properties ((ModelProperties, optional). Defaults to None.) – ModelProperties object required to save and deploy model.
bucket_uri ((str, optional). Defaults to None.) – The OCI Object Storage URI where model artifacts will be copied to. The bucket_uri is only necessary for downloading large artifacts with size is greater than 2GB. Example: oci://<bucket_name>@<namespace>/prefix/.
remove_existing_artifact ((bool, optional). Defaults to True.) – Wether artifacts uploaded to object storage bucket need to be removed or not.
kwargs –
- compartment_id(str, optional)
Compartment OCID. If not specified, the value will be taken from the environment variables.
- timeout(int, optional). Defaults to 10 seconds.
The connection timeout in seconds for the client.
- Returns
An instance of GenericModel class.
- Return type
- classmethod from_model_artifact(uri: str, model_file_name: Optional[str] = None, artifact_dir: Optional[str] = None, auth: Optional[Dict] = None, force_overwrite: Optional[bool] = False, properties: Optional[ModelProperties] = None, **kwargs: dict) GenericModel
Loads model from a folder, or zip/tar archive.
- Parameters
uri (str) – The folder path, ZIP file path, or TAR file path. It could contain a seriliazed model(required) as well as any files needed for deployment including: serialized model, runtime.yaml, score.py and etc. The content of the folder will be copied to the artifact_dir folder.
model_file_name ((str, optional). Defaults to None.) – The serialized model file name. Will be extracted from artifacts if not provided.
artifact_dir ((str, optional). Defaults to None.) – The artifact directory to store the files needed for deployment. Will be created if not exists.
auth ((Dict, optional). Defaults to None.) – The default authetication is set using ads.set_auth API. If you need to override the default, use the ads.common.auth.api_keys or ads.common.auth.resource_principal to create appropriate authentication signer and kwargs required to instantiate IdentityClient object.
force_overwrite ((bool, optional). Defaults to False.) – Whether to overwrite existing files or not.
properties ((ModelProperties, optional). Defaults to None.) – ModelProperties object required to save and deploy model.
- Returns
An instance of GenericModel class.
- Return type
- Raises
ValueError – If model_file_name not provided.
- classmethod from_model_catalog(model_id: str, model_file_name: Optional[str] = None, artifact_dir: Optional[str] = None, auth: Optional[Dict] = None, force_overwrite: Optional[bool] = False, properties: Optional[Union[ModelProperties, Dict]] = None, bucket_uri: Optional[str] = None, remove_existing_artifact: Optional[bool] = True, **kwargs) GenericModel
Loads model from model catalog.
- Parameters
model_id (str) – The model OCID.
model_file_name ((str, optional). Defaults to None.) – The name of the serialized model.
artifact_dir ((str, optional). Defaults to None.) – The artifact directory to store the files needed for deployment. Will be created if not exists.
auth ((Dict, optional). Defaults to None.) – The default authetication is set using ads.set_auth API. If you need to override the default, use the ads.common.auth.api_keys or ads.common.auth.resource_principal to create appropriate authentication signer and kwargs required to instantiate IdentityClient object.
force_overwrite ((bool, optional). Defaults to False.) – Whether to overwrite existing files or not.
properties ((ModelProperties, optional). Defaults to None.) – ModelProperties object required to save and deploy model.
bucket_uri ((str, optional). Defaults to None.) – The OCI Object Storage URI where model artifacts will be copied to. The bucket_uri is only necessary for downloading large artifacts with size is greater than 2GB. Example: oci://<bucket_name>@<namespace>/prefix/.
remove_existing_artifact ((bool, optional). Defaults to True.) – Wether artifacts uploaded to object storage bucket need to be removed or not.
kwargs –
- compartment_id(str, optional)
Compartment OCID. If not specified, the value will be taken from the environment variables.
- timeout(int, optional). Defaults to 10 seconds.
The connection timeout in seconds for the client.
- 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.
- Returns
An instance of GenericModel class.
- Return type
- classmethod from_model_deployment(model_deployment_id: str, model_file_name: Optional[str] = None, artifact_dir: Optional[str] = None, auth: Optional[Dict] = None, force_overwrite: Optional[bool] = False, properties: Optional[Union[ModelProperties, Dict]] = None, bucket_uri: Optional[str] = None, remove_existing_artifact: Optional[bool] = True, **kwargs) GenericModel
Loads model from model deployment.
- Parameters
model_deployment_id (str) – The model deployment OCID.
model_file_name ((str, optional). Defaults to None.) – The name of the serialized model.
artifact_dir ((str, optional). Defaults to None.) – The artifact directory to store the files needed for deployment. Will be created if not exists.
auth ((Dict, optional). Defaults to None.) – The default authetication is set using ads.set_auth API. If you need to override the default, use the ads.common.auth.api_keys or ads.common.auth.resource_principal to create appropriate authentication signer and kwargs required to instantiate IdentityClient object.
force_overwrite ((bool, optional). Defaults to False.) – Whether to overwrite existing files or not.
properties ((ModelProperties, optional). Defaults to None.) – ModelProperties object required to save and deploy model.
bucket_uri ((str, optional). Defaults to None.) – The OCI Object Storage URI where model artifacts will be copied to. The bucket_uri is only necessary for downloading large artifacts with size is greater than 2GB. Example: oci://<bucket_name>@<namespace>/prefix/.
remove_existing_artifact ((bool, optional). Defaults to True.) – Wether artifacts uploaded to object storage bucket need to be removed or not.
kwargs –
- compartment_id(str, optional)
Compartment OCID. If not specified, the value will be taken from the environment variables.
- timeout(int, optional). Defaults to 10 seconds.
The connection timeout in seconds for the client.
- 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.
- Returns
An instance of GenericModel class.
- Return type
- get_data_serializer(data: any, data_type: Optional[str] = None)
The data_serializer_class class is set in
init
and used here. Frameworks should subclass the InputDataSerializer class, then set that as theself.data_serializer_class
. Frameworks should avoid overwriting this method whenever possible.- Parameters
data ((Any)) – data to be passed to model for prediction.
data_type (str) – Type of the data.
- Returns
Serialized data.
- Return type
data
- introspect() DataFrame
Conducts instrospection.
- Returns
A pandas DataFrame which contains the instrospection results.
- Return type
pandas.DataFrame
- property metadata_custom
- property metadata_provenance
- property metadata_taxonomy
- property model_deployment_id
- property model_id
- predict(data: Optional[Any] = None, auto_serialize_data: bool = False, **kwargs) Dict[str, Any]
Returns prediction of input data run against the model deployment endpoint.
Examples
>>> uri = "https://github.com/pytorch/hub/raw/master/images/dog.jpg" >>> prediction = model.predict(image=uri)['prediction']
>>> # examples on storage options >>> prediction = model.predict( ... image="oci://<bucket>@<tenancy>/myimage.png", ... storage_options=ads.auth.default_signer() ... )['prediction']
- Parameters
data (Any) – Data for the prediction for onnx models, for local serialization method, data can be the data types that each framework support.
auto_serialize_data (bool.) – Whether to auto serialize input data. Defauls to False for GenericModel, and True for other frameworks. data required to be json serializable if auto_serialize_data=False. If auto_serialize_data set to True, data will be serialized before sending to model deployment endpoint.
kwargs –
content_type: str, used to indicate the media type of the resource. image: PIL.Image Object or uri for the image.
A valid string path for image file can be local path, http(s), oci, s3, gs.
- storage_options: dict
Passed to fsspec.open for a particular storage connection. Please see fsspec (https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.open) for more details.
- Returns
Dictionary with the predicted values.
- Return type
Dict[str, Any]
- Raises
NotActiveDeploymentError – If model deployment process was not started or not finished yet.
ValueError – If data is empty or not JSON serializable.
- prepare(inference_conda_env: Optional[str] = None, inference_python_version: Optional[str] = None, training_conda_env: Optional[str] = None, training_python_version: Optional[str] = None, model_file_name: Optional[str] = None, as_onnx: bool = False, initial_types: Optional[List[Tuple]] = None, force_overwrite: bool = False, namespace: str = 'id19sfcrra6z', use_case_type: Optional[str] = None, X_sample: Optional[Union[list, tuple, DataFrame, Series, ndarray]] = None, y_sample: Optional[Union[list, tuple, DataFrame, Series, ndarray]] = None, training_script_path: Optional[str] = None, training_id: Optional[str] = None, ignore_pending_changes: bool = True, max_col_num: int = 2000, **kwargs: Dict) GenericModel
Prepare and save the score.py, serialized model and runtime.yaml file.
- Parameters
inference_conda_env ((str, optional). Defaults to None.) – Can be either slug or object storage path of the conda pack. You can only pass in slugs if the conda pack is a service pack.
inference_python_version ((str, optional). Defaults to None.) – Python version which will be used in deployment.
training_conda_env ((str, optional). Defaults to None.) – Can be either slug or object storage path of the conda pack. You can only pass in slugs if the conda pack is a service pack. If training_conda_env is not provided, training_conda_env will use the same value of training_conda_env.
training_python_version ((str, optional). Defaults to None.) – Python version used during training.
model_file_name ((str, optional). Defaults to None.) – Name of the serialized model. Will be auto generated if not provided.
as_onnx ((bool, optional). Defaults to False.) – Whether to serialize as onnx model.
initial_types ((list[Tuple], optional).) – Defaults to None. Only used for SklearnModel, LightGBMModel and XGBoostModel. Each element is a tuple of a variable name and a type. Check this link http://onnx.ai/sklearn-onnx/api_summary.html#id2 for more explanation and examples for initial_types.
force_overwrite ((bool, optional). Defaults to False.) – Whether to overwrite existing files.
namespace ((str, optional).) – Namespace of region. This is used for identifying which region the service pack is from when you pass a slug to inference_conda_env and training_conda_env.
use_case_type (str) – The use case type of the model. Use it through UserCaseType class or string provided in UseCaseType. For example, use_case_type=UseCaseType.BINARY_CLASSIFICATION or use_case_type=”binary_classification”. Check with UseCaseType class to see all supported types.
X_sample (Union[list, tuple, pd.Series, np.ndarray, pd.DataFrame]. Defaults to None.) – A sample of input data that will be used to generate input schema.
y_sample (Union[list, tuple, pd.Series, np.ndarray, pd.DataFrame]. Defaults to None.) – A sample of output data that will be used to generate output schema.
training_script_path (str. Defaults to None.) – Training script path.
training_id ((str, optional). Defaults to value from environment variables.) – The training OCID for model. Can be notebook session or job OCID.
ignore_pending_changes (bool. Defaults to False.) – whether to ignore the pending changes in the git.
max_col_num ((int, optional). Defaults to utils.DATA_SCHEMA_MAX_COL_NUM.) – Do not generate the input schema if the input has more than this number of features(columns).
kwargs –
- impute_values: (dict, optional).
The dictionary where the key is the column index(or names is accepted for pandas dataframe) and the value is the impute value for the corresponding column.
- Raises
FileExistsError – If files already exist but force_overwrite is False.
ValueError – If inference_python_version is not provided, but also cannot be found through manifest file.
- Returns
An instance of GenericModel class.
- Return type
- prepare_save_deploy(inference_conda_env: Optional[str] = None, inference_python_version: Optional[str] = None, training_conda_env: Optional[str] = None, training_python_version: Optional[str] = None, model_file_name: Optional[str] = None, as_onnx: bool = False, initial_types: Optional[List[Tuple]] = None, force_overwrite: bool = False, namespace: str = 'id19sfcrra6z', use_case_type: Optional[str] = None, X_sample: Optional[Union[list, tuple, DataFrame, Series, ndarray]] = None, y_sample: Optional[Union[list, tuple, DataFrame, Series, ndarray]] = None, training_script_path: Optional[str] = None, training_id: Optional[str] = None, ignore_pending_changes: bool = True, max_col_num: int = 2000, model_display_name: Optional[str] = None, model_description: Optional[str] = None, model_freeform_tags: Optional[dict] = None, model_defined_tags: Optional[dict] = None, ignore_introspection: Optional[bool] = False, wait_for_completion: Optional[bool] = True, deployment_display_name: Optional[str] = None, deployment_description: Optional[str] = None, deployment_instance_shape: Optional[str] = None, deployment_instance_count: Optional[int] = None, deployment_bandwidth_mbps: Optional[int] = None, deployment_log_group_id: Optional[str] = None, deployment_access_log_id: Optional[str] = None, deployment_predict_log_id: Optional[str] = None, deployment_memory_in_gbs: Optional[float] = None, deployment_ocpus: Optional[float] = None, bucket_uri: Optional[str] = None, overwrite_existing_artifact: Optional[bool] = True, remove_existing_artifact: Optional[bool] = True, **kwargs: Dict) ModelDeployment
Shortcut for prepare, save and deploy steps.
- Parameters
inference_conda_env ((str, optional). Defaults to None.) – Can be either slug or object storage path of the conda pack. You can only pass in slugs if the conda pack is a service pack.
inference_python_version ((str, optional). Defaults to None.) – Python version which will be used in deployment.
training_conda_env ((str, optional). Defaults to None.) – Can be either slug or object storage path of the conda pack. You can only pass in slugs if the conda pack is a service pack. If training_conda_env is not provided, training_conda_env will use the same value of training_conda_env.
training_python_version ((str, optional). Defaults to None.) – Python version used during training.
model_file_name ((str, optional). Defaults to None.) – Name of the serialized model.
as_onnx ((bool, optional). Defaults to False.) – Whether to serialize as onnx model.
initial_types ((list[Tuple], optional).) – Defaults to None. Only used for SklearnModel, LightGBMModel and XGBoostModel. Each element is a tuple of a variable name and a type. Check this link http://onnx.ai/sklearn-onnx/api_summary.html#id2 for more explanation and examples for initial_types.
force_overwrite ((bool, optional). Defaults to False.) – Whether to overwrite existing files.
namespace ((str, optional).) – Namespace of region. This is used for identifying which region the service pack is from when you pass a slug to inference_conda_env and training_conda_env.
use_case_type (str) – The use case type of the model. Use it through UserCaseType class or string provided in UseCaseType. For example, use_case_type=UseCaseType.BINARY_CLASSIFICATION or use_case_type=”binary_classification”. Check with UseCaseType class to see all supported types.
X_sample (Union[list, tuple, pd.Series, np.ndarray, pd.DataFrame]. Defaults to None.) – A sample of input data that will be used to generate input schema.
y_sample (Union[list, tuple, pd.Series, np.ndarray, pd.DataFrame]. Defaults to None.) – A sample of output data that will be used to generate output schema.
training_script_path (str. Defaults to None.) – Training script path.
training_id ((str, optional). Defaults to value from environment variables.) – The training OCID for model. Can be notebook session or job OCID.
ignore_pending_changes (bool. Defaults to False.) – whether to ignore the pending changes in the git.
max_col_num ((int, optional). Defaults to utils.DATA_SCHEMA_MAX_COL_NUM.) – Do not generate the input schema if the input has more than this number of features(columns).
model_display_name ((str, optional). Defaults to None.) – The name of the model. If a model_display_name is not provided in kwargs, a randomly generated easy to remember name with timestamp will be generated, like ‘strange-spider-2022-08-17-23:55.02’.
model_description ((str, optional). Defaults to None.) – The description of the model.
model_freeform_tags (Dict(str, str), Defaults to None.) – Freeform tags for the model.
model_defined_tags ((Dict(str, dict(str, object)), optional). Defaults to None.) – Defined tags for the model.
ignore_introspection ((bool, optional). Defaults to None.) – Determine whether to ignore the result of model introspection or not. If set to True, the save will ignore all model introspection errors.
wait_for_completion ((bool, optional). Defaults to True.) – Flag set for whether to wait for deployment to complete before proceeding.
deployment_display_name ((str, optional). Defaults to None.) – The name of the model deployment. If a deployment_display_name is not provided in kwargs, a randomly generated easy to remember name with timestamp will be generated, like ‘strange-spider-2022-08-17-23:55.02’.
description ((str, optional). Defaults to None.) – The description of the model.
deployment_instance_shape ((str, optional). Default to VM.Standard2.1.) – The shape of the instance used for deployment.
deployment_instance_count ((int, optional). Defaults to 1.) – The number of instance used for deployment.
deployment_bandwidth_mbps ((int, optional). Defaults to 10.) – The bandwidth limit on the load balancer in Mbps.
deployment_log_group_id ((str, optional). Defaults to None.) – The oci logging group id. The access log and predict log share the same log group.
deployment_access_log_id ((str, optional). Defaults to None.) – The access log OCID for the access logs. https://docs.oracle.com/en-us/iaas/data-science/using/model_dep_using_logging.htm
deployment_predict_log_id ((str, optional). Defaults to None.) – The predict log OCID for the predict logs. https://docs.oracle.com/en-us/iaas/data-science/using/model_dep_using_logging.htm
deployment_memory_in_gbs ((float, optional). Defaults to None.) – Specifies the size of the memory of the model deployment instance in GBs.
deployment_ocpus ((float, optional). Defaults to None.) – Specifies the ocpus count of the model deployment instance.
bucket_uri ((str, optional). Defaults to None.) – The OCI Object Storage URI where model artifacts will be copied to. The bucket_uri is only necessary for downloading large artifacts with size is greater than 2GB. Example: oci://<bucket_name>@<namespace>/prefix/.
overwrite_existing_artifact ((bool, optional). Defaults to True.) – Overwrite target bucket artifact if exists.
remove_existing_artifact ((bool, optional). Defaults to True.) – Wether artifacts uploaded to object storage bucket need to be removed or not.
kwargs –
- impute_values: (dict, optional).
The dictionary where the key is the column index(or names is accepted for pandas dataframe) and the value is the impute value for the corresponding column.
- project_id: (str, optional).
Project OCID. If not specified, the value will be taken either from the environment variables or model properties.
- compartment_id(str, optional).
Compartment OCID. If not specified, the value will be taken either from the environment variables or model properties.
- timeout: (int, optional). Defaults to 10 seconds.
The connection timeout in seconds for the client.
- max_wait_time(int, optional). Defaults to 1200 seconds.
Maximum amount of time to wait in seconds. Negative implies infinite wait time.
- poll_interval(int, optional). Defaults to 60 seconds.
Poll interval in seconds.
- freeform_tags: (Dict[str, str], optional). Defaults to None.
Freeform tags of the model deployment.
- defined_tags: (Dict[str, dict[str, object]], optional). Defaults to None.
Defined tags of the model deployment.
- 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.
Also can be any keyword argument for initializing the ads.model.deployment.ModelDeploymentProperties. See ads.model.deployment.ModelDeploymentProperties() for details.
- Returns
The ModelDeployment instance.
- Return type
- Raises
FileExistsError – If files already exist but force_overwrite is False.
ValueError – If inference_python_version is not provided, but also cannot be found through manifest file.
- reload() GenericModel
Reloads the model artifact files: score.py and the runtime.yaml.
- Returns
An instance of GenericModel class.
- Return type
- reload_runtime_info() None
Reloads the model artifact file: runtime.yaml.
- Returns
Nothing.
- Return type
None
- save(display_name: Optional[str] = None, description: Optional[str] = None, freeform_tags: Optional[dict] = None, defined_tags: Optional[dict] = None, ignore_introspection: Optional[bool] = False, bucket_uri: Optional[str] = None, overwrite_existing_artifact: Optional[bool] = True, remove_existing_artifact: Optional[bool] = True, **kwargs) str
Saves model artifacts to the model catalog.
- Parameters
display_name ((str, optional). Defaults to None.) – The name of the model. If a display_name is not provided in kwargs, randomly generated easy to remember name with timestamp will be generated, like ‘strange-spider-2022-08-17-23:55.02’.
description ((str, optional). Defaults to None.) – The description of the model.
freeform_tags (Dict(str, str), Defaults to None.) – Freeform tags for the model.
defined_tags ((Dict(str, dict(str, object)), optional). Defaults to None.) – Defined tags for the model.
ignore_introspection ((bool, optional). Defaults to None.) – Determine whether to ignore the result of model introspection or not. If set to True, the save will ignore all model introspection errors.
bucket_uri ((str, optional). Defaults to None.) – The OCI Object Storage URI where model artifacts will be copied to. The bucket_uri is only necessary for uploading large artifacts which size is greater than 2GB. Example: oci://<bucket_name>@<namespace>/prefix/.
overwrite_existing_artifact ((bool, optional). Defaults to True.) – Overwrite target bucket artifact if exists.
remove_existing_artifact ((bool, optional). Defaults to True.) – Wether artifacts uploaded to object storage bucket need to be removed or not.
kwargs –
- project_id: (str, optional).
Project OCID. If not specified, the value will be taken either from the environment variables or model properties.
- compartment_id(str, optional).
Compartment OCID. If not specified, the value will be taken either from the environment variables or model properties.
- 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.
Also can be any attribute that oci.data_science.models.Model accepts.
- Raises
RuntimeInfoInconsistencyError – When .runtime_info is not synched with runtime.yaml file.
- Returns
The model id.
- Return type
str
- property schema_input
- property schema_output
- serialize_model(as_onnx: bool = False, initial_types: Optional[List[Tuple]] = None, force_overwrite: bool = False, X_sample: Optional[any] = None)
Serialize and save model using ONNX or model specific method.
- Parameters
as_onnx ((boolean, optional)) – If set as True, convert into ONNX model.
initial_types ((List[Tuple], optional)) – a python list. Each element is a tuple of a variable name and a data type.
force_overwrite ((boolean, optional)) – If set as True, overwrite serialized model if exists.
X_sample ((any, optional). Defaults to None.) – Contains model inputs such that model(X_sample) is a valid invocation of the model, used to valid model input type.
- Returns
Nothing
- Return type
None
- summary_status() DataFrame
A summary table of the current status.
- Returns
The summary stable of the current status.
- Return type
pd.DataFrame
- update(**kwargs) GenericModel
Updates model metadata in the Model Catalog. Updates only metadata information. The model artifacts are immutable and cannot be updated.
- Parameters
kwargs –
- display_name: (str, optional). Defaults to None.
The name of the model.
- description: (str, optional). Defaults to None.
The description of the model.
- freeform_tagsDict(str, str), Defaults to None.
Freeform tags for the model.
- defined_tags(Dict(str, dict(str, object)), optional). Defaults to None.
Defined tags for the model.
Additional kwargs arguments. Can be any attribute that oci.data_science.models.Model accepts.
- Returns
An instance of GenericModel (self).
- Return type
- Raises
ValueError – if model not saved to the Model Catalog.
- classmethod update_deployment(model_deployment_id: Optional[str] = None, properties: Optional[Union[ModelDeploymentProperties, dict]] = None, wait_for_completion: bool = True, max_wait_time: int = 1200, poll_interval: int = 30, **kwargs) ModelDeployment
Updates a model deployment.
You can update model_deployment_configuration_details and change instance_shape and model_id when the model deployment is in the ACTIVE lifecycle state. The bandwidth_mbps or instance_count can only be updated while the model deployment is in the INACTIVE state. Changes to the bandwidth_mbps or instance_count will take effect the next time the ActivateModelDeployment action is invoked on the model deployment resource.
Examples
>>> # Update access log id, freeform tags and description for the model deployment >>> model.update_deployment( >>> properties=ModelDeploymentProperties( >>> access_log_id=<log_ocid>, >>> description="Description for Custom Model", >>> freeform_tags={"key": "value"}, >>> ) >>> )
- Parameters
model_deployment_id (str.) – The model deployment OCID. Defaults to None. If the method called on instance level, then self.model_deployment.model_deployment_id will be used.
properties (ModelDeploymentProperties or dict) – The properties for updating the deployment.
wait_for_completion (bool) – Flag set for whether to wait for deployment to complete before proceeding. Defaults to True.
max_wait_time (int) – Maximum amount of time to wait in seconds (Defaults to 1200). Negative implies infinite wait time.
poll_interval (int) – Poll interval in seconds (Defaults to 60).
kwargs –
- auth: (Dict, optional). Defaults to None.
The default authetication is set using ads.set_auth API. If you need to override the default, use the ads.common.auth.api_keys or ads.common.auth.resource_principal to create appropriate authentication signer and kwargs required to instantiate IdentityClient object.
- Returns
An instance of ModelDeployment class.
- Return type
- upload_artifact(uri: str, auth: Optional[Dict] = None, force_overwrite: Optional[bool] = False) None
Uploads model artifacts to the provided uri. The artifacts will be zipped before uploading.
- Parameters
uri (str) – The destination location for the model artifacts, which can be a local path or OCI object storage URI. Examples: >>> upload_artifact(uri=”/some/local/folder/”) >>> upload_artifact(uri=”oci://bucket@namespace/prefix/”)
auth ((Dict, optional). Defaults to None.) – The default authetication is set using ads.set_auth API. If you need to override the default, use the ads.common.auth.api_keys or ads.common.auth.resource_principal to create appropriate authentication signer and kwargs required to instantiate IdentityClient object.
force_overwrite (bool) – Overwrite target_dir if exists.
- verify(data: Optional[Any] = None, reload_artifacts: bool = True, auto_serialize_data: bool = False, **kwargs) Dict[str, Any]
Test if deployment works in local environment.
Examples
>>> uri = "https://github.com/pytorch/hub/raw/master/images/dog.jpg" >>> prediction = model.verify(image=uri)['prediction']
>>> # examples on storage options >>> prediction = model.verify( ... image="oci://<bucket>@<tenancy>/myimage.png", ... storage_options=ads.auth.default_signer() ... )['prediction']
- Parameters
data (Any) – Data used to test if deployment works in local environment.
reload_artifacts (bool. Defaults to True.) – Whether to reload artifacts or not.
auto_serialize_data (bool.) – Whether to auto serialize input data. Defauls to False for GenericModel, and True for other frameworks. data required to be json serializable if auto_serialize_data=False. if auto_serialize_data set to True, data will be serialized before sending to model deployment endpoint.
kwargs –
content_type: str, used to indicate the media type of the resource. image: PIL.Image Object or uri for the image.
A valid string path for image file can be local path, http(s), oci, s3, gs.
- storage_options: dict
Passed to fsspec.open for a particular storage connection. Please see fsspec (https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.open) for more details.
- Returns
A dictionary which contains prediction results.
- Return type
Dict
- class ads.model.generic_model.ModelState(value)
Bases:
Enum
An enumeration.
- AVAILABLE = 'Available'
- DONE = 'Done'
- NEEDSACTION = 'Needs Action'
- NOTAVAILABLE = 'Not Available'
- exception ads.model.generic_model.NotActiveDeploymentError(state: str)
Bases:
Exception
- exception ads.model.generic_model.RuntimeInfoInconsistencyError
Bases:
Exception
- exception ads.model.generic_model.SerializeInputNotImplementedError
Bases:
NotImplementedError
- exception ads.model.generic_model.SerializeModelNotImplementedError
Bases:
NotImplementedError
- class ads.model.generic_model.SummaryStatus
Bases:
object
SummaryStatus class which track the status of the Model frameworks.
- update_action(detail: str, action: str) None
Updates the action of the summary status table of the corresponding detail.
- Parameters
detail ((str)) – Value of the detail in the Details column. Used to locate which row to update.
status ((str)) – New status to be updated for the row specified by detail.
- Returns
Nothing.
- Return type
None
- update_status(detail: str, status: str) None
Updates the status of the summary status table of the corresponding detail.
- Parameters
detail ((str)) – value of the detail in the Details column. Used to locate which row to update.
status ((str)) – new status to be updated for the row specified by detail.
- Returns
Nothing.
- Return type
None
ads.model.model_properties module
- class ads.model.model_properties.ModelProperties(inference_conda_env: Optional[str] = None, inference_python_version: Optional[str] = None, training_conda_env: Optional[str] = None, training_python_version: Optional[str] = None, training_resource_id: Optional[str] = None, training_script_path: Optional[str] = None, training_id: Optional[str] = None, compartment_id: Optional[str] = None, project_id: Optional[str] = None, bucket_uri: Optional[str] = None, remove_existing_artifact: Optional[bool] = None, overwrite_existing_artifact: Optional[bool] = None, deployment_instance_shape: Optional[str] = None, deployment_instance_count: Optional[int] = None, deployment_bandwidth_mbps: Optional[int] = None, deployment_log_group_id: Optional[str] = None, deployment_access_log_id: Optional[str] = None, deployment_predict_log_id: Optional[str] = None, deployment_memory_in_gbs: Optional[Union[float, int]] = None, deployment_ocpus: Optional[Union[float, int]] = None)
Bases:
BaseProperties
Represents properties required to save and deploy model.
- bucket_uri: str = None
- compartment_id: str = None
- deployment_access_log_id: str = None
- deployment_bandwidth_mbps: int = None
- deployment_instance_count: int = None
- deployment_instance_shape: str = None
- deployment_log_group_id: str = None
- deployment_memory_in_gbs: Union[float, int] = None
- deployment_ocpus: Union[float, int] = None
- deployment_predict_log_id: str = None
- inference_conda_env: str = None
- inference_python_version: str = None
- overwrite_existing_artifact: bool = None
- project_id: str = None
- remove_existing_artifact: bool = None
- training_conda_env: str = None
- training_id: str = None
- training_python_version: str = None
- training_resource_id: str = None
- training_script_path: str = None
ads.model.runtime.runtime_info module
- class ads.model.runtime.runtime_info.RuntimeInfo(model_artifact_version: str = '', model_deployment: ~ads.model.runtime.model_deployment_details.ModelDeploymentDetails = <factory>, model_provenance: ~ads.model.runtime.model_provenance_details.ModelProvenanceDetails = <factory>)
Bases:
DataClassSerializable
RuntimeInfo class which is the data class represenation of the runtime yaml file.
- classmethod from_env() RuntimeInfo
Popolate the RuntimeInfo from environment variables.
- Returns
A RuntimeInfo instance.
- Return type
- model_artifact_version: str = ''
- model_deployment: ModelDeploymentDetails
- model_provenance: ModelProvenanceDetails
- save()
Save the RuntimeInfo object into runtime.yaml file under the artifact directory.
- Returns
Nothing.
- Return type
None
ads.model.extractor.model_info_extractor_factory module
- class ads.model.extractor.model_info_extractor_factory.ModelInfoExtractorFactory
Bases:
object
Class that extract Model Taxonomy Metadata for all supported frameworks.
- static extract_info(model)
Extracts model taxonomy metadata.
- Parameters
model ([ADS model, sklearn, xgboost, lightgbm, keras, oracle_automl]) – The model object
- Returns
A dictionary with keys of Framework, FrameworkVersion, Algorithm, Hyperparameters of the model
- Return type
ModelTaxonomyMetadata
Examples
>>> from ads.common.model_info_extractor_factory import ModelInfoExtractorFactory >>> metadata_taxonomy = ModelInfoExtractorFactory.extract_info(model)
ads.model.extractor.model_artifact module
ads.model.extractor.automl_extractor module
- class ads.model.extractor.automl_extractor.AutoMLExtractor(model)
Bases:
ModelInfoExtractor
Class that extract model metadata from automl models.
- model
The model to extract metadata from.
- Type
object
- estimator
The estimator to extract metadata from.
- Type
object
- property algorithm
Extracts the algorithm of the model.
- Returns
The algorithm of the model.
- Return type
object
- property framework
Extracts the framework of the model.
- Returns
The framework of the model.
- Return type
str
- property hyperparameter
Extracts the hyperparameters of the model.
- Returns
The hyperparameters of the model.
- Return type
dict
- property version
Extracts the framework version of the model.
- Returns
The framework version of the model.
- Return type
str
ads.model.extractor.xgboost_extractor module
- class ads.model.extractor.xgboost_extractor.XgboostExtractor(model)
Bases:
ModelInfoExtractor
Class that extract model metadata from xgboost models.
- model
The model to extract metadata from.
- Type
object
- estimator
The estimator to extract metadata from.
- Type
object
- framework(self) str
Returns the framework of the model.
- algorithm(self) object
Returns the algorithm of the model.
- version(self) str
Returns the version of framework of the model.
- hyperparameter(self) dict
Returns the hyperparameter of the model.
- property algorithm
Extracts the algorithm of the model.
- Returns
The algorithm of the model.
- Return type
object
- property framework
Extracts the framework of the model.
- Returns
The framework of the model.
- Return type
str
- property hyperparameter
Extracts the hyperparameters of the model.
- Returns
The hyperparameters of the model.
- Return type
dict
- property version
Extracts the framework version of the model.
- Returns
The framework version of the model.
- Return type
str
ads.model.extractor.lightgbm_extractor module
- class ads.model.extractor.lightgbm_extractor.LightgbmExtractor(model)
Bases:
ModelInfoExtractor
Class that extract model metadata from lightgbm models.
- model
The model to extract metadata from.
- Type
object
- estimator
The estimator to extract metadata from.
- Type
object
- framework(self) str
Returns the framework of the model.
- algorithm(self) object
Returns the algorithm of the model.
- version(self) str
Returns the version of framework of the model.
- hyperparameter(self) dict
Returns the hyperparameter of the model.
- property algorithm
Extracts the algorithm of the model.
- Returns
The algorithm of the model.
- Return type
object
- property framework
Extracts the framework of the model.
- Returns
The framework of the model.
- Return type
str
- property hyperparameter
Extracts the hyperparameters of the model.
- Returns
The hyperparameters of the model.
- Return type
dict
- property version
Extracts the framework version of the model.
- Returns
The framework version of the model.
- Return type
str
ads.model.extractor.model_info_extractor module
- class ads.model.extractor.model_info_extractor.ModelInfoExtractor
Bases:
ABC
The base abstract class to extract model metadata.
- framework(self) str
Returns the framework of the model.
- algorithm(self) object
Returns the algorithm of the model.
- version(self) str
Returns the version of framework of the model.
- hyperparameter(self) dict
Returns the hyperparameter of the model.
- info(self) dict
Returns the model taxonomy metadata information.
- abstract algorithm()
The abstract method to extracts the algorithm of the model.
- Returns
The algorithm of the model.
- Return type
object
- abstract framework()
The abstract method to extracts the framework of the model.
- Returns
The framework of the model.
- Return type
str
- abstract hyperparameter()
The abstract method to extracts the hyperparameters of the model.
- Returns
The hyperparameter of the model.
- Return type
dict
- info()
Extracts the taxonomy metadata of the model.
- Returns
The taxonomy metadata of the model.
- Return type
dict
- abstract version()
The abstract method to extracts the framework version of the model.
- Returns
The framework version of the model.
- Return type
str
- ads.model.extractor.model_info_extractor.normalize_hyperparameter(data: Dict) dict
Converts all the fields to string to make sure it’s json serializable.
- Parameters
data (([Dict])) – The hyperparameter returned by the model.
- Returns
Normalized (json serializable) dictionary.
- Return type
Dict
ads.model.extractor.sklearn_extractor module
- class ads.model.extractor.sklearn_extractor.SklearnExtractor(model)
Bases:
ModelInfoExtractor
Class that extract model metadata from sklearn models.
- model
The model to extract metadata from.
- Type
object
- estimator
The estimator to extract metadata from.
- Type
object
- framework(self) str
Returns the framework of the model.
- algorithm(self) object
Returns the algorithm of the model.
- version(self) str
Returns the version of framework of the model.
- hyperparameter(self) dict
Returns the hyperparameter of the model.
- property algorithm
Extracts the algorithm of the model.
- Returns
The algorithm of the model.
- Return type
object
- property framework
Extracts the framework of the model.
- Returns
The framework of the model.
- Return type
str
- property hyperparameter
Extracts the hyperparameters of the model.
- Returns
The hyperparameters of the model.
- Return type
dict
- property version
Extracts the framework version of the model.
- Returns
The framework version of the model.
- Return type
str
ads.model.extractor.keras_extractor module
- class ads.model.extractor.keras_extractor.KerasExtractor(model)
Bases:
ModelInfoExtractor
Class that extract model metadata from keras models.
- model
The model to extract metadata from.
- Type
object
- estimator
The estimator to extract metadata from.
- Type
object
- property algorithm
Extracts the algorithm of the model.
- Returns
The algorithm of the model.
- Return type
object
- property framework
Extracts the framework of the model.
- Returns
The framework of the model.
- Return type
str
- property hyperparameter
Extracts the hyperparameters of the model.
- Returns
The hyperparameters of the model.
- Return type
dict
- property version
Extracts the framework version of the model.
- Returns
The framework version of the model.
- Return type
str
ads.model.extractor.tensorflow_extractor module
- class ads.model.extractor.tensorflow_extractor.TensorflowExtractor(model)
Bases:
ModelInfoExtractor
Class that extract model metadata from tensorflow models.
- model
The model to extract metadata from.
- Type
object
- estimator
The estimator to extract metadata from.
- Type
object
- framework(self) str
Returns the framework of the model.
- algorithm(self) object
Returns the algorithm of the model.
- version(self) str
Returns the version of framework of the model.
- hyperparameter(self) dict
Returns the hyperparameter of the model.
- property algorithm
Extracts the algorithm of the model.
- Returns
The algorithm of the model.
- Return type
object
- property framework
Extracts the framework of the model.
- Returns
The framework of the model.
- Return type
str
- property hyperparameter
Extracts the hyperparameters of the model.
- Returns
The hyperparameters of the model.
- Return type
dict
- property version
Extracts the framework version of the model.
- Returns
The framework version of the model.
- Return type
str
ads.model.extractor.pytorch_extractor module
- class ads.model.extractor.pytorch_extractor.PyTorchExtractor(model)
Bases:
ModelInfoExtractor
Class that extract model metadata from pytorch models.
- model
The model to extract metadata from.
- Type
object
- estimator
The estimator to extract metadata from.
- Type
object
- framework(self) str
Returns the framework of the model.
- algorithm(self) object
Returns the algorithm of the model.
- version(self) str
Returns the version of framework of the model.
- hyperparameter(self) dict
Returns the hyperparameter of the model.
- property algorithm
Extracts the algorithm of the model.
- Returns
The algorithm of the model.
- Return type
object
- property framework
Extracts the framework of the model.
- Returns
The framework of the model.
- Return type
str
- property hyperparameter
Extracts the hyperparameters of the model.
- Returns
The hyperparameters of the model.
- Return type
dict
- property version
Extracts the framework version of the model.
- Returns
The framework version of the model.
- Return type
str
- class ads.model.extractor.pytorch_extractor.PytorchExtractor(model)
Bases:
PyTorchExtractor