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

workspace
Workspace
Required

The workspace in which the package exists.

operation_id
str
Required

ID of the package creation operation.

environment
Environment
Required

Environment in which the model is being packaged.

workspace
Workspace
Required

The workspace in which the package exists.

operation_id
str
Required

ID of the package creation operation.

environment
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

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

The address and login credentials for the container registry.

Return type

get_logs

Retrieve the package creation logs.

get_logs(decode=True, offset=0)

Parameters

decode
bool
default value: True

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

offset
int
default value: 0

The byte offset from which to start reading the logs.

Returns

The package creation logs.

Return type

str

Exceptions

pull

Pull the package output to the local machine.

This can only be used with a Docker image package.

pull()

Exceptions

save

Save the package output to a local directory.

This can only be used with a Dockerfile package.

save(output_directory)

Parameters

output_directory
str
Required

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

Exceptions

serialize

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

serialize()

Returns

The JSON representation of this ModelPackage.

Return type

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

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

show_output
bool
default value: False

Indicates whether to print more verbose output.

Exceptions