Search code examples
pythondockerdeploymentazure-container-instancesazure-machine-learning-service

Why does my ML model deployment in Azure Container Instance still fail with "current service state: Transitioning"?


I am using Azure Machine Learning Service to deploy a ML model as web service.

I registered a model and now would like to deploy it as an ACI web service as in the guide.

To do so I define

from azureml.core.webservice import Webservice, AciWebservice
from azureml.core.image import ContainerImage

aciconfig = AciWebservice.deploy_configuration(cpu_cores=4, 
                      memory_gb=32, 
                      tags={"data": "text",  "method" : "NB"}, 
                      description='Predict something')

and

image_config = ContainerImage.image_configuration(execution_script="score.py", 
                      docker_file="Dockerfile",
                      runtime="python", 
                      conda_file="myenv.yml")

and create an image with

image = ContainerImage.create(name = "scorer-image",
                      models = [model],
                      image_config = image_config,
                      workspace = ws
                      )

Image creation succeeds with

Creating image Image creation operation finished for image scorer-image:5, operation "Succeeded"

Also, troubleshooting the image by running it locally on an Azure VM with

sudo docker run -p 8002:5001 myscorer0588419434.azurecr.io/scorer-image:5

allows me to run (locally) queries successfully against http://localhost:8002/score.

However, deployment with

service_name = 'scorer-svc'
service = Webservice.deploy_from_image(deployment_config = aciconfig,
                                        image = image,
                                        name = service_name,
                                        workspace = ws)

fails with

Creating service
Running.
FailedACI service creation operation finished, operation "Failed"
Service creation polling reached terminal state, current service state: Transitioning
Service creation polling reached terminal state, unexpected response received. Transitioning

I tried setting in the aciconfig more generous memory_gb, but to no avail: the deployment stays in a transitioning state (like in the image below if monitored on the Azure portal): enter image description here

Also, running service.get_logs() gives me

WebserviceException: Received bad response from Model Management Service: Response Code: 404

What could possibly be the culprit?


Solution

  • If ACI deployment fails, one solution is trying to allocate less resources, e.g.

    aciconfig = AciWebservice.deploy_configuration(cpu_cores=1, 
                      memory_gb=8, 
                      tags={"data": "text",  "method" : "NB"}, 
                      description='Predict something')
    

    While the error messages thrown are not particularly informative, this is actually clearly stated in the documentation:

    When a region is under heavy load, you may experience a failure when deploying instances. To mitigate such a deployment failure, try deploying instances with lower resource settings [...]

    The documentation also states which are the maximum values of the CPU/RAM resources available in the different regions (at the time of writing, requiring a deployment with memory_gb=32 would likely fail in all regions because of insufficient resources).

    Upon requiring less resources, deployment should succeed with

    Creating service
    Running......................................................
    SucceededACI service creation operation finished, operation
    "Succeeded" Healthy