functions Package

Contains functionality for packaging Azure Machine Learning models for deployment to Azure Functions.

Azure Functions allows you to run small pieces of code (called "functions") that can be triggered by a specified event, such as changes in data, or on a schedule as often needed in machine learning workflows. For more information, see An introduction to Azure Functions.

With the functions in this package, you can create Azure Functions applications from models registered in your Azure Machine Learning workspace. Each function returns a ModelPackage object representing either a Docker image that encapsulates your model and its dependencies or a Dockerfile build context.

For examples of using Azure Functions for machine learning, see Tutorial: Apply machine learning models in Azure Functions with Python and TensorFlow and Tutorial: Deploy a pre-trained image classification model to Azure Functions with PyTorch.

Functions

package

Create a model package in the form of a Docker image or Dockerfile build context.

This function creates a model package for use in Azure Functions with the specified trigger type. The other functions in this package, create model packages for specific trigger types. For more information, see Azure Functions triggers and bindings.

package(workspace, models, inference_config, generate_dockerfile=False, functions_enabled=False, trigger=None, **kwargs)

Parameters

Name Description
workspace
Required

The workspace in which to create the package.

models
Required

A list of Model objects to include in the package. Can be an empty list.

inference_config
Required

An InferenceConfig object to configure the operation of the models. This must include an Environment object.

generate_dockerfile

Whether to create a Dockerfile that can be run locally instead of building an image.

default value: False
functions_enabled

Whether Azure Functions should be enabled in the packaged container.

default value: False
trigger
str

An optional trigger for the function. The values can be "blob", "http", or "service_bus_queue".

default value: None
kwargs
Required

Any of the arguments for a specific package function defined in this module. For example, for the package_http method, the argument passed is auth_level.

Returns

Type Description

A ModelPackage object.

Exceptions

Type Description

Invalid trigger specified.

package_blob

Create an Azure Functions model package as a Docker image or Dockerfile build context with a blob trigger.

package_blob(workspace, models, inference_config, generate_dockerfile=False, input_path=None, output_path=None)

Parameters

Name Description
workspace
Required

The workspace in which to create the package.

models
Required

A list of Model objects to include in the package. Can be an empty list.

inference_config
Required

An InferenceConfig object to configure the operation of the models. This must include an Environment object.

generate_dockerfile

Whether to create a Dockerfile that can be run locally instead of building an image.

default value: False
input_path
str

Input path for the blob trigger option.

default value: None
output_path
str

Output path for the blob trigger option.

default value: None

Returns

Type Description

A ModelPackage object.

Exceptions

Type Description

Invalid trigger specified.

package_http

Create an Azure Functions model package as a Docker image or Dockerfile build context with an HTTP trigger.

package_http(workspace, models, inference_config, generate_dockerfile=False, auth_level=None)

Parameters

Name Description
workspace
Required

The workspace in which to create the package.

models
Required

A list of Model objects to include in the package. Can be an empty list.

inference_config
Required

An InferenceConfig object to configure the operation of the models. This must include an Environment object.

generate_dockerfile

Whether to create a Dockerfile that can be run locally instead of building an image.

default value: False
auth_level
str

Auth level for the generated HTTP function.

default value: None

Returns

Type Description

A ModelPackage object.

Exceptions

Type Description

Invalid trigger specified.

package_service_bus_queue

Create an Azure Functions model package as a Docker image or Dockerfile with a service bus queue trigger.

package_service_bus_queue(workspace, models, inference_config, generate_dockerfile=False, input_queue_name=None, output_queue_name=None)

Parameters

Name Description
workspace
Required

The workspace in which to create the package.

models
Required

A list of Model objects to include in the package. Can be an empty list.

inference_config
Required

An InferenceConfig object to configure the operation of the models. This must include an Environment object.

generate_dockerfile

Whether to create a Dockerfile that can be run locally instead of building an image.

default value: False
input_queue_name
str

Input queue name for the queue trigger option.

default value: None
output_queue_name
str

Output queue name for the queue trigger option.

default value: None

Returns

Type Description

A ModelPackage object.

Exceptions

Type Description

Invalid trigger specified.