Deploy a model to Azure Machine Learning compute instances

APPLIES TO: yesBasic edition yesEnterprise edition                    (Upgrade to Enterprise edition)


Compute instances (preview) are available only for workspaces with a region of North Central US or UK South. If your workspace is in any other region, you can continue to create and use a Notebook VM instead. You can deploy a model to either a compute instance or a Notebook VM using the steps in this article.

Learn how to use Azure Machine Learning to deploy a model as a web service on your Azure Machine Learning compute instance. Use compute instances if one of the following conditions is true:

  • You need to quickly deploy and validate your model.
  • You are testing a model that is under development.


Deploying a model from a Jupyter Notebook on a compute instance, to a web service on the same VM is a local deployment. In this case, the 'local' computer is the compute instance. For more information on deployments, see Deploy models with Azure Machine Learning.


Deploy to the compute instances

An example notebook that demonstrates local deployments is included on your compute instance. Use the following steps to load the notebook and deploy the model as a web service on the VM:

  1. From Azure Machine Learning studio, select your Azure Machine Learning compute instances.

  2. Open the samples-* subdirectory, and then open how-to-use-azureml/deploy-to-local/register-model-deploy-local.ipynb. Once open, run the notebook.

    Screenshot of the running local service on notebook

  3. The notebook displays the URL and port that the service is running on. For example, https://localhost:6789. You can also run the cell containing print('Local service port: {}'.format(local_service.port)) to display the port.

    Screenshot of the running local service port

  4. To test the service from a compute instance, use the https://localhost:<local_service.port> URL. To test from a remote client, get the public URL of the service running on the compute instance. The public URL can be determined use the following formula;

    • Notebook VM: https://<vm_name>-<local_service_port>.<azure_region_of_workspace>
    • Compute instance: https://<vm_name>-<local_service_port>.<azure_region_of_workspace>

    For example,

    • Notebook VM:
    • Compute instance:

Test the service

To submit sample data to the running service, use the following code. Replace the value of service_url with the URL of from the previous step:


When authenticating to a deployment on the compute instance, the authentication is made using Azure Active Directory. The call to interactive_auth.get_authentication_header() in the example code authenticates you using AAD, and returns a header that can then be used to authenticate to the service on the compute instance. For more information, see Set up authentication for Azure Machine Learning resources and workflows.

When authenticating to a deployment on Azure Kubernetes Service or Azure Container Instances, a different authentication method is used. For more information on, see Set up authentication for Azure Machine Learning resources and workflows.

import requests
import json
from azureml.core.authentication import InteractiveLoginAuthentication

# Get a token to authenticate to the compute instance from remote
interactive_auth = InteractiveLoginAuthentication()
auth_header = interactive_auth.get_authentication_header()

# Create and submit a request using the auth header
headers = auth_header
# Add content type header

# Sample data to send to the service
test_sample = json.dumps({'data': [
test_sample = bytes(test_sample,encoding = 'utf8')

# Replace with the URL for your compute instance, as determined from the previous section
service_url = ""
# for a compute instance, the url would be
resp =, test_sample, headers=headers)
print("prediction:", resp.text)

Next steps