Compare commits

...

18 Commits

Author SHA1 Message Date
Jordan Edwards
01e188d61f Create deploymentconfig.json 2019-04-30 08:02:43 -07:00
Jordan Edwards
7a754faa7e Create inferenceconfig.json 2019-04-30 08:02:06 -07:00
Jordan Edwards
78f8ec3d24 Create mylib.py 2019-04-30 07:36:44 -07:00
Jordan Edwards
6120c6897f Adding sample train.py file 2019-04-30 07:36:12 -07:00
Jordan Edwards
8c4168dfa1 Update README.md 2019-04-28 13:15:14 -07:00
Jordan Edwards
8580dcc01b Update README.md 2019-04-28 13:14:30 -07:00
Jordan Edwards
5443b05152 Update azure-pipelines-model-deploy.yml 2019-04-28 13:06:38 -07:00
Jordan Edwards
afec974f09 Update README.md 2019-04-28 13:06:13 -07:00
Jordan Edwards
d6b558f88d Update README.md 2019-04-28 13:04:26 -07:00
Jordan Edwards
70c021eb69 Update azure-pipelines-model-deploy.yml 2019-04-28 12:59:48 -07:00
Jordan Edwards
550abc7167 Update azure-pipelines-model-deploy.yml 2019-04-28 12:54:29 -07:00
Jordan Edwards
6c12043732 Update README.md 2019-04-28 12:53:59 -07:00
Jordan Edwards
2f3f1ff756 Update azure-pipelines-model-deploy.yml 2019-04-28 12:49:49 -07:00
Jordan Edwards
05f056a692 Update azure-pipelines-model-deploy.yml 2019-04-28 12:49:25 -07:00
Jordan Edwards
8e559ef577 Create azure-pipelines-model-deploy.yml 2019-04-28 12:47:45 -07:00
Jordan Edwards
a8e4fc2f9a Create deploymentConfig.yml 2019-04-28 12:46:20 -07:00
Jordan Edwards
f5e4df0864 Update inferenceConfig.yml 2019-04-28 12:46:00 -07:00
Jordan Edwards
13d0d9baf1 Create inferenceConfig.yml 2019-04-28 12:45:21 -07:00
8 changed files with 150 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
# Model Deployment with Azure ML service # Model Deployment with Azure ML service
You can use Azure Machine Learning to package, debug, validate and deploy inference containers to a variety of compute targets. This process is known as "MLOps" (ML operationalization). You can use Azure Machine Learning to package, debug, validate and deploy inference containers to a variety of compute targets. This process is known as "MLOps" (ML operationalization).
For more information please check out this article: https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-deploy-and-where For more information please check out this article: https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-deploy-and-where
@@ -8,5 +9,17 @@ For more information please check out this article: https://docs.microsoft.com/e
## Deploy to the cloud ## Deploy to the cloud
You can deploy to the cloud using the Azure ML CLI or the Azure ML SDK. You can deploy to the cloud using the Azure ML CLI or the Azure ML SDK.
- CLI example: https://aka.ms/azmlcli
- Notebook example: [model-register-and-deploy](./model-register-and-deploy.ipynb). ### Deploy with the CLI
```
az extension add -n azure-cli-ml
az ml folder attach -w myworkspace -g myresourcegroup
az ml model register -n sklearn_regression_model.pkl -p sklearn_regression_model.pkl -t model.json
az ml model deploy -n acicicd -f model.json --ic inferenceConfig.yml --dc deploymentConfig.yml
```
Here is an [Azure DevOps Pipelines model deployment example](./azure-pipelines-model-deploy.yml)
[![Build Status](https://aidemos.visualstudio.com/azmlcli/_apis/build/status/Azure.MachineLearningNotebooks?branchName=cli-ga)](https://aidemos.visualstudio.com/azmlcli/_build/latest?definitionId=87&branchName=cli-ga)
### Deploy from a notebook
- Notebook example: [model-register-and-deploy](./model-register-and-deploy.ipynb).

View File

@@ -0,0 +1,50 @@
trigger:
- master
pool:
vmImage: 'Ubuntu-16.04'
steps:
- task: DownloadSecureFile@1
inputs:
name: config.json
secureFile: config.json
- script: cp $(Agent.TempDirectory)/config.json $(Build.SourcesDirectory)
- task: AzureCLI@1
displayName: 'Install the CLI'
inputs:
azureSubscription: 'azmldemows'
scriptLocation: inlineScript
inlineScript: 'az extension add -n azure-cli-ml'
- task: AzureCLI@1
displayName: 'Attach folder to workspace'
inputs:
azureSubscription: 'azmldemows'
scriptLocation: inlineScript
inlineScript: 'az ml folder attach'
- task: AzureCLI@1
displayName: 'Register model'
inputs:
azureSubscription: 'azmldemows'
scriptLocation: inlineScript
inlineScript: 'az ml model register -n sklearn_regression_model.pkl -p sklearn_regression_model.pkl -t model.json'
workingDirectory: 'how-to-use-azureml/deploy-to-cloud/'
- task: AzureCLI@1
displayName: 'Deploy model'
inputs:
azureSubscription: 'azmldemows'
scriptLocation: inlineScript
inlineScript: 'az ml model deploy -n acicicd -f model.json --ic inferenceConfig.yml --dc deploymentConfig.yml'
workingDirectory: 'how-to-use-azureml/deploy-to-cloud/'
- task: AzureCLI@1
displayName: 'Delete deployed service'
inputs:
azureSubscription: 'azmldemows'
scriptLocation: inlineScript
inlineScript: 'az ml service delete -n acicicd'

View File

@@ -0,0 +1,5 @@
---
containerResourceRequirements:
cpu: 1
memoryInGB: 1
computeType: ACI

View File

@@ -0,0 +1,7 @@
{
"containerResourceRequirements": {
"cpu": 1,
"memoryInGB": 1
},
"computeType": "ACI"
}

View File

@@ -0,0 +1,9 @@
entryScript: score.py
runtime: python
condaFile: myenv.yml
extraDockerfileSteps:
schemaFile:
dependencies:
enableGpu: False
baseImage:
baseImageRegistry:

View File

@@ -0,0 +1,11 @@
{
"entryScript": "score.py",
"runtime": "python",
"condaFile": "myenv.yml",
"extraDockerfileSteps": null,
"schemaFile": null,
"dependencies": null,
"enableGpu": false,
"baseImage": null,
"baseImageRegistry": null
}

View File

@@ -0,0 +1,8 @@
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license.
import numpy as np
def get_alphas():
# list of numbers from 0.0 to 1.0 with a 0.05 interval
return np.arange(0.0, 1.0, 0.05)

View File

@@ -0,0 +1,45 @@
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license.
from sklearn.datasets import load_diabetes
from sklearn.linear_model import Ridge
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
from azureml.core.run import Run
from sklearn.externals import joblib
import os
import numpy as np
import mylib
os.makedirs('./outputs', exist_ok=True)
X, y = load_diabetes(return_X_y=True)
run = Run.get_context()
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.2,
random_state=0)
data = {"train": {"X": X_train, "y": y_train},
"test": {"X": X_test, "y": y_test}}
# list of numbers from 0.0 to 1.0 with a 0.05 interval
alphas = mylib.get_alphas()
for alpha in alphas:
# Use Ridge algorithm to create a regression model
reg = Ridge(alpha=alpha)
reg.fit(data["train"]["X"], data["train"]["y"])
preds = reg.predict(data["test"]["X"])
mse = mean_squared_error(preds, data["test"]["y"])
run.log('alpha', alpha)
run.log('mse', mse)
model_file_name = 'ridge_{0:.2f}.pkl'.format(alpha)
# save model in the outputs folder so it automatically get uploaded
with open(model_file_name, "wb") as file:
joblib.dump(value=reg, filename=os.path.join('./outputs/',
model_file_name))
print('alpha is {0:.2f}, and mse is {1:0.2f}'.format(alpha, mse))