Skip to content

Commit 147f6c4

Browse files
authored
Merge branch 'main' into ODSC-39781/deprecate_model_deployment_properties_api
2 parents 60d5b7e + 2dbc2a0 commit 147f6c4

File tree

4 files changed

+331
-58
lines changed

4 files changed

+331
-58
lines changed

ads/model/deployment/model_deployment.py

+22-10
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
)
4545
from ads.common import utils as ads_utils
4646
from .common import utils
47-
from .common.utils import OCIClientManager, State
47+
from .common.utils import State
4848
from .model_deployment_properties import ModelDeploymentProperties
4949
from oci.data_science.models import (
5050
LogDetails,
@@ -205,7 +205,10 @@ class ModelDeployment(Builder):
205205
... .with_health_check_port(<health_check_port>)
206206
... .with_env({"key":"value"})
207207
... .with_deployment_mode("HTTPS_ONLY")
208-
... .with_model_uri(<model_uri>))
208+
... .with_model_uri(<model_uri>)
209+
... .with_bucket_uri(<bucket_uri>)
210+
... .with_auth(<auth>)
211+
... .with_timeout(<time_out>))
209212
... )
210213
... )
211214
>>> ds_model_deployment.deploy()
@@ -1636,15 +1639,24 @@ def _build_model_deployment_configuration_details(self) -> Dict:
16361639

16371640
model_id = runtime.model_uri
16381641
if not model_id.startswith("ocid"):
1639-
model_id = OCIClientManager().prepare_artifact(
1640-
model_uri=runtime.model_uri,
1641-
properties=dict(
1642-
display_name=self.display_name,
1643-
compartment_id=self.infrastructure.compartment_id
1644-
or COMPARTMENT_OCID,
1645-
project_id=self.infrastructure.project_id or PROJECT_OCID,
1646-
),
1642+
1643+
from ads.model.datascience_model import DataScienceModel
1644+
1645+
dsc_model = DataScienceModel(
1646+
name=self.display_name,
1647+
compartment_id=self.infrastructure.compartment_id
1648+
or COMPARTMENT_OCID,
1649+
project_id=self.infrastructure.project_id or PROJECT_OCID,
1650+
artifact=runtime.model_uri,
1651+
).create(
1652+
bucket_uri=runtime.bucket_uri,
1653+
auth=runtime.auth,
1654+
region=runtime.region,
1655+
overwrite_existing_artifact=runtime.overwrite_existing_artifact,
1656+
remove_existing_artifact=runtime.remove_existing_artifact,
1657+
timeout=runtime.timeout
16471658
)
1659+
model_id = dsc_model.id
16481660

16491661
model_configuration_details = {
16501662
infrastructure.CONST_BANDWIDTH_MBPS: infrastructure.bandwidth_mbps

ads/model/deployment/model_deployment_runtime.py

+201
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ class ModelDeploymentRuntime(Builder):
3636
The output stream ids of model deployment.
3737
model_uri: str
3838
The model uri of model deployment.
39+
bucket_uri: str
40+
The OCI Object Storage URI where large size model artifacts will be copied to.
41+
auth: Dict
42+
The default authentication is set using `ads.set_auth` API.
43+
region: str
44+
The destination Object Storage bucket region.
45+
overwrite_existing_artifact: bool
46+
Whether overwrite existing target bucket artifact or not.
47+
remove_existing_artifact: bool
48+
Whether artifacts uploaded to object storage bucket need to be removed or not.
49+
timeout: int
50+
The connection timeout in seconds for the client.
3951
4052
Methods
4153
-------
@@ -49,6 +61,18 @@ class ModelDeploymentRuntime(Builder):
4961
Sets the output stream ids of model deployment
5062
with_model_uri(model_uri)
5163
Sets the model uri of model deployment
64+
with_bucket_uri(bucket_uri)
65+
Sets the bucket uri when uploading large size model.
66+
with_auth(auth)
67+
Sets the default authentication when uploading large size model.
68+
with_region(region)
69+
Sets the region when uploading large size model.
70+
with_overwrite_existing_artifact(overwrite_existing_artifact)
71+
Sets whether to overwrite existing artifact when uploading large size model.
72+
with_remove_existing_artifact(remove_existing_artifact)
73+
Sets whether to remove existing artifact when uploading large size model.
74+
with_timeout(timeout)
75+
Sets the connection timeout when uploading large size model.
5276
"""
5377

5478
CONST_MODEL_ID = "modelId"
@@ -60,6 +84,12 @@ class ModelDeploymentRuntime(Builder):
6084
CONST_INPUT_STREAM_IDS = "inputStreamIds"
6185
CONST_OUTPUT_STREAM_IDS = "outputStreamIds"
6286
CONST_ENVIRONMENT_CONFIG_DETAILS = "environmentConfigurationDetails"
87+
CONST_BUCKET_URI = "bucketUri"
88+
CONST_AUTH = "auth"
89+
CONST_REGION = "region"
90+
CONST_OVERWRITE_EXISTING_ARTIFACT = "overwriteExistingArtifact"
91+
CONST_REMOVE_EXISTING_ARTIFACT = "removeExistingArtifact"
92+
CONST_TIMEOUT = "timeout"
6393

6494
attribute_map = {
6595
CONST_ENV: "env",
@@ -68,6 +98,12 @@ class ModelDeploymentRuntime(Builder):
6898
CONST_OUTPUT_STREAM_IDS: "output_stream_ids",
6999
CONST_DEPLOYMENT_MODE: "deployment_mode",
70100
CONST_MODEL_URI: "model_uri",
101+
CONST_BUCKET_URI: "bucket_uri",
102+
CONST_AUTH: "auth",
103+
CONST_REGION: "region",
104+
CONST_OVERWRITE_EXISTING_ARTIFACT: "overwrite_existing_artifact",
105+
CONST_REMOVE_EXISTING_ARTIFACT: "remove_existing_artifact",
106+
CONST_TIMEOUT: "timeout"
71107
}
72108

73109
ENVIRONMENT_CONFIG_DETAILS_PATH = (
@@ -236,7 +272,172 @@ def with_model_uri(self, model_uri: str) -> "ModelDeploymentRuntime":
236272
The ModelDeploymentRuntime instance (self).
237273
"""
238274
return self.set_spec(self.CONST_MODEL_URI, model_uri)
275+
276+
@property
277+
def bucket_uri(self) -> str:
278+
"""The bucket uri of model.
279+
280+
Returns
281+
-------
282+
str
283+
The bucket uri of model.
284+
"""
285+
return self.get_spec(self.CONST_BUCKET_URI, None)
286+
287+
def with_bucket_uri(self, bucket_uri: str) -> "ModelDeploymentRuntime":
288+
"""Sets the bucket uri of model.
289+
290+
Parameters
291+
----------
292+
bucket_uri: str
293+
The bucket uri of model.
294+
295+
Returns
296+
-------
297+
ModelDeploymentRuntime
298+
The ModelDeploymentRuntime instance (self).
299+
"""
300+
return self.set_spec(self.CONST_BUCKET_URI, bucket_uri)
301+
302+
@property
303+
def auth(self) -> Dict:
304+
"""The auth when uploading large-size model.
305+
306+
Returns
307+
-------
308+
Dict
309+
The auth when uploading large-size model.
310+
"""
311+
return self.get_spec(self.CONST_AUTH, {})
312+
313+
def with_auth(self, auth: Dict) -> "ModelDeploymentRuntime":
314+
"""Sets the auth when uploading large-size model.
315+
316+
Parameters
317+
----------
318+
auth: Dict
319+
The auth when uploading large-size model.
320+
321+
Returns
322+
-------
323+
ModelDeploymentRuntime
324+
The ModelDeploymentRuntime instance (self).
325+
"""
326+
return self.set_spec(self.CONST_AUTH, auth)
327+
328+
@property
329+
def region(self) -> str:
330+
"""The region when uploading large-size model.
239331
332+
Returns
333+
-------
334+
str
335+
The region when uploading large-size model.
336+
"""
337+
return self.get_spec(self.CONST_REGION, None)
338+
339+
def with_region(self, region: str) -> "ModelDeploymentRuntime":
340+
"""Sets the region when uploading large-size model.
341+
342+
Parameters
343+
----------
344+
region: str
345+
The region when uploading large-size model.
346+
347+
Returns
348+
-------
349+
ModelDeploymentRuntime
350+
The ModelDeploymentRuntime instance (self).
351+
"""
352+
return self.set_spec(self.CONST_REGION, region)
353+
354+
@property
355+
def overwrite_existing_artifact(self) -> bool:
356+
"""Overwrite existing artifact when uploading large size model.
357+
358+
Returns
359+
-------
360+
bool
361+
Overwrite existing artifact when uploading large size model.
362+
"""
363+
return self.get_spec(self.CONST_OVERWRITE_EXISTING_ARTIFACT, True)
364+
365+
def with_overwrite_existing_artifact(
366+
self,
367+
overwrite_existing_artifact: bool
368+
) -> "ModelDeploymentRuntime":
369+
"""Sets whether to overwrite existing artifact when uploading large size model.
370+
371+
Parameters
372+
----------
373+
overwrite_existing_artifact: bool
374+
Overwrite existing artifact when uploading large size model.
375+
376+
Returns
377+
-------
378+
ModelDeploymentRuntime
379+
The ModelDeploymentRuntime instance (self).
380+
"""
381+
return self.set_spec(
382+
self.CONST_OVERWRITE_EXISTING_ARTIFACT,
383+
overwrite_existing_artifact
384+
)
385+
386+
@property
387+
def remove_existing_artifact(self) -> bool:
388+
"""Remove existing artifact when uploading large size model.
389+
390+
Returns
391+
-------
392+
bool
393+
Remove existing artifact when uploading large size model.
394+
"""
395+
return self.get_spec(self.CONST_REMOVE_EXISTING_ARTIFACT, True)
396+
397+
def with_remove_existing_artifact(
398+
self,
399+
remove_existing_artifact: bool
400+
) -> "ModelDeploymentRuntime":
401+
"""Sets whether to remove existing artifact when uploading large size model.
402+
403+
Parameters
404+
----------
405+
remove_existing_artifact: bool
406+
Remove existing artifact when uploading large size model.
407+
408+
Returns
409+
-------
410+
ModelDeploymentRuntime
411+
The ModelDeploymentRuntime instance (self).
412+
"""
413+
return self.set_spec(self.CONST_REMOVE_EXISTING_ARTIFACT, remove_existing_artifact)
414+
415+
@property
416+
def timeout(self) -> int:
417+
"""The timeout when uploading large-size model.
418+
419+
Returns
420+
-------
421+
int
422+
The timeout when uploading large-size model.
423+
"""
424+
return self.get_spec(self.CONST_TIMEOUT, None)
425+
426+
def with_timeout(self, timeout: int) -> "ModelDeploymentRuntime":
427+
"""Sets the timeout when uploading large-size model.
428+
429+
Parameters
430+
----------
431+
timeout: int
432+
The timeout when uploading large-size model.
433+
434+
Returns
435+
-------
436+
ModelDeploymentRuntime
437+
The ModelDeploymentRuntime instance (self).
438+
"""
439+
return self.set_spec(self.CONST_TIMEOUT, timeout)
440+
240441
def init(self) -> "ModelDeploymentRuntime":
241442
"""Initializes a starter specification for the runtime.
242443

docs/source/user_guide/model_registration/model_deploy_byoc.rst

+15-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@ Below is an example of deploying model on container runtime using ``ModelDeploym
114114
.with_health_check_port(5000)
115115
.with_env({"key":"value"})
116116
.with_deployment_mode("HTTPS_ONLY")
117-
.with_model_uri("<MODEL_URI>")
117+
.with_model_uri("<path_to_artifact>")
118+
.with_auth({"auth_key":"auth_value"})
119+
.with_region("us-ashburn-1")
120+
.with_overwrite_existing_artifact(True)
121+
.with_remove_existing_artifact(True)
122+
.with_timeout(100)
123+
.with_bucket_uri("oci://<bucket>@<namespace>/<prefix>")
118124
)
119125

120126
# configure model deployment
@@ -169,14 +175,21 @@ Below is an example of deploying model on container runtime using ``ModelDeploym
169175
kind: runtime
170176
type: container
171177
spec:
172-
modelUri: <MODEL_URI>
178+
modelUri: <path_to_artifact>
173179
image: iad.ocir.io/<namespace>/<image>:<tag>
174180
imageDigest: <IMAGE_DIGEST>
175181
entrypoint: ["python","/opt/ds/model/deployed_model/api.py"]
176182
serverPort: 5000
177183
healthCheckPort: 5000
178184
env:
179185
WEB_CONCURRENCY: "10"
186+
auth:
187+
auth_key: auth_value
188+
region: us-ashburn-1
189+
overwriteExistingArtifact: True
190+
removeExistingArtifact: True
191+
timeout: 100
192+
bucketUri: oci://<bucket>@<namespace>/<prefix>
180193
deploymentMode: HTTPS_ONLY
181194
"""
182195

0 commit comments

Comments
 (0)