Skip to content

Commit aaa35f5

Browse files
committed
Updated pr.
1 parent a91bb43 commit aaa35f5

File tree

14 files changed

+371
-278
lines changed

14 files changed

+371
-278
lines changed

docs/source/user_guide/model_deployment/access_a_model_deployment.rst

Lines changed: 0 additions & 13 deletions
This file was deleted.

docs/source/user_guide/model_deployment/accessing.rst

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Activate
2+
********
3+
4+
An inactive model deployment can be activated using a ``ModelDeployment`` object. See `Activate Model Deployments <https://docs.oracle.com/en-us/iaas/data-science/using/model_dep_manage.htm#model_dep_deactivate>`_ for more details.
5+
6+
If you have a ``ModelDeployment`` object, you can use the ``.activate()`` method to activate the model that is associated with that object.
7+
8+
In the following code snippets, the variable ``deployment`` is a ``ModelDeployment`` object. This object can be obtained from a call to ``.deploy()`` or ``.from_id()``.
9+
10+
.. code-block:: python3
11+
12+
deployment.activate(wait_for_completion=True)
13+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Deactivate
2+
**********
3+
4+
An activate model deployment can be deactivated using a ``ModelDeployment`` object. Deactivating a model deployment shuts down the instances that are associated with your deployment. See `Deactivate Model Deployments <https://docs.oracle.com/en-us/iaas/data-science/using/model_dep_manage.htm#model_dep_deactivate>`_ for more details.
5+
6+
If you have a ``ModelDeployment`` object, you can use the ``.deactivate()`` method to deactivate the model that is associated with that object.
7+
8+
In the following code snippets, the variable ``deployment`` is a ``ModelDeployment`` object. This object can be obtained from a call to ``.deploy()`` or ``.from_id()``.
9+
10+
.. code-block:: python3
11+
12+
deployment.deactivate(wait_for_completion=True)
13+

docs/source/user_guide/model_deployment/delete.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ A model deployment can be deleted using a ``ModelDeployment`` object.
55

66
When a model deployment is deleted, it deletes the load balancer instances associated with it. However, it doesn't delete other resources like log group, log, or model.
77

8-
If you have a ``ModelDeployment`` object, you can use the ``.delete()`` method to delete the model that is associated with that object. The optional ``wait_for_completion`` parameter accepts a Boolean and determines if the process is blocking or not.
8+
If you have a ``ModelDeployment`` object, you can use the ``.delete()`` method to delete the model that is associated with that object.
99

1010
In the following code snippets, the variable ``deployment`` is a ``ModelDeployment`` object. This object can be obtained from a call to ``.deploy()`` or ``.from_id()``.
1111

1212
.. code-block:: python3
1313
14-
deployment = deployment.delete(wait_for_completion=True)
14+
deployment.delete(wait_for_completion=True)
1515

docs/source/user_guide/model_deployment/deploy.rst

Lines changed: 115 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
11
Deploy
22
******
33

4-
The ``.deploy()`` method of the ``ModelDeployment`` class is used to create a model deployment. It has the following parameters:
4+
To deploy a model deployment, you'll need to define a ``ModelDeployment`` object and call the ``.deploy()`` of it. You could either use API or YAML to define the ``ModelDeployment`` object.
55

6-
* ``max_wait_time``: The timeout limit, in seconds, for the deployment process to wait until it is active. Defaults to 1200 seconds.
7-
* ``poll_interval``: The interval between checks of the deployment status in seconds. Defaults to 30 seconds.
8-
* ``wait_for_completion``: Blocked process until the deployment has been completed. Defaults to ``True``.
6+
Deploy a ModelDeployment on Docker Container Runtime
7+
====================================================
98

10-
To deploy a ``ModelDeployment``, you need to define a ``ModelDeployment`` object first and then call ``.deploy()``. There are two ways to define a ``ModelDeployment`` object.
9+
The ADS ``ModelDeploymentContainerRuntime`` class allows you to run a container image using OCI data science model deployment.
1110

12-
Builder Pattern
13-
===============
11+
To use the ``ModelDeploymentContainerRuntime``, you need to first build a docker container image. See `<build_container_image>` for the end-to-end example. Once you have the image, push it to `OCI container registry <https://docs.oracle.com/en-us/iaas/Content/Registry/Concepts/registryoverview.htm>`_. See `Creating a Repository <https://docs.oracle.com/en-us/iaas/Content/Registry/Tasks/registrycreatingarepository.htm>`_ and `Pushing Images Using the Docker CLI <https://docs.oracle.com/en-us/iaas/Content/Registry/Tasks/registrycreatingarepository.htm>`_ for more details.
1412

15-
Infrastructure
16-
--------------
13+
To configure ``ModelDeploymentContainerRuntime``, you must specify the container ``image``. You can optionally specify the `entrypoint` and `cmd` for running the container (See `Understand how CMD and ENTRYPOINT interact <https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact>`_).
1714

18-
You define the model deployment infrastructure by passing the following properties to ``ModelDeploymentInfrastructure``:
15+
Below is an example of deploying model on docker container runtime:
1916

20-
* ``access_log``: Log group OCID and log OCID for the access logs.
21-
* ``bandwidth_mbps``: The bandwidth limit on the load balancer in Mbps.
22-
* ``compartment_id``: Compartment OCID that the model deployment belongs to.
23-
* ``replica``: The number of instances to deploy.
24-
* ``shape_name``: The instance shape name to use. For example, "VM.Standard.E4.Flex".
25-
* ``shape_config_details``: The instance shape configure details to use if flexible shape is selected for ``shape_name``.
26-
* ``predict_log``: Log group OCID and log OCID for the predict logs.
27-
* ``project_id``: Project OCID that the model deployment will belong to.
28-
* ``web_concurrency``: The web concurrency to use.
17+
.. tabs::
2918

30-
Below is an example to define a ``ModelDeploymentInfrastructure`` object
31-
32-
.. code-block:: python3
19+
.. code-tab:: Python3
20+
:caption: Python
3321

3422
from ads.model.deployment.model_deployment_infrastructure import ModelDeploymentInfrastructure
23+
from ads.model.deployment.model_deployment_runtime import ModelDeploymentContainerRuntime
24+
from ads.model.deployment import ModelDeployment
3525

3626
infrastructure = (
3727
ModelDeploymentInfrastructure()
@@ -55,40 +45,6 @@ Below is an example to define a ``ModelDeploymentInfrastructure`` object
5545
)
5646
)
5747

58-
59-
Runtime
60-
-------
61-
62-
The Data Science Model Deployment supports service managed conda runtime and customized docker container runtime.
63-
64-
* ``ModelDeploymentContainerRuntime`` allows you to deploy model deployment on customized docker container runtime.
65-
* ``ModelDeploymentCondaRuntime`` allows you to deploy model deployment on service-managed conda runtime.
66-
67-
ModelDeploymentContainerRuntime
68-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69-
70-
To use the ``ModelDeploymentContainerRuntime``, you need to first push the image to `OCI container registry <https://docs.oracle.com/en-us/iaas/Content/Registry/Concepts/registryoverview.htm>`_. See `Creating a Repository <https://docs.oracle.com/en-us/iaas/Content/Registry/Tasks/registrycreatingarepository.htm>`_ and `Pushing Images Using the Docker CLI <https://docs.oracle.com/en-us/iaas/Content/Registry/Tasks/registrycreatingarepository.htm>`_ for more details.
71-
72-
You can define the model deployment container runtime by passing the following properties to ``ModelDeploymentContainerRuntime`` object:
73-
74-
* ``model_uri``: The model ocid or path to model artifacts directory that is used in the model deployment.
75-
* ``deployment_mode``: The mode of model deployment. Allowed deployment modes are ``HTTPS_ONLY`` and ``STREAM_ONLY``. Optional.
76-
* ``input_stream_ids``: The input stream ids for model deployment. Required when deployment mode is ``STREAM_ONLY``.
77-
* ``output_stream_ids``: The output stream ids for model deployment. Required when deployment mode is ``STREAM_ONLY``.
78-
* ``env``: The environment variables. Optional.
79-
* ``image``: The full path of docker container image to the OCIR registry. The acceptable formats are: ``<region>.ocir.io/<registry>/<image>:<tag>`` and ``<region>.ocir.io/<registry>/<image>:<tag>@digest``. Required.
80-
* ``image_digest``: The docker container image digest. Optional.
81-
* ``entrypoint``: The entrypoint to docker container image. Optional.
82-
* ``server_port``: The server port of docker container image. Optional.
83-
* ``health_check_port``: The health check port of docker container image. Optional.
84-
* ``cmd``: The additional commands to docker container image. The commands can be args to the entrypoint or the only command to execute in the absence of an entrypoint. Optional.
85-
86-
Below is an example to define a ``ModelDeploymentContainerRuntime`` object
87-
88-
.. code-block:: python3
89-
90-
from ads.model.deployment.model_deployment_runtime import ModelDeploymentContainerRuntime
91-
9248
container_runtime = (
9349
ModelDeploymentContainerRuntime()
9450
.with_image("<IMAGE_PATH_TO_OCIR>")
@@ -101,94 +57,129 @@ Below is an example to define a ``ModelDeploymentContainerRuntime`` object
10157
.with_model_uri("<MODEL_URI>")
10258
)
10359

60+
deployment = (
61+
ModelDeployment()
62+
.with_display_name("Model Deployment Demo using ADS")
63+
.with_description("The model deployment description")
64+
.with_freeform_tags({"key1":"value1"})
65+
.with_infrastructure(infrastructure)
66+
.with_runtime(container_runtime)
67+
)
10468

105-
ModelDeploymentCondaRuntime
106-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
69+
deployment.deploy()
10770

108-
You can define the model deployment conda runtime by passing the following properties to ``ModelDeploymentCondaRuntime`` object:
71+
.. code-tab:: Python3
72+
:caption: YAML
10973

110-
* ``model_uri``: The model ocid or path to model artifacts that is used in the model deployment.
111-
* ``deployment_mode``: The deployment mode. The allowed deployment modes are ``HTTPS_ONLY`` and ``STREAM_ONLY``. Optional.
112-
* ``input_stream_ids``: The input stream ids for model deployment. Required when deployment mode is ``STREAM_ONLY``.
113-
* ``output_stream_ids``: The output stream ids for model deployment. Required when deployment mode is ``STREAM_ONLY``.
114-
* ``env``: The environment variables. Optional.
74+
from ads.model.deployment import ModelDeployment
11575

116-
Below is an example to define a ``ModelDeploymentCondaRuntime`` object
76+
yaml_string = """
77+
kind: deployment
78+
spec:
79+
displayName: Model Deployment Demo using ADS
80+
description: The model deployment description
81+
freeform_tags:
82+
key1: value1
83+
infrastructure:
84+
kind: infrastructure
85+
type: datascienceModelDeployment
86+
spec:
87+
compartmentId: <COMPARTMENT_OCID>
88+
projectId: <PROJECT_OCID>
89+
accessLog:
90+
logGroupId: <ACCESS_LOG_GROUP_OCID>
91+
logId: <ACCESS_LOG_OCID>
92+
predictLog:
93+
logGroupId: <PREDICT_LOG_GROUP_OCID>
94+
logId: <PREDICT_LOG_OCID>
95+
shapeName: VM.Standard.E4.Flex
96+
shapeConfigDetails:
97+
memoryInGBs: 16
98+
ocpus: 1
99+
replica: 1
100+
bandWidthMbps: 10
101+
webConcurrency: 10
102+
runtime:
103+
kind: runtime
104+
type: container
105+
spec:
106+
modelUri: <MODEL_URI>
107+
image: <IMAGE_PATH_TO_OCIR>
108+
imageDigest: <IMAGE_DIGEST>
109+
entrypoint: ["python","/opt/ds/model/deployed_model/api.py"]
110+
serverPort: 5000
111+
healthCheckPort: 5000
112+
env:
113+
WEB_CONCURRENCY: "10"
114+
deploymentMode: HTTPS_ONLY
115+
"""
117116

118-
.. code-block:: python3
117+
deployment = ModelDeployment.from_yaml(yaml_string)
118+
deployment.deploy()
119119

120-
from ads.model.deployment.model_deployment_runtime import ModelDeploymentCondaRuntime
121120

122-
conda_runtime = (
123-
ModelDeploymentCondaRuntime()
124-
.with_env({"key":"value"})
125-
.with_deployment_mode("HTTPS_ONLY")
126-
.with_model_uri("<MODEL_URI>")
127-
)
121+
Deploy a ModelDeployment on Conda Runtime
122+
=========================================
128123

124+
To deploy a model deployment on conda runtime, you need to configure ``ModelDeploymentCondaRuntime``.
129125

130-
ModelDeployment
131-
~~~~~~~~~~~~~~~
126+
Below is an example of deploying model on conda runtime:
132127

133-
You can define the model deployment by passing the following properties to ``ModelDeployment`` object:
128+
.. tabs::
134129

135-
* ``defined_tags``: A dictionary of defined tags to be attached to the model deployment. Optional.
136-
* ``description``: A description of the model deployment. Optional.
137-
* ``display_name``: A name that identifies the model deployment in the Console.
138-
* ``freeform_tags``: A dictionary of freeform tags to be attached to the model deployment. Optional.
139-
* ``runtime``: The runtime configuration to be attached to the model deployment.
140-
* ``infrastructure``: The infrastructure configuration to be attached to the model deployment.
130+
.. code-tab:: Python3
131+
:caption: Python
141132

142-
Below is an example to define and deploy a ``ModelDeployment`` object with custom docker container runtime
133+
from ads.model.deployment.model_deployment_infrastructure import ModelDeploymentInfrastructure
134+
from ads.model.deployment.model_deployment_runtime import ModelDeploymentCondaRuntime
135+
from ads.model.deployment import ModelDeployment
143136

144-
.. code-block:: python3
137+
infrastructure = (
138+
ModelDeploymentInfrastructure()
139+
.with_project_id("<PROJECT_OCID>")
140+
.with_compartment_id("<COMPARTMENT_OCID>")
141+
.with_shape_name("VM.Standard.E4.Flex")
142+
.with_shape_config_details(
143+
ocpus=1,
144+
memory_in_gbs=16
145+
)
146+
.with_replica(1)
147+
.with_bandwidth_mbps(10)
148+
.with_web_concurrency(10)
149+
.with_access_log(
150+
log_group_id="<ACCESS_LOG_GROUP_OCID>",
151+
log_id="<ACCESS_LOG_OCID>"
152+
)
153+
.with_predict_log(
154+
log_group_id="<PREDICT_LOG_GROUP_OCID>",
155+
log_id="<PREDICT_LOG_OCID>"
156+
)
157+
)
145158

146-
from ads.model.deployment import ModelDeployment
159+
conda_runtime = (
160+
ModelDeploymentCondaRuntime()
161+
.with_env({"key":"value"})
162+
.with_deployment_mode("HTTPS_ONLY")
163+
.with_model_uri("<MODEL_URI>")
164+
)
147165

148166
deployment = (
149167
ModelDeployment()
150168
.with_display_name("Model Deployment Demo using ADS")
151169
.with_description("The model deployment description")
152170
.with_freeform_tags({"key1":"value1"})
153171
.with_infrastructure(infrastructure)
154-
.with_runtime(container_runtime)
172+
.with_runtime(conda_runtime)
155173
)
156174

157-
deployment.deploy(wait_for_completion=False)
158-
159-
160-
YAML Serialization
161-
==================
162-
163-
A ``ModelDeployment`` object can be serialized to a YAML file by calling ``to_yaml()``, which returns the YAML as a string. You can easily share the YAML with others, and reload the configurations by calling ``from_yaml()``. The ``to_yaml()`` and ``from_yaml()`` methods also take an optional ``uri`` argument for saving and loading the YAML file. This argument can be any URI to the file location supported by `fsspec <https://filesystem-spec.readthedocs.io/en/latest/>`__, including Object Storage. For example:
164-
165-
.. code-block:: python3
166-
167-
# Save the model deployment configurations to YAML file
168-
deployment.to_yaml(uri="oci://bucket_name@namespace/path/to/deployment.yaml")
169-
170-
# Load the model deployment configurations from YAML file
171-
deployment = ModelDeployment.from_yaml(uri="oci://bucket_name@namespace/path/to/deployment.yaml")
172-
173-
# Save the model deployment configurations to YAML in a string
174-
yaml_string = ModelDeployment.to_yaml()
175+
deployment.deploy()
175176

176-
# Load the model deployment configurations from a YAML string
177-
deployment = ModelDeployment.from_yaml("""
178-
kind: deployment
179-
spec:
180-
infrastructure:
181-
kind: infrastructure
182-
...
183-
"""")
184-
185-
deployment.deploy(wait_for_completion=False)
177+
.. code-tab:: Python3
178+
:caption: YAML
186179

187-
Here is an example of a YAML file representing the ``ModelDeployment`` with docker container runtime defined in the preceding examples:
188-
189-
190-
.. code-block:: yaml
180+
from ads.model.deployment import ModelDeployment
191181

182+
yaml_string = """
192183
kind: deployment
193184
spec:
194185
displayName: Model Deployment Demo using ADS
@@ -213,19 +204,19 @@ Here is an example of a YAML file representing the ``ModelDeployment`` with dock
213204
ocpus: 1
214205
replica: 1
215206
bandWidthMbps: 10
207+
webConcurrency: 10
216208
runtime:
217209
kind: runtime
218-
type: container
210+
type: conda
219211
spec:
220212
modelUri: <MODEL_URI>
221-
image: <IMAGE_PATH_TO_OCIR>
222-
imageDigest: <IMAGE_DIGEST>
223-
entrypoint: ["python","/opt/ds/model/deployed_model/api.py"]
224-
serverPort: 5000
225-
healthCheckPort: 5000
226213
env:
227214
WEB_CONCURRENCY: "10"
228215
deploymentMode: HTTPS_ONLY
216+
"""
217+
218+
deployment = ModelDeployment.from_yaml(yaml_string)
219+
deployment.deploy()
229220

230221

231222
**ADS ModelDeployment YAML schema**

0 commit comments

Comments
 (0)