@@ -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,55 @@ 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
+ # GenericModel itself has a ModelDeployment instance. When calling deploy(),
2114
+ # if there are parameters passed in they will override this ModelDeployment instance,
2115
+ # otherwise the properties of the ModelDeployment instance will be applied for deployment.
2116
+ existing_infrastructure = self .model_deployment .infrastructure
2117
+ existing_runtime = self .model_deployment .runtime
2118
+ property_dict = ModelProperties (
2119
+ compartment_id = existing_infrastructure .compartment_id
2120
+ or self .properties .compartment_id
2121
+ or _COMPARTMENT_OCID ,
2122
+ project_id = existing_infrastructure .project_id
2123
+ or self .properties .project_id
2124
+ or PROJECT_OCID ,
2125
+ deployment_instance_shape = existing_infrastructure .shape_name
2126
+ or self .properties .deployment_instance_shape
2127
+ or MODEL_DEPLOYMENT_INSTANCE_SHAPE ,
2128
+ deployment_instance_count = existing_infrastructure .replica
2129
+ or self .properties .deployment_instance_count
2130
+ or MODEL_DEPLOYMENT_INSTANCE_COUNT ,
2131
+ deployment_bandwidth_mbps = existing_infrastructure .bandwidth_mbps
2132
+ or self .properties .deployment_bandwidth_mbps
2133
+ or MODEL_DEPLOYMENT_BANDWIDTH_MBPS ,
2134
+ deployment_ocpus = existing_infrastructure .shape_config_details .get (
2135
+ "ocpus" , None
2136
+ )
2137
+ or self .properties .deployment_ocpus
2138
+ or MODEL_DEPLOYMENT_INSTANCE_OCPUS ,
2139
+ deployment_memory_in_gbs = existing_infrastructure .shape_config_details .get (
2140
+ "memoryInGBs" , None
2141
+ )
2142
+ or self .properties .deployment_memory_in_gbs
2143
+ or MODEL_DEPLOYMENT_INSTANCE_MEMORY_IN_GBS ,
2144
+ deployment_log_group_id = existing_infrastructure .log_group_id
2145
+ or self .properties .deployment_log_group_id ,
2146
+ deployment_access_log_id = existing_infrastructure .access_log .get (
2147
+ "log_id" , None
2148
+ )
2149
+ or self .properties .deployment_access_log_id ,
2150
+ deployment_predict_log_id = existing_infrastructure .predict_log .get (
2151
+ "log_id" , None
2152
+ )
2153
+ or self .properties .deployment_predict_log_id ,
2154
+ deployment_image = existing_runtime .image
2155
+ or self .properties .deployment_image ,
2156
+ deployment_instance_subnet_id = existing_infrastructure .subnet_id
2157
+ or self .properties .deployment_instance_subnet_id
2158
+ ).to_dict ()
2159
+
2160
+ property_dict .update (override_properties )
2161
+ self .properties .with_dict (property_dict )
2126
2162
2127
2163
if not self .model_id :
2128
2164
raise ValueError (
@@ -2140,104 +2176,58 @@ def deploy(
2140
2176
"cannot be used without `deployment_log_group_id`."
2141
2177
)
2142
2178
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
- ):
2179
+ if not self .properties .compartment_id :
2153
2180
raise ValueError ("`compartment_id` has to be provided." )
2154
- if not ( self .properties .project_id or existing_infrastructure . project_id ) :
2181
+ if not self .properties .project_id :
2155
2182
raise ValueError ("`project_id` has to be provided." )
2156
2183
infrastructure = (
2157
2184
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 )
2185
+ .with_compartment_id (self .properties .compartment_id )
2186
+ .with_project_id (self .properties .project_id )
2187
+ .with_bandwidth_mbps (self .properties .deployment_bandwidth_mbps )
2188
+ .with_shape_name (self .properties .deployment_instance_shape )
2189
+ .with_replica (self .properties .deployment_instance_count )
2190
+ .with_subnet_id (self .properties .deployment_instance_subnet_id )
2181
2191
)
2182
2192
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" )
2193
+ web_concurrency = (
2194
+ kwargs .pop ("web_concurrency" , None )
2195
+ or existing_infrastructure .web_concurrency
2190
2196
)
2197
+ if web_concurrency :
2198
+ infrastructure .with_web_concurrency (web_concurrency )
2191
2199
2192
2200
if infrastructure .shape_name .endswith ("Flex" ):
2193
2201
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 ,
2202
+ ocpus = self . properties . deployment_ocpus ,
2203
+ memory_in_gbs = self . properties . deployment_memory_in_gbs ,
2196
2204
)
2197
2205
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
2206
# specifies the access log id
2208
- if access_log_id :
2207
+ if self . properties . deployment_access_log_id :
2209
2208
infrastructure .with_access_log (
2210
- log_group_id = access_log_group_id ,
2211
- log_id = access_log_id ,
2209
+ log_group_id = self . properties . deployment_log_group_id ,
2210
+ log_id = self . properties . deployment_access_log_id ,
2212
2211
)
2213
2212
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
2213
# specifies the predict log id
2224
- if predict_log_id :
2214
+ if self . properties . deployment_predict_log_id :
2225
2215
infrastructure .with_predict_log (
2226
- log_group_id = predict_log_group_id ,
2227
- log_id = predict_log_id ,
2216
+ log_group_id = self . properties . deployment_log_group_id ,
2217
+ log_id = self . properties . deployment_predict_log_id ,
2228
2218
)
2229
2219
2230
2220
environment_variables = (
2231
2221
kwargs .pop ("environment_variables" , {}) or existing_runtime .env
2232
2222
)
2233
2223
deployment_mode = (
2234
- kwargs .pop ("deployment_mode" , ModelDeploymentMode . HTTPS )
2224
+ kwargs .pop ("deployment_mode" , None )
2235
2225
or existing_runtime .deployment_mode
2226
+ or ModelDeploymentMode .HTTPS
2236
2227
)
2237
2228
2238
2229
runtime = None
2239
- image = self .properties .deployment_image or existing_runtime .image
2240
- if image :
2230
+ if self .properties .deployment_image :
2241
2231
image_digest = (
2242
2232
kwargs .pop ("image_digest" , None ) or existing_runtime .image_digest
2243
2233
)
@@ -2252,7 +2242,7 @@ def deploy(
2252
2242
)
2253
2243
runtime = (
2254
2244
ModelDeploymentContainerRuntime ()
2255
- .with_image (image )
2245
+ .with_image (self . properties . deployment_image )
2256
2246
.with_image_digest (image_digest )
2257
2247
.with_cmd (cmd )
2258
2248
.with_entrypoint (entrypoint )
0 commit comments