forked from microsoft/MLOpsPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_scoring_image.py
61 lines (49 loc) · 1.65 KB
/
create_scoring_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
from azureml.core import Workspace
from azureml.core.image import ContainerImage, Image
from azureml.core.model import Model
from dotenv import load_dotenv
from azureml.core.authentication import ServicePrincipalAuthentication
load_dotenv()
TENANT_ID = os.environ.get('TENANT_ID')
APP_ID = os.environ.get('SP_APP_ID')
APP_SECRET = os.environ.get('SP_APP_SECRET')
WORKSPACE_NAME = os.environ.get("BASE_NAME")+"-AML-WS"
SUBSCRIPTION_ID = os.environ.get('SUBSCRIPTION_ID')
RESOURCE_GROUP = os.environ.get("BASE_NAME")+"-AML-RG"
MODEL_NAME = os.environ.get('MODEL_NAME')
MODEL_VERSION = os.environ.get('MODEL_VERSION')
IMAGE_NAME = os.environ.get('IMAGE_NAME')
SP_AUTH = ServicePrincipalAuthentication(
tenant_id=TENANT_ID,
service_principal_id=APP_ID,
service_principal_password=APP_SECRET)
ws = Workspace.get(
WORKSPACE_NAME,
SP_AUTH,
SUBSCRIPTION_ID,
RESOURCE_GROUP
)
model = Model(ws, name=MODEL_NAME, version=MODEL_VERSION)
os.chdir("./code/scoring")
image_config = ContainerImage.image_configuration(
execution_script="score.py",
runtime="python",
conda_file="conda_dependencies.yml",
description="Image with ridge regression model",
tags={"area": "diabetes", "type": "regression"},
)
image = Image.create(
name=IMAGE_NAME, models=[model], image_config=image_config, workspace=ws
)
image.wait_for_creation(show_output=True)
if image.creation_state != "Succeeded":
raise Exception("Image creation status: {image.creation_state}")
print("{}(v.{} [{}]) stored at {} with build log {}".format(
image.name,
image.version,
image.creation_state,
image.image_location,
image.image_build_log_uri,
)
)