Created
June 5, 2020 07:11
-
-
Save korkridake/4c2011c4605648d2a973a37c45be7ae3 to your computer and use it in GitHub Desktop.
MLOps Ep.4 Productionizing Evaluation and Deployment Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import azureml.core | |
# Display the core SDK version number | |
print("Azure ML SDK Version: ", azureml.core.VERSION) | |
# Define an environment | |
from azureml.core.environment import Environment | |
from azureml.core.conda_dependencies import CondaDependencies | |
# to install required packages | |
env = Environment('sklearn-usedcars-env') | |
cd = CondaDependencies.create(pip_packages=['azureml-dataprep[pandas,fuse]>=1.1.14', 'azureml-defaults'], conda_packages = ['scikit-learn==0.22.1']) | |
env.python.conda_dependencies = cd | |
# Register environment to re-use later | |
env.register(workspace = ws) | |
# Create a deployment configuration file | |
from azureml.core.webservice import AciWebservice | |
aciconfig = AciWebservice.deploy_configuration(cpu_cores=1, | |
memory_gb=1, | |
tags={"data": "usedcars", "method" : "sklearn"}, | |
description='Predict the price of used cars with sklearn regressors') | |
# Deploy in ACI | |
%%time | |
from azureml.core.webservice import Webservice | |
from azureml.core.model import InferenceConfig | |
from azureml.core.environment import Environment | |
from azureml.core import Workspace | |
from azureml.core.model import Model | |
ws = Workspace.from_config() | |
model = Model(ws, 'sklearn_regression_model') | |
myenv = Environment.get(workspace=ws, name="sklearn-usedcars-env", version="1") | |
inference_config = InferenceConfig(entry_script="score.py", environment=myenv) | |
service = Model.deploy(workspace=ws, | |
name='sklearn-usedcars-mlprod', | |
models = [model], | |
inference_config = inference_config, | |
deployment_config = aciconfig) | |
service.wait_for_deployment(show_output=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment