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

workspace
Workspace
Required

The workspace in which to create the package.

models
list[Model]
Required

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

inference_config
InferenceConfig
Required

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

generate_dockerfile
bool
default value: False

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

functions_enabled
bool
default value: False

Whether Azure Functions should be enabled in the packaged container.

trigger
str
default value: None

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

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

A ModelPackage object.

Return type

Exceptions

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

workspace
Workspace
Required

The workspace in which to create the package.

models
list[Model]
Required

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

inference_config
InferenceConfig
Required

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

generate_dockerfile
bool
default value: False

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

input_path
str
default value: None

Input path for the blob trigger option.

output_path
str
default value: None

Output path for the blob trigger option.

Returns

A ModelPackage object.

Return type

Exceptions

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

workspace
Workspace
Required

The workspace in which to create the package.

models
list[Model]
Required

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

inference_config
InferenceConfig
Required

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

generate_dockerfile
bool
default value: False

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

auth_level
str
default value: None

Auth level for the generated HTTP function.

Returns

A ModelPackage object.

Return type

Exceptions

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

workspace
Workspace
Required

The workspace in which to create the package.

models
list[Model]
Required

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

inference_config
InferenceConfig
Required

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

generate_dockerfile
bool
default value: False

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

input_queue_name
str
default value: None

Input queue name for the queue trigger option.

output_queue_name
str
default value: None

Output queue name for the queue trigger option.

Returns

A ModelPackage object.

Return type

Exceptions

Invalid trigger specified.