mirror of
https://github.com/Azure/MachineLearningNotebooks.git
synced 2025-12-20 01:27:06 -05:00
Compare commits
18 Commits
azureml-sd
...
cli-ga
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01e188d61f | ||
|
|
7a754faa7e | ||
|
|
78f8ec3d24 | ||
|
|
6120c6897f | ||
|
|
8c4168dfa1 | ||
|
|
8580dcc01b | ||
|
|
5443b05152 | ||
|
|
afec974f09 | ||
|
|
d6b558f88d | ||
|
|
70c021eb69 | ||
|
|
550abc7167 | ||
|
|
6c12043732 | ||
|
|
2f3f1ff756 | ||
|
|
05f056a692 | ||
|
|
8e559ef577 | ||
|
|
a8e4fc2f9a | ||
|
|
f5e4df0864 | ||
|
|
13d0d9baf1 |
@@ -1,4 +1,5 @@
|
||||
# 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).
|
||||
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
|
||||
You can deploy to the cloud using the Azure ML CLI or the Azure ML SDK.
|
||||
- CLI example: https://aka.ms/azmlcli
|
||||
|
||||
### 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)
|
||||
[](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).
|
||||
@@ -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'
|
||||
5
how-to-use-azureml/deploy-to-cloud/deploymentConfig.yml
Normal file
5
how-to-use-azureml/deploy-to-cloud/deploymentConfig.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
containerResourceRequirements:
|
||||
cpu: 1
|
||||
memoryInGB: 1
|
||||
computeType: ACI
|
||||
7
how-to-use-azureml/deploy-to-cloud/deploymentconfig.json
Normal file
7
how-to-use-azureml/deploy-to-cloud/deploymentconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"containerResourceRequirements": {
|
||||
"cpu": 1,
|
||||
"memoryInGB": 1
|
||||
},
|
||||
"computeType": "ACI"
|
||||
}
|
||||
9
how-to-use-azureml/deploy-to-cloud/inferenceConfig.yml
Normal file
9
how-to-use-azureml/deploy-to-cloud/inferenceConfig.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
entryScript: score.py
|
||||
runtime: python
|
||||
condaFile: myenv.yml
|
||||
extraDockerfileSteps:
|
||||
schemaFile:
|
||||
dependencies:
|
||||
enableGpu: False
|
||||
baseImage:
|
||||
baseImageRegistry:
|
||||
11
how-to-use-azureml/deploy-to-cloud/inferenceconfig.json
Normal file
11
how-to-use-azureml/deploy-to-cloud/inferenceconfig.json
Normal 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
|
||||
}
|
||||
8
how-to-use-azureml/deploy-to-cloud/mylib.py
Normal file
8
how-to-use-azureml/deploy-to-cloud/mylib.py
Normal 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)
|
||||
45
how-to-use-azureml/deploy-to-cloud/train.py
Normal file
45
how-to-use-azureml/deploy-to-cloud/train.py
Normal 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))
|
||||
Reference in New Issue
Block a user