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
The workspace object containing any Model objects that will be retrieved.
- must_exist
- bool
Whether the webservice must already exist when creating the in-memory object.
- workspace
- Workspace
The workspace object containing any Model objects that will be retrieved.
- must_exist
- bool
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
Whether to delete temporary files cached for the service. (Default: True)
Exceptions
deploy_configuration
Create a configuration object for deploying a local Webservice.
static deploy_configuration(port=None)
Parameters
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
The name to give the deployed service. Must be unique to the workspace.
- deployment_config
- WebserviceDeploymentConfiguration
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
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
Exceptions
get_keys
Retrieve auth keys for this Webservice.
Note
Not supported for LocalWebservice.
get_keys()
Returns
The auth keys for this Webservice.
Exceptions
get_logs
Retrieve logs for this LocalWebservice.
get_logs(num_lines=5000, raw=False)
Parameters
- raw
- bool
Return the raw Docker container output without attempting to format it. (Default: False)
Returns
The logs for this LocalWebservice.
Return type
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
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
- model_name
- str
Filter list to only include LocalWebservices deployed with the specific model name.
- model_id
- str
Filter list to only include LocalWebservices deployed with the specific model ID.
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
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
Exceptions
run
Call this LocalWebservice with the provided input.
run(input_data)
Parameters
- input_data
- <xref:varies>
The input with which to call the LocalWebservice.
Returns
The result of calling the LocalWebservice.
Return type
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
- image_config
- ContainerImageConfig
Image configuration options to apply to the LocalWebservice.
- deployment_config
- LocalWebserviceDeploymentConfiguration
Deployment configuration options to apply to the LocalWebservice.
- inference_config
- InferenceConfig
An InferenceConfig object used to provide the required model deployment properties.
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
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
Exceptions
Attributes
port
scoring_uri
swagger_uri
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'
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for