LocalWebservice Class

Represents a machine learning model deployed as a local web service endpoint.

Deploying web services locally is useful for debugging and testing scenarios.

Local webservice constructor.

LocalWebservice constructor is used to retrieve a local representation of a LocalWebservice object associated with the provided workspace.

Inheritance
LocalWebservice

Constructor

LocalWebservice(*args, **kwargs)

Parameters

workspace
Workspace
Required

The workspace object containing any Model objects that will be retrieved.

name
str
Required

The name of the Webservice object to retrieve.

must_exist
bool
Required

Whether the webservice must already exist when creating the in-memory object.

workspace
Workspace
Required

The workspace object containing any Model objects that will be retrieved.

name
str
Required

The name of the LocalWebservice object to retrieve.

must_exist
bool
Required

Whether the webservice must already exist when creating the in-memory object.

Remarks

The following code samples shows how to create a local Docker web service. See the notebook link for more details.


   from azureml.core.webservice import LocalWebservice

   # This is optional, if not provided Docker will choose a random unused port.
   deployment_config = LocalWebservice.deploy_configuration(port=6789)

   local_service = Model.deploy(ws, "test", [model], inference_config, deployment_config)

   local_service.wait_for_deployment()

Full sample is available from https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/deployment/deploy-to-local/register-model-deploy-local.ipynb

Methods

delete

Delete this LocalWebservice from the local machine.

This function call is not asynchronous; it runs until the service is deleted.

deploy_configuration

Create a configuration object for deploying a local Webservice.

deploy_to_cloud

Deploy a Webservice based on the LocalWebservice's configuration.

deserialize

Convert a Model Management Service response JSON object into a Webservice object.

Note

Not supported for LocalWebservice.

get_keys

Retrieve auth keys for this Webservice.

Note

Not supported for LocalWebservice.

get_logs

Retrieve logs for this LocalWebservice.

get_token

Retrieve auth token for this Webservice, scoped to the current user.

Note

Not supported for LocalWebservice.

list

List the LocalWebservices associated with the corresponding Workspace.

The results returned can be filtered using parameters.

regen_key

Regenerate one of the Webservice's keys.

Note

Not supported for LocalWebservice.

reload

Reload the LocalWebservice's execution script and dependencies.

This restarts the service's container with copies of updated assets, including the execution script and local dependencies, but it does not rebuild the underlying image. Accordingly, changes to Conda/pip dependencies or custom Docker steps will not be reflected in the reloaded LocalWebservice. To handle those changes call the update method instead.

run

Call this LocalWebservice with the provided input.

serialize

Convert this Webservice object into a JSON-serialized dictionary.

update

Update the LocalWebservice with provided properties.

Values left as None will remain unchanged in this LocalWebservice.

update_deployment_state

Refresh the current state of the in-memory object.

Perform an in-place update of the properties of the object based on the current state of the corresponding local Docker container.

wait_for_deployment

Poll the running LocalWebservice deployment.

delete

Delete this LocalWebservice from the local machine.

This function call is not asynchronous; it runs until the service is deleted.

delete(delete_cache=True, delete_image=False, delete_volume=True)

Parameters

delete_cache
bool
Required

Whether to delete temporary files cached for the service. (Default: True)

delete_image
bool
Required

Whether to delete the service's Docker image. (Default: False)

delete_volume
bool
Required

Whether to delete the service's Docker volume. (Default: True)

Exceptions

deploy_configuration

Create a configuration object for deploying a local Webservice.

static deploy_configuration(port=None)

Parameters

port
int
default value: None

The local port on which to expose the service's HTTP endpoint.

Returns

A configuration object to use when deploying a Webservice object.

Return type

Exceptions

deploy_to_cloud

Deploy a Webservice based on the LocalWebservice's configuration.

deploy_to_cloud(name=None, deployment_config=None, deployment_target=None)

Parameters

name
str
default value: None

The name to give the deployed service. Must be unique to the workspace.

deployment_config
WebserviceDeploymentConfiguration
default value: None

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

deployment_target
ComputeTarget
default value: None

A ComputeTarget to which to deploy the Webservice. As ACI has no associated ComputeTarget, leave this parameter as None to deploy to ACI.

Returns

A Webservice object corresponding to the deployed webservice.

Return type

Exceptions

deserialize

Convert a Model Management Service response JSON object into a Webservice object.

Note

Not supported for LocalWebservice.

deserialize(workspace, webservice_payload)

Parameters

cls
Required
workspace
Workspace
Required

The workspace object the Webservice is registered under.

webservice_payload
dict
Required

A JSON object to convert to a Webservice object.

Exceptions

azureml.exceptions.NotImplementedError

get_keys

Retrieve auth keys for this Webservice.

Note

Not supported for LocalWebservice.

get_keys()

Returns

The auth keys for this Webservice.

Exceptions

azureml.exceptions.NotImplementedError

get_logs

Retrieve logs for this LocalWebservice.

get_logs(num_lines=5000, raw=False)

Parameters

num_lines
int
Required

The maximum number of log lines to retrieve. (Default: 5000)

raw
bool
Required

Return the raw Docker container output without attempting to format it. (Default: False)

Returns

The logs for this LocalWebservice.

Return type

str

Exceptions

get_token

Retrieve auth token for this Webservice, scoped to the current user.

Note

Not supported for LocalWebservice.

get_token()

Returns

The auth token for this Webservice and when it should be refreshed after.

Return type

Exceptions

azureml.exceptions.NotImplementedError

list

List the LocalWebservices associated with the corresponding Workspace.

The results returned can be filtered using parameters.

static list(workspace, model_name=None, model_id=None, all=None)

Parameters

workspace
Workspace
Required

The Workspace object associated with the LocalWebservices.

model_name
str
default value: None

Filter list to only include LocalWebservices deployed with the specific model name.

model_id
str
default value: None

Filter list to only include LocalWebservices deployed with the specific model ID.

all
bool
default value: None

Show all services. Only running services are shown by default.

Returns

A filtered list of LocalWebservices associated with the provided Workspace.

Return type

Exceptions

regen_key

Regenerate one of the Webservice's keys.

Note

Not supported for LocalWebservice.

regen_key(key)

Parameters

key
str
Required

Which key to regenerate. Options are 'Primary' or 'Secondary'

Exceptions

reload

Reload the LocalWebservice's execution script and dependencies.

This restarts the service's container with copies of updated assets, including the execution script and local dependencies, but it does not rebuild the underlying image. Accordingly, changes to Conda/pip dependencies or custom Docker steps will not be reflected in the reloaded LocalWebservice. To handle those changes call the update method instead.

reload(wait=False)

Parameters

wait
bool
Required

Wait for the service's container to reach a healthy state. (Default: False)

Exceptions

run

Call this LocalWebservice with the provided input.

run(input_data)

Parameters

input_data
<xref:varies>
Required

The input with which to call the LocalWebservice.

Returns

The result of calling the LocalWebservice.

Return type

<xref:varies>

Exceptions

serialize

Convert this Webservice object into a JSON-serialized dictionary.

serialize()

Returns

Serialized representation of the Webservice object.

Return type

Exceptions

update

Update the LocalWebservice with provided properties.

Values left as None will remain unchanged in this LocalWebservice.

update(models=None, image_config=None, deployment_config=None, wait=False, inference_config=None)

Parameters

models
list[Model]
Required

A new list of models contained in the LocalWebservice.

image_config
ContainerImageConfig
Required

Image configuration options to apply to the LocalWebservice.

deployment_config
LocalWebserviceDeploymentConfiguration
Required

Deployment configuration options to apply to the LocalWebservice.

inference_config
InferenceConfig
Required

An InferenceConfig object used to provide the required model deployment properties.

wait
bool
Required

Wait for the service's container to reach a healthy state. (Default: False)

Return type

Exceptions

update_deployment_state

Refresh the current state of the in-memory object.

Perform an in-place update of the properties of the object based on the current state of the corresponding local Docker container.

update_deployment_state(must_exist=False)

Parameters

must_exist
bool
default value: False

Whether the webservice must already exist when creating the in-memory object.

Exceptions

wait_for_deployment

Poll the running LocalWebservice deployment.

wait_for_deployment(show_output=False)

Parameters

show_output
bool
Required

Option to print more verbose output. (Default: False)

Exceptions

Attributes

port

Get the local webservice port.

Returns

Port number.

Return type

int

scoring_uri

Get the local webservice scoring URI.

Returns

Scoring URI.

Return type

str

swagger_uri

Get the local webservice Swagger URI.

Returns

Swagger URI.

Return type

str

NETWORK_NAME

NETWORK_NAME = 'azureml-local'

STATE_DELETED

STATE_DELETED = 'deleted'

STATE_DEPLOYING

STATE_DEPLOYING = 'deploying'

STATE_FAILED

STATE_FAILED = 'failed'

STATE_RUNNING

STATE_RUNNING = 'running'

STATE_UNKNOWN

STATE_UNKNOWN = 'unknown'