10
10
from ._registry_utils import get_registry_model
11
11
12
12
13
+ def get_empty_deployment_arm_template ():
14
+ return {
15
+ "$schema" : "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#" ,
16
+ "contentVersion" : "1.0.0.0" ,
17
+ "parameters" : {
18
+ "onlineEndpointProperties" : {
19
+ "defaultValue" : {
20
+ "authMode" : "Key" ,
21
+ "publicNetworkAccess" : "Enabled" ,
22
+ "properties" : {
23
+ "enforce_access_to_default_secret_stores" : "enabled"
24
+ },
25
+ },
26
+ "type" : "Object" ,
27
+ },
28
+ "onlineEndpointPropertiesTrafficUpdate" : {
29
+ "defaultValue" : {
30
+ "traffic" : {"[parameters('onlineDeploymentName')]" : 100 },
31
+ "authMode" : "Key" ,
32
+ "publicNetworkAccess" : "Enabled" ,
33
+ "properties" : {
34
+ "enforce_access_to_default_secret_stores" : "enabled"
35
+ },
36
+ },
37
+ "type" : "Object" ,
38
+ },
39
+ },
40
+ "resources" : [
41
+ {
42
+ "type" : "Microsoft.MachineLearningServices/workspaces/onlineEndpoints" ,
43
+ "apiVersion" : "2023-04-01-Preview" ,
44
+ "name" : "[concat(parameters('workspaceName'), '/', parameters('onlineEndpointName'))]" ,
45
+ "location" : "[parameters('location')]" ,
46
+ "identity" : {"type" : "SystemAssigned" },
47
+ "properties" : "[parameters('onlineEndpointProperties')]" ,
48
+ "copy" : {"name" : "onlineEndpointCopy" , "count" : 1 , "mode" : "serial" },
49
+ },
50
+ {
51
+ "type" : "Microsoft.MachineLearningServices/workspaces/onlineEndpoints/deployments" ,
52
+ "apiVersion" : "2023-04-01-Preview" ,
53
+ "name" : "[concat(parameters('workspaceName'), '/', parameters('onlineEndpointName'), '/', parameters('onlineDeploymentName'))]" ,
54
+ "location" : "[parameters('location')]" ,
55
+ "dependsOn" : [
56
+ "onlineEndpointCopy" ,
57
+ ],
58
+ "sku" : {"capacity" : "[parameters('deploymentInstanceCount')]" , "name" : "default" },
59
+ "identity" : {"type" : "None" },
60
+ "properties" : "[parameters('onlineDeploymentProperties')]" ,
61
+ "copy" : {"name" : "onlineDeploymentCopy" , "count" : 1 , "mode" : "serial" },
62
+ },
63
+ {
64
+ "type" : "Microsoft.Resources/deployments" ,
65
+ "apiVersion" : "2015-01-01" ,
66
+ "name" : "[concat('updateEndpointWithTraffic', '-', parameters('onlineEndpointName'))]" ,
67
+ "dependsOn" : ["onlineDeploymentCopy" ],
68
+ "properties" : {
69
+ "mode" : "Incremental" ,
70
+ "template" : {
71
+ "$schema" : "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#" ,
72
+ "contentVersion" : "1.0.0.0" ,
73
+ "resources" : [
74
+ {
75
+ "type" : "Microsoft.MachineLearningServices/workspaces/onlineEndpoints" ,
76
+ "apiVersion" : "2023-04-01-Preview" ,
77
+ "location" : "[parameters('location')]" ,
78
+ "name" : "[concat(parameters('workspaceName'), '/', parameters('onlineEndpointName'))]" ,
79
+ "properties" : "[parameters('onlineEndpointPropertiesTrafficUpdate')]" ,
80
+ "identity" : {"type" : "SystemAssigned" },
81
+ }
82
+ ],
83
+ },
84
+ },
85
+ },
86
+ ],
87
+ "outputs" : {
88
+ "online_endpoint_name" : {
89
+ "type" : "string" ,
90
+ "value" : "[parameters('onlineEndpointName')]" ,
91
+ },
92
+ "online_deployment_name" : {
93
+ "type" : "string" ,
94
+ "value" : "[parameters('onlineDeploymentName')]" ,
95
+ },
96
+ },
97
+ }
98
+
99
+
13
100
def get_default_allowed_instance_type_for_hugging_face (
14
101
model_details : Model , credential : Any
15
102
) -> Tuple [str , str ]:
@@ -23,31 +110,46 @@ def get_default_allowed_instance_type_for_hugging_face(
23
110
hf_engines = hf_engines .split ("," )
24
111
if len (hf_engines ) > 1 :
25
112
for engine_id in hf_engines :
26
- instance_type , instance_type_list = get_default_allowed_instance_type_from_model_engine (engine_id , credential )
113
+ (
114
+ instance_type ,
115
+ instance_type_list ,
116
+ ) = get_default_allowed_instance_type_from_model_engine (
117
+ engine_id , credential
118
+ )
27
119
if "cpu" in engine_id :
28
120
default_instance_type = instance_type
29
121
allowed_instance_types .append (instance_type_list )
30
122
else :
31
123
# if the model has only one engine, we can proceed with that as the default engine for SKU
32
124
# selection
33
- default_instance_type , allowed_instance_types = get_default_allowed_instance_type_from_model_engine (hf_engines [0 ], credential )
125
+ (
126
+ default_instance_type ,
127
+ allowed_instance_types ,
128
+ ) = get_default_allowed_instance_type_from_model_engine (
129
+ hf_engines [0 ], credential
130
+ )
34
131
else :
35
- default_instance_type , allowed_instance_types = parse_deployment_config (deployment_config )
132
+ default_instance_type , allowed_instance_types = parse_deployment_config (
133
+ deployment_config
134
+ )
36
135
return (default_instance_type , allowed_instance_types )
37
136
38
137
39
138
def parse_deployment_config (deployment_config : str ):
40
139
deployment_config = json .loads (deployment_config )
41
- allowed_instance_types = deployment_config ["PipelineMetadata" ]["PipelineDefinition" ]["ec" ]["AllowedInstanceTypes" ]
42
- default_instance_type = deployment_config ["PipelineMetadata" ]["PipelineDefinition" ]["ec" ]["DefaultInstanceType" ]
140
+ allowed_instance_types = deployment_config ["PipelineMetadata" ][
141
+ "PipelineDefinition"
142
+ ]["ec" ]["AllowedInstanceTypes" ]
143
+ default_instance_type = deployment_config ["PipelineMetadata" ]["PipelineDefinition" ][
144
+ "ec"
145
+ ]["DefaultInstanceType" ]
43
146
44
147
return (default_instance_type , allowed_instance_types )
45
148
46
149
47
- def get_default_allowed_instance_type_from_model_engine (engine_id : str , credential : Any ):
48
- model_details = get_registry_model (
49
- credential ,
50
- id = engine_id
51
- )
150
+ def get_default_allowed_instance_type_from_model_engine (
151
+ engine_id : str , credential : Any
152
+ ):
153
+ model_details = get_registry_model (credential , id = engine_id )
52
154
deployment_config = model_details .properties .get ("modelDeploymentConfig" , None )
53
- return parse_deployment_config (deployment_config )
155
+ return parse_deployment_config (deployment_config )
0 commit comments