Model class

Definition

Class for AzureML models.

Model constructor is used to retrieve a cloud representation of a Model object associated with the provided workspace. Must provide either name or ID.

Model(workspace, name=None, id=None, tags=None, properties=None, version=None, run_id=None, model_framework=None)
Inheritance
builtins.object
Model

Parameters

workspace
Workspace

The workspace object containing the Model to retrieve

name
str

Will retrieve the latest model with the corresponding name, if it exists

id
str

Will retrieve the model with the corresponding ID, if it exists

tags
<xref:azureml.core.model.Model.list>

Optional, will filter based on the provided list, searching by either 'key' or '[key, value]'. Ex. ['key', ['key2', 'key2 value']]

properties
<xref:azureml.core.model.Model.list>

Optional, will filter based on the provided list, searching by either 'key' or '[key, value]'. Ex. ['key', ['key2', 'key2 value']]

version
int

When provided along with name, will get the specific version of the specified named model, if it exists

run_id
str

Optional, will filter based on the provided ID.

Methods

add_dataset_references(datasets)

Associate the provided datasets with this Model.

add_properties(properties)

Add key value pairs to this model's properties dictionary.

add_tags(tags)

Add key value pairs to this model's tags dictionary.

delete()

Delete this model from its associated workspace.

deploy(workspace, name, models, inference_config, deployment_config=None, deployment_target=None)

Deploy a Webservice from zero or more model objects.

This function is similar to deploy(workspace, name, model_paths, image_config, deployment_config=None, deployment_target=None), but does not register(workspace, model_path, model_name, tags=None, properties=None, description=None, datasets=None, model_framework=None, model_framework_version=None, child_paths=None) the models. Use this function if you have model objects that are already registered.

deserialize(workspace, model_payload)

Convert a json object into a Model object.

Will fail if the provided workspace is not the workspace the model is registered under.

download(target_dir='.', exist_ok=False, exists_ok=None)

Download model to target_dir of local file system.

get_model_path(model_name, version=None, _workspace=None)

Return path to model.

The function will search for the model in the following locations If version is None:

  1. download from remote to cache
  2. load from cache azureml-models/$MODEL_NAME/$LATEST_VERSION/
  3. ./$MODEL_NAME

If version is not None:

  1. load from cache azureml-models/$MODEL_NAME/$LATEST_VERSION/
  2. download from remote to cache
list(workspace, name=None, tags=None, properties=None, run_id=None, latest=False)

Retrieve a list of all models associated with the provided workspace, with optional filters.

profile(workspace, profile_name, models, inference_config, input_data)

Profiles this model to get resource requirement recommendations.

register(workspace, model_path, model_name, tags=None, properties=None, description=None, datasets=None, model_framework=None, model_framework_version=None, child_paths=None)

Register a model with the provided workspace.

remove_tags(tags)

Remove the specified keys from this model's dictionary of tags.

serialize()

Convert this Model into a json serialized dictionary.

update(tags)

Perform an inplace update of the model.

update_tags_properties(add_tags=None, remove_tags=None, add_properties=None)

Perform an update of the model's tags and properties.

add_dataset_references(datasets)

Associate the provided datasets with this Model.

add_dataset_references(datasets)

Parameters

datasets
<xref:azureml.core.model.list[(str or Dataset | DatasetSnapshot)]>

A list of tuples representing a pairing of dataset purpose to Dataset object

add_properties(properties)

Add key value pairs to this model's properties dictionary.

add_properties(properties)

Parameters

properties
dict[str or str]

The dictionary of properties to add

add_tags(tags)

Add key value pairs to this model's tags dictionary.

add_tags(tags)

Parameters

tags
dict[str or str]

The dictionary of tags to add

delete()

Delete this model from its associated workspace.

delete()

deploy(workspace, name, models, inference_config, deployment_config=None, deployment_target=None)

Deploy a Webservice from zero or more model objects.

This function is similar to deploy(workspace, name, model_paths, image_config, deployment_config=None, deployment_target=None), but does not register(workspace, model_path, model_name, tags=None, properties=None, description=None, datasets=None, model_framework=None, model_framework_version=None, child_paths=None) the models. Use this function if you have model objects that are already registered.

deploy(workspace, name, models, inference_config, deployment_config=None, deployment_target=None)

Parameters

workspace
Workspace

A Workspace object to associate the Webservice with

name
str

The name to give the deployed service. Must be unique to the workspace, only consist of lowercase letters, numbers, or dashes, start with a letter, and be between 3 and 32 characters long.

models
<xref:list[Model]>

A list of model objects. Can be an empty list.

inference_config
InferenceConfig

An InferenceConfig object used to determine required model properties.

deployment_config
WebserviceDeploymentConfiguration

A WebserviceDeploymentConfiguration used to configure the webservice. If one is not provided, an empty configuration object will be used based on the desired target.

default value: None
deployment_target
ComputeTarget

A ComputeTarget to deploy the Webservice to. As Azure Container Instances has no associated ComputeTarget, leave this parameter as None to deploy to Azure Container Instances.

default value: None

Returns

A Webservice object corresponding to the deployed webservice

Return type

deserialize(workspace, model_payload)

Convert a json object into a Model object.

Will fail if the provided workspace is not the workspace the model is registered under.

deserialize(workspace, model_payload)

Parameters

workspace
Workspace

The workspace object the model is registered under

model_payload
dict

A json object to convert to a Model object

Returns

The Model representation of the provided json object

Return type

download(target_dir='.', exist_ok=False, exists_ok=None)

Download model to target_dir of local file system.

download(target_dir='.', exist_ok=False, exists_ok=None)

Parameters

target_dir
str

Path to directory for where to download the model. Defaults to "."

default value: .
exist_ok
bool

Boolean to replace downloaded dir/files if exists. Defaults to False

default value: False
exists_ok
default value: None

Returns

string path to file or folder of model

Return type

str

get_model_path(model_name, version=None, _workspace=None)

Return path to model.

The function will search for the model in the following locations If version is None:

  1. download from remote to cache
  2. load from cache azureml-models/$MODEL_NAME/$LATEST_VERSION/
  3. ./$MODEL_NAME

If version is not None:

  1. load from cache azureml-models/$MODEL_NAME/$LATEST_VERSION/
  2. download from remote to cache
get_model_path(model_name, version=None, _workspace=None)

Parameters

model_name
str

The name of the model to retrieve

version
int

The version of the model to retrieve, defaults to the latest version

default value: None
_workspace
Workspace

The workspace to retrieve a model from. Can't use remotely

default value: None

Returns

The path on disk to the model

Return type

str

list(workspace, name=None, tags=None, properties=None, run_id=None, latest=False)

Retrieve a list of all models associated with the provided workspace, with optional filters.

list(workspace, name=None, tags=None, properties=None, run_id=None, latest=False)

Parameters

workspace
Workspace

The workspace object to retrieve models from

name
str

If provided, will only return models with the specified name, if any

default value: None
tags
<xref:azureml.core.model.Model.list>

Will filter based on the provided list, by either 'key' or '[key, value]'. Ex. ['key', ['key2', 'key2 value']]

default value: None
properties
<xref:azureml.core.model.Model.list>

Will filter based on the provided list, by either 'key' or '[key, value]'. Ex. ['key', ['key2', 'key2 value']]

default value: None
run_id
str

Will filter based on the provided run ID.

default value: None
latest
bool

If true, will only return models with the latest version.

default value: False

Returns

A list of models, optionally filtered

Return type

<xref:list[Model]>

profile(workspace, profile_name, models, inference_config, input_data)

Profiles this model to get resource requirement recommendations.

profile(workspace, profile_name, models, inference_config, input_data)

Parameters

workspace
Workspace

A Workspace object in which to profile the model

profile_name
str

The name of the profiling run

models
<xref:list[Model]>

A list of model objects. Can be an empty list.

inference_config
InferenceConfig

An InferenceConfig object used to determine required model properties.

input_data
str

The input data for profiling

Return type

register(workspace, model_path, model_name, tags=None, properties=None, description=None, datasets=None, model_framework=None, model_framework_version=None, child_paths=None)

Register a model with the provided workspace.

register(workspace, model_path, model_name, tags=None, properties=None, description=None, datasets=None, model_framework=None, model_framework_version=None, child_paths=None)

Parameters

workspace
workspace: azureml.core.Workspace

The workspace to register the model under

model_path
str

String which points to the path on the local file system where the model assets are located. This can be a direct pointer to a single file or folder. If pointing to a folder, the child_paths parameter can be used to specify individual files to bundle together as the Model object, as opposed to using the entire contents of the folder.

model_name
str

The name to register the model with

tags
dict[str or str]

Dictionary of key value tags to give the model

default value: None
properties
dict[str or str]

Dictionary of key value properties to give the model. These properties cannot be changed after model creation, however new key value pairs can be added

default value: None
description
str

A text description of the model

default value: None
datasets
<xref:azureml.core.model.list[tuple[str or Dataset | DatasetSnapshot]]>

A list of tuples representing a pairing of dataset purpose to Dataset or DatasetSnapshot object. The Dataset or Dataset snapshot should be registered with the Workspace prior to this call.

default value: None
model_framework
str

The framework of the registered model

default value: None
model_framework_version
str

The framework version of the registered model

default value: None
child_paths
<xref:azureml.core.model.list[str]>

If provided in conjunction with a model_path to a folder, only the specified files will be bundled into the Model object.

default value: None

Returns

The registered model object

Return type

remove_tags(tags)

Remove the specified keys from this model's dictionary of tags.

remove_tags(tags)

Parameters

tags
<xref:azureml.core.model.list[str]>

The list of keys to remove

serialize()

Convert this Model into a json serialized dictionary.

serialize()

Returns

The json representation of this Model

Return type

update(tags)

Perform an inplace update of the model.

update(tags)

Parameters

tags
dict[str or str]

A dictionary of tags to update the model with. With replace what currently exists

update_tags_properties(add_tags=None, remove_tags=None, add_properties=None)

Perform an update of the model's tags and properties.

update_tags_properties(add_tags=None, remove_tags=None, add_properties=None)

Parameters

add_tags
dict[str or str]

A dictionary of tags to add

default value: None
remove_tags
<xref:azureml.core.model.list[str]>

A list of tag names to remove

default value: None
add_properties
dict[str or str]

A dictionary of properties to add

default value: None