ModelPackage Class

Represents a packaging of one or more models and their dependencies into either a Docker image or Dockerfile.

A ModelPackage object is returned from the package method of the Model class. The generate_dockerfile parameter of the package method determines if a Docker image or Dockerfile is created.

Initialize package created with model(s) and dependencies.

Inheritance
builtins.object
ModelPackage

Constructor

ModelPackage(workspace, operation_id, environment)

Parameters

Name Description
workspace
Required

The workspace in which the package exists.

operation_id
Required
str

ID of the package creation operation.

environment
Required

Environment in which the model is being packaged.

workspace
Required

The workspace in which the package exists.

operation_id
Required
str

ID of the package creation operation.

environment
Required

Environment in which the model is being packaged.

Remarks

To build a Docker image that encapsulates your model and its dependencies, you can use the model packaging option. The output image will be pushed to your workspace's ACR.

You must include an Environment object in your inference configuration to use the Model package method.


   package = Model.package(ws, [model], inference_config)
   package.wait_for_creation(show_output=True)  # Or show_output=False to hide the Docker build logs.
   package.pull()

Instead of a fully-built image, you can instead generate a Dockerfile and download all the assets needed to build an image on top of your Environment.


   package = Model.package(ws, [model], inference_config, generate_dockerfile=True)
   package.wait_for_creation(show_output=True)
   package.save("./local_context_dir")

Variables

Name Description
azureml.core.model.ModelPackage.workspace

The workspace in which the package is created.

Methods

get_container_registry

Return a ContainerRegistry object indicating where the image or base image (Dockerfile packages) is stored.

get_logs

Retrieve the package creation logs.

pull

Pull the package output to the local machine.

This can only be used with a Docker image package.

save

Save the package output to a local directory.

This can only be used with a Dockerfile package.

serialize

Convert this ModelPackage into a JSON-serializable dictionary for display by the CLI.

update_creation_state

Refresh the current state of the in-memory object.

This method performs an in-place update of the properties of the object based on the current state of the corresponding cloud object. This is primarily used for manual polling of creation state.

wait_for_creation

Wait for the package to finish creating.

This method waits for package creation to reach a terminal state. Will throw a WebserviceException if it reaches a non-successful terminal state.

get_container_registry

Return a ContainerRegistry object indicating where the image or base image (Dockerfile packages) is stored.

get_container_registry()

Returns

Type Description

The address and login credentials for the container registry.

get_logs

Retrieve the package creation logs.

get_logs(decode=True, offset=0)

Parameters

Name Description
decode

Indicates whether to decode the raw log bytes to a string.

Default value: True
offset
int

The byte offset from which to start reading the logs.

Default value: 0

Returns

Type Description
str

The package creation logs.

Exceptions

Type Description

pull

Pull the package output to the local machine.

This can only be used with a Docker image package.

pull()

Exceptions

Type Description

save

Save the package output to a local directory.

This can only be used with a Dockerfile package.

save(output_directory)

Parameters

Name Description
output_directory
Required
str

The local directory that will be created to contain the contents of the package.

Exceptions

Type Description

serialize

Convert this ModelPackage into a JSON-serializable dictionary for display by the CLI.

serialize()

Returns

Type Description

The JSON representation of this ModelPackage.

update_creation_state

Refresh the current state of the in-memory object.

This method performs an in-place update of the properties of the object based on the current state of the corresponding cloud object. This is primarily used for manual polling of creation state.

update_creation_state()

Exceptions

Type Description

wait_for_creation

Wait for the package to finish creating.

This method waits for package creation to reach a terminal state. Will throw a WebserviceException if it reaches a non-successful terminal state.

wait_for_creation(show_output=False)

Parameters

Name Description
show_output

Indicates whether to print more verbose output.

Default value: False

Exceptions

Type Description