@@ -2101,7 +2101,7 @@ def deploy(
2101
2101
if not display_name :
2102
2102
display_name = utils .get_random_name_for_resource ()
2103
2103
# populates properties from args and kwargs. Empty values will be ignored.
2104
- self . properties . with_dict ( _extract_locals (locals () ))
2104
+ override_properties = _extract_locals (locals ())
2105
2105
# clears out project_id and compartment_id from kwargs, to prevent passing
2106
2106
# these params to the deployment via kwargs.
2107
2107
kwargs .pop ("project_id" , None )
@@ -2110,19 +2110,51 @@ def deploy(
2110
2110
max_wait_time = kwargs .pop ("max_wait_time" , DEFAULT_WAIT_TIME )
2111
2111
poll_interval = kwargs .pop ("poll_interval" , DEFAULT_POLL_INTERVAL )
2112
2112
2113
- self .properties .compartment_id = (
2114
- self .properties .compartment_id or _COMPARTMENT_OCID
2115
- )
2116
- self .properties .project_id = self .properties .project_id or PROJECT_OCID
2117
- self .properties .deployment_instance_shape = (
2118
- self .properties .deployment_instance_shape or MODEL_DEPLOYMENT_INSTANCE_SHAPE
2119
- )
2120
- self .properties .deployment_instance_count = (
2121
- self .properties .deployment_instance_count or MODEL_DEPLOYMENT_INSTANCE_COUNT
2122
- )
2123
- self .properties .deployment_bandwidth_mbps = (
2124
- self .properties .deployment_bandwidth_mbps or MODEL_DEPLOYMENT_BANDWIDTH_MBPS
2125
- )
2113
+ existing_infrastructure = self .model_deployment .infrastructure
2114
+ existing_runtime = self .model_deployment .runtime
2115
+ properties = {
2116
+ "compartment_id" : existing_infrastructure .compartment_id
2117
+ or self .properties .compartment_id
2118
+ or _COMPARTMENT_OCID ,
2119
+ "project_id" : existing_infrastructure .project_id
2120
+ or self .properties .project_id
2121
+ or PROJECT_OCID ,
2122
+ "deployment_instance_shape" : existing_infrastructure .shape_name
2123
+ or self .properties .deployment_instance_shape
2124
+ or MODEL_DEPLOYMENT_INSTANCE_SHAPE ,
2125
+ "deployment_instance_count" : existing_infrastructure .replica
2126
+ or self .properties .deployment_instance_count
2127
+ or MODEL_DEPLOYMENT_INSTANCE_COUNT ,
2128
+ "deployment_bandwidth_mbps" : existing_infrastructure .bandwidth_mbps
2129
+ or self .properties .deployment_bandwidth_mbps
2130
+ or MODEL_DEPLOYMENT_BANDWIDTH_MBPS ,
2131
+ "deployment_ocpus" : existing_infrastructure .shape_config_details .get (
2132
+ "ocpus" , None
2133
+ )
2134
+ or self .properties .deployment_ocpus
2135
+ or MODEL_DEPLOYMENT_INSTANCE_OCPUS ,
2136
+ "deployment_memory_in_gbs" : existing_infrastructure .shape_config_details .get (
2137
+ "memory_in_gbs" , None
2138
+ )
2139
+ or self .properties .deployment_memory_in_gbs
2140
+ or MODEL_DEPLOYMENT_INSTANCE_MEMORY_IN_GBS ,
2141
+ "deployment_log_group_id" : existing_infrastructure .log_group_id
2142
+ or self .properties .deployment_log_group_id ,
2143
+ "deployment_access_log_id" : existing_infrastructure .access_log .get (
2144
+ "log_id" , None
2145
+ )
2146
+ or self .properties .deployment_access_log_id ,
2147
+ "deployment_predict_log_id" : existing_infrastructure .predict_log .get (
2148
+ "log_id" , None
2149
+ )
2150
+ or self .properties .deployment_predict_log_id ,
2151
+ "deployment_image" : existing_runtime .image
2152
+ or self .properties .deployment_image ,
2153
+ "deployment_instance_subnet_id" : existing_infrastructure .subnet_id
2154
+ or self .properties .deployment_instance_subnet_id
2155
+ }
2156
+ properties .update (override_properties )
2157
+ self .properties .with_dict (properties )
2126
2158
2127
2159
if not self .model_id :
2128
2160
raise ValueError (
@@ -2140,104 +2172,58 @@ def deploy(
2140
2172
"cannot be used without `deployment_log_group_id`."
2141
2173
)
2142
2174
2143
- existing_infrastructure = self .model_deployment .infrastructure
2144
- existing_runtime = self .model_deployment .runtime
2145
-
2146
- web_concurrency = (
2147
- kwargs .pop ("web_concurrency" , None )
2148
- or existing_infrastructure .web_concurrency
2149
- )
2150
- if not (
2151
- self .properties .compartment_id or existing_infrastructure .compartment_id
2152
- ):
2175
+ if not self .properties .compartment_id :
2153
2176
raise ValueError ("`compartment_id` has to be provided." )
2154
- if not ( self .properties .project_id or existing_infrastructure . project_id ) :
2177
+ if not self .properties .project_id :
2155
2178
raise ValueError ("`project_id` has to be provided." )
2156
2179
infrastructure = (
2157
2180
ModelDeploymentInfrastructure ()
2158
- .with_compartment_id (
2159
- self .properties .compartment_id or existing_infrastructure .compartment_id
2160
- )
2161
- .with_project_id (
2162
- self .properties .project_id or existing_infrastructure .project_id
2163
- )
2164
- .with_bandwidth_mbps (
2165
- self .properties .deployment_bandwidth_mbps
2166
- or existing_infrastructure .bandwidth_mbps
2167
- )
2168
- .with_shape_name (
2169
- self .properties .deployment_instance_shape
2170
- or existing_infrastructure .shape_name
2171
- )
2172
- .with_subnet_id (
2173
- self .properties .deployment_instance_subnet_id
2174
- or existing_infrastructure .subnet_id
2175
- )
2176
- .with_replica (
2177
- self .properties .deployment_instance_count
2178
- or existing_infrastructure .replica
2179
- )
2180
- .with_web_concurrency (web_concurrency )
2181
+ .with_compartment_id (self .properties .compartment_id )
2182
+ .with_project_id (self .properties .project_id )
2183
+ .with_bandwidth_mbps (self .properties .deployment_bandwidth_mbps )
2184
+ .with_shape_name (self .properties .deployment_instance_shape )
2185
+ .with_replica (self .properties .deployment_instance_count )
2186
+ .with_subnet_id (self .properties .deployment_instance_subnet_id )
2181
2187
)
2182
2188
2183
- ocpus = (
2184
- self .properties .deployment_ocpus
2185
- or existing_infrastructure .shape_config_details .get ("ocpus" )
2186
- )
2187
- memory_in_gbs = (
2188
- self .properties .deployment_memory_in_gbs
2189
- or existing_infrastructure .shape_config_details .get ("memory_in_gbs" )
2189
+ web_concurrency = (
2190
+ kwargs .pop ("web_concurrency" , None )
2191
+ or existing_infrastructure .web_concurrency
2190
2192
)
2193
+ if web_concurrency :
2194
+ infrastructure .with_web_concurrency (web_concurrency )
2191
2195
2192
2196
if infrastructure .shape_name .endswith ("Flex" ):
2193
2197
infrastructure .with_shape_config_details (
2194
- ocpus = ocpus or MODEL_DEPLOYMENT_INSTANCE_OCPUS ,
2195
- memory_in_gbs = memory_in_gbs or MODEL_DEPLOYMENT_INSTANCE_MEMORY_IN_GBS ,
2198
+ ocpus = self . properties . deployment_ocpus ,
2199
+ memory_in_gbs = self . properties . deployment_memory_in_gbs ,
2196
2200
)
2197
2201
2198
- access_log_id = (
2199
- self .properties .deployment_access_log_id
2200
- or existing_infrastructure .access_log .get ("log_id" )
2201
- )
2202
- access_log_group_id = (
2203
- self .properties .deployment_log_group_id
2204
- or existing_infrastructure .access_log .get ("log_group_id" )
2205
- )
2206
-
2207
2202
# specifies the access log id
2208
- if access_log_id :
2203
+ if self . properties . deployment_access_log_id :
2209
2204
infrastructure .with_access_log (
2210
- log_group_id = access_log_group_id ,
2211
- log_id = access_log_id ,
2205
+ log_group_id = self . properties . deployment_log_group_id ,
2206
+ log_id = self . properties . deployment_access_log_id ,
2212
2207
)
2213
2208
2214
- predict_log_id = (
2215
- self .properties .deployment_predict_log_id
2216
- or existing_infrastructure .predict_log .get ("log_id" )
2217
- )
2218
- predict_log_group_id = (
2219
- self .properties .deployment_log_group_id
2220
- or existing_infrastructure .predict_log .get ("log_group_id" )
2221
- )
2222
-
2223
2209
# specifies the predict log id
2224
- if predict_log_id :
2210
+ if self . properties . deployment_predict_log_id :
2225
2211
infrastructure .with_predict_log (
2226
- log_group_id = predict_log_group_id ,
2227
- log_id = predict_log_id ,
2212
+ log_group_id = self . properties . deployment_log_group_id ,
2213
+ log_id = self . properties . deployment_predict_log_id ,
2228
2214
)
2229
2215
2230
2216
environment_variables = (
2231
2217
kwargs .pop ("environment_variables" , {}) or existing_runtime .env
2232
2218
)
2233
2219
deployment_mode = (
2234
- kwargs .pop ("deployment_mode" , ModelDeploymentMode . HTTPS )
2220
+ kwargs .pop ("deployment_mode" , None )
2235
2221
or existing_runtime .deployment_mode
2222
+ or ModelDeploymentMode .HTTPS
2236
2223
)
2237
2224
2238
2225
runtime = None
2239
- image = self .properties .deployment_image or existing_runtime .image
2240
- if image :
2226
+ if self .properties .deployment_image :
2241
2227
image_digest = (
2242
2228
kwargs .pop ("image_digest" , None ) or existing_runtime .image_digest
2243
2229
)
@@ -2252,7 +2238,7 @@ def deploy(
2252
2238
)
2253
2239
runtime = (
2254
2240
ModelDeploymentContainerRuntime ()
2255
- .with_image (image )
2241
+ .with_image (self . properties . deployment_image )
2256
2242
.with_image_digest (image_digest )
2257
2243
.with_cmd (cmd )
2258
2244
.with_entrypoint (entrypoint )
0 commit comments