Skip to content

Commit 9cf3c32

Browse files
authored
Merge pull request #115985 from shivp950/patch-14
updated deployment section
2 parents 718cc59 + 0c3a0d3 commit 9cf3c32

File tree

1 file changed

+21
-48
lines changed

1 file changed

+21
-48
lines changed

articles/machine-learning/how-to-use-mlflow.md

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -261,26 +261,9 @@ runid = runs[0].id
261261
model_save_path = 'model'
262262
```
263263
264-
### Create Docker image
264+
### Deploy the model
265265
266-
The `mlflow.azureml.build_image()` function builds a Docker image from the saved model in a framework-aware manner. It automatically creates the framework-specific inferencing wrapper code and specifies package dependencies for you. Specify the model path, your workspace, run ID and other parameters.
267-
268-
The following code builds a docker image using *runs:/<run.id>/model* as the model_uri path for a Scikit-learn experiment.
269-
270-
```python
271-
import mlflow.azureml
272-
273-
azure_image, azure_model = mlflow.azureml.build_image(model_uri='runs:/{}/{}'.format(runid, model_save_path),
274-
workspace=ws,
275-
model_name='sklearn-model',
276-
image_name='sklearn-image',
277-
synchronous=True)
278-
```
279-
The creation of the Docker image can take several minutes.
280-
281-
### Deploy the Docker image
282-
283-
After the image is created, use the Azure Machine Learning SDK to deploy the image as a web service.
266+
Use the Azure Machine Learning SDK to deploy the model as a web service.
284267
285268
First, specify the deployment configuration. Azure Container Instance (ACI) is a suitable choice for a quick dev-test deployment, while Azure Kubernetes Service (AKS) is suitable for scalable production deployments.
286269
@@ -299,30 +282,21 @@ aci_config = AciWebservice.deploy_configuration(cpu_cores=1,
299282
location='eastus2')
300283
```
301284
302-
Then, deploy the image by using the Azure Machine Learning SDK [deploy_from_image()](/python/api/azureml-core/azureml.core.webservice.webservice(class)?view=azure-ml-py#deploy-from-image-workspace--name--image--deployment-config-none--deployment-target-none--overwrite-false-) method.
285+
Then, register and deploy the model by using the Azure Machine Learning SDK [deploy](/python/api/azureml-core/azureml.core.model.model?view=azure-ml-py#deploy-workspace--name--models--inference-config-none--deployment-config-none--deployment-target-none--overwrite-false-) method.
303286
304287
```python
305-
webservice = Webservice.deploy_from_image( image=azure_image,
306-
workspace=ws,
307-
name='diabetes-model-1',
308-
deployment_config=aci_config)
288+
(webservice,model) = mlflow.azureml.deploy( model_uri='runs:/{}/{}'.format(run.id, model_path),
289+
workspace=ws,
290+
model_name='sklearn-model',
291+
service_name='diabetes-model-1',
292+
deployment_config=aci_config,
293+
tags=None, mlflow_home=None, synchronous=True)
309294
310295
webservice.wait_for_deployment(show_output=True)
311296
```
312297
#### Deploy to AKS
313298
314-
To deploy to AKS, first create an AKS cluster and bring over the Docker image you want to deploy. For this example, bring over the previously created image from the ACI deployment.
315-
316-
To get the image from the previous ACI deployment use the [Image](https://docs.microsoft.com/python/api/azureml-core/azureml.core.image.image.image?view=azure-ml-py) class.
317-
318-
```python
319-
from azureml.core.image import Image
320-
321-
# Get the image by name, you can change this based on the image you want to deploy
322-
myimage = Image(workspace=ws, name='sklearn-image')
323-
```
324-
325-
Create an AKS cluster using the [ComputeTarget.create()](https://docs.microsoft.com/python/api/azureml-core/azureml.core.computetarget?view=azure-ml-py#create-workspace--name--provisioning-configuration-) method. It may take 20-25 minutes to create a new cluster.
299+
To deploy to AKS, first create an AKS cluster. Create an AKS cluster using the [ComputeTarget.create()](https://docs.microsoft.com/python/api/azureml-core/azureml.core.computetarget?view=azure-ml-py#create-workspace--name--provisioning-configuration-) method. It may take 20-25 minutes to create a new cluster.
326300
327301
```python
328302
from azureml.core.compute import AksCompute, ComputeTarget
@@ -346,26 +320,25 @@ Set up your deployment configuration with the [deploy_configuration()](https://d
346320
347321
```python
348322
from azureml.core.webservice import Webservice, AksWebservice
349-
from azureml.core.image import ContainerImage
350323
351324
# Set the web service configuration (using default here with app insights)
352-
aks_config = AksWebservice.deploy_configuration(enable_app_insights=True)
325+
aks_config = AksWebservice.deploy_configuration(enable_app_insights=True, compute_target_name='aks-mlflow')
353326
354-
# Unique service name
355-
service_name ='aks-service'
356-
```
357327
358-
Then, deploy the image by using the Azure Machine Learning SDK [deploy_from_image()](/python/api/azureml-core/azureml.core.webservice.webservice(class)?view=azure-ml-py#deploy-from-image-workspace--name--image--deployment-config-none--deployment-target-none--overwrite-false-) method.
328+
Then, deploy the image by using the Azure Machine Learning SDK [deploy()](Then, register and deploy the model by using the Azure Machine Learning SDK [deploy](/python/api/azureml-core/azureml.core.model.model?view=azure-ml-py#deploy-workspace--name--models--inference-config-none--deployment-config-none--deployment-target-none--overwrite-false-) method.
359329
360330
```python
361331
# Webservice creation using single command
362-
aks_service = Webservice.deploy_from_image( workspace=ws,
363-
name=service_name,
364-
deployment_config = aks_config
365-
image = myimage,
366-
deployment_target = aks_target)
332+
from azureml.core.webservice import AksWebservice, Webservice
333+
(webservice, model) = mlflow.azureml.deploy( model_uri='runs:/{}/{}'.format(run.id, model_path),
334+
workspace=ws,
335+
model_name='sklearn-model',
336+
service_name='my-aks',
337+
deployment_config=aks_config,
338+
tags=None, mlflow_home=None, synchronous=True)
339+
367340
368-
aks_service.wait_for_deployment(show_output=True)
341+
webservice.wait_for_deployment()
369342
```
370343
371344
The service deployment can take several minutes.

0 commit comments

Comments
 (0)