1
1
#!/usr/bin/env python
2
- # -*- coding: utf-8; -*-
3
2
4
- # Copyright (c) 2021, 2023 Oracle and/or its affiliates.
3
+ # Copyright (c) 2021, 2025 Oracle and/or its affiliates.
5
4
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6
5
7
6
8
7
import collections
9
8
import copy
10
9
import datetime
11
- import oci
12
- import warnings
13
10
import time
14
- from typing import Dict , List , Union , Any
11
+ import warnings
12
+ from typing import Any , Dict , List , Union
15
13
14
+ import oci
16
15
import oci .loggingsearch
17
- from ads .common import auth as authutil
18
16
import pandas as pd
19
- from ads .model .serde .model_input import JsonModelInputSERDE
17
+ from oci .data_science .models import (
18
+ CreateModelDeploymentDetails ,
19
+ LogDetails ,
20
+ UpdateModelDeploymentDetails ,
21
+ )
22
+
23
+ from ads .common import auth as authutil
24
+ from ads .common import utils as ads_utils
20
25
from ads .common .oci_logging import (
21
26
LOG_INTERVAL ,
22
27
LOG_RECORDS_LIMIT ,
30
35
from ads .model .deployment .common .utils import send_request
31
36
from ads .model .deployment .model_deployment_infrastructure import (
32
37
DEFAULT_BANDWIDTH_MBPS ,
38
+ DEFAULT_MEMORY_IN_GBS ,
39
+ DEFAULT_OCPUS ,
33
40
DEFAULT_REPLICA ,
34
41
DEFAULT_SHAPE_NAME ,
35
- DEFAULT_OCPUS ,
36
- DEFAULT_MEMORY_IN_GBS ,
37
42
MODEL_DEPLOYMENT_INFRASTRUCTURE_TYPE ,
38
43
ModelDeploymentInfrastructure ,
39
44
)
45
50
ModelDeploymentRuntimeType ,
46
51
OCIModelDeploymentRuntimeType ,
47
52
)
53
+ from ads .model .serde .model_input import JsonModelInputSERDE
48
54
from ads .model .service .oci_datascience_model_deployment import (
49
55
OCIDataScienceModelDeployment ,
50
56
)
51
- from ads . common import utils as ads_utils
57
+
52
58
from .common import utils
53
59
from .common .utils import State
54
60
from .model_deployment_properties import ModelDeploymentProperties
55
- from oci .data_science .models import (
56
- LogDetails ,
57
- CreateModelDeploymentDetails ,
58
- UpdateModelDeploymentDetails ,
59
- )
60
61
61
62
DEFAULT_WAIT_TIME = 1200
62
63
DEFAULT_POLL_INTERVAL = 10
@@ -751,6 +752,8 @@ def watch(
751
752
log_filter : str, optional
752
753
Expression for filtering the logs. This will be the WHERE clause of the query.
753
754
Defaults to None.
755
+ status_list : List[str], optional
756
+ List of status of model deployment. This is used to store list of status from logs.
754
757
755
758
Returns
756
759
-------
@@ -964,7 +967,9 @@ def predict(
964
967
except oci .exceptions .ServiceError as ex :
965
968
# When bandwidth exceeds the allocated value, TooManyRequests error (429) will be raised by oci backend.
966
969
if ex .status == 429 :
967
- bandwidth_mbps = self .infrastructure .bandwidth_mbps or DEFAULT_BANDWIDTH_MBPS
970
+ bandwidth_mbps = (
971
+ self .infrastructure .bandwidth_mbps or DEFAULT_BANDWIDTH_MBPS
972
+ )
968
973
utils .get_logger ().warning (
969
974
f"Load balancer bandwidth exceeds the allocated { bandwidth_mbps } Mbps."
970
975
"To estimate the actual bandwidth, use formula: (payload size in KB) * (estimated requests per second) * 8 / 1024."
@@ -1644,22 +1649,22 @@ def _build_model_deployment_configuration_details(self) -> Dict:
1644
1649
}
1645
1650
1646
1651
if infrastructure .subnet_id :
1647
- instance_configuration [
1648
- infrastructure .CONST_SUBNET_ID
1649
- ] = infrastructure . subnet_id
1652
+ instance_configuration [infrastructure . CONST_SUBNET_ID ] = (
1653
+ infrastructure .subnet_id
1654
+ )
1650
1655
1651
1656
if infrastructure .private_endpoint_id :
1652
1657
if not hasattr (
1653
1658
oci .data_science .models .InstanceConfiguration , "private_endpoint_id"
1654
1659
):
1655
1660
# TODO: add oci version with private endpoint support.
1656
- raise EnvironmentError (
1661
+ raise OSError (
1657
1662
"Private endpoint is not supported in the current OCI SDK installed."
1658
1663
)
1659
1664
1660
- instance_configuration [
1661
- infrastructure .CONST_PRIVATE_ENDPOINT_ID
1662
- ] = infrastructure . private_endpoint_id
1665
+ instance_configuration [infrastructure . CONST_PRIVATE_ENDPOINT_ID ] = (
1666
+ infrastructure .private_endpoint_id
1667
+ )
1663
1668
1664
1669
scaling_policy = {
1665
1670
infrastructure .CONST_POLICY_TYPE : "FIXED_SIZE" ,
@@ -1704,7 +1709,7 @@ def _build_model_deployment_configuration_details(self) -> Dict:
1704
1709
oci .data_science .models ,
1705
1710
"ModelDeploymentEnvironmentConfigurationDetails" ,
1706
1711
):
1707
- raise EnvironmentError (
1712
+ raise OSError (
1708
1713
"Environment variable hasn't been supported in the current OCI SDK installed."
1709
1714
)
1710
1715
@@ -1720,9 +1725,9 @@ def _build_model_deployment_configuration_details(self) -> Dict:
1720
1725
and runtime .inference_server .upper ()
1721
1726
== MODEL_DEPLOYMENT_INFERENCE_SERVER_TRITON
1722
1727
):
1723
- environment_variables [
1724
- "CONTAINER_TYPE"
1725
- ] = MODEL_DEPLOYMENT_INFERENCE_SERVER_TRITON
1728
+ environment_variables ["CONTAINER_TYPE" ] = (
1729
+ MODEL_DEPLOYMENT_INFERENCE_SERVER_TRITON
1730
+ )
1726
1731
runtime .set_spec (runtime .CONST_ENV , environment_variables )
1727
1732
environment_configuration_details = {
1728
1733
runtime .CONST_ENVIRONMENT_CONFIG_TYPE : runtime .environment_config_type ,
@@ -1734,17 +1739,17 @@ def _build_model_deployment_configuration_details(self) -> Dict:
1734
1739
oci .data_science .models ,
1735
1740
"OcirModelDeploymentEnvironmentConfigurationDetails" ,
1736
1741
):
1737
- raise EnvironmentError (
1742
+ raise OSError (
1738
1743
"Container runtime hasn't been supported in the current OCI SDK installed."
1739
1744
)
1740
1745
environment_configuration_details ["image" ] = runtime .image
1741
1746
environment_configuration_details ["imageDigest" ] = runtime .image_digest
1742
1747
environment_configuration_details ["cmd" ] = runtime .cmd
1743
1748
environment_configuration_details ["entrypoint" ] = runtime .entrypoint
1744
1749
environment_configuration_details ["serverPort" ] = runtime .server_port
1745
- environment_configuration_details [
1746
- "healthCheckPort"
1747
- ] = runtime . health_check_port
1750
+ environment_configuration_details ["healthCheckPort" ] = (
1751
+ runtime . health_check_port
1752
+ )
1748
1753
1749
1754
model_deployment_configuration_details = {
1750
1755
infrastructure .CONST_DEPLOYMENT_TYPE : "SINGLE_MODEL" ,
@@ -1754,7 +1759,7 @@ def _build_model_deployment_configuration_details(self) -> Dict:
1754
1759
1755
1760
if runtime .deployment_mode == ModelDeploymentMode .STREAM :
1756
1761
if not hasattr (oci .data_science .models , "StreamConfigurationDetails" ):
1757
- raise EnvironmentError (
1762
+ raise OSError (
1758
1763
"Model deployment mode hasn't been supported in the current OCI SDK installed."
1759
1764
)
1760
1765
model_deployment_configuration_details [
@@ -1786,9 +1791,13 @@ def _build_category_log_details(self) -> Dict:
1786
1791
1787
1792
logs = {}
1788
1793
if (
1789
- self .infrastructure .access_log and
1790
- self .infrastructure .access_log .get (self .infrastructure .CONST_LOG_GROUP_ID , None )
1791
- and self .infrastructure .access_log .get (self .infrastructure .CONST_LOG_ID , None )
1794
+ self .infrastructure .access_log
1795
+ and self .infrastructure .access_log .get (
1796
+ self .infrastructure .CONST_LOG_GROUP_ID , None
1797
+ )
1798
+ and self .infrastructure .access_log .get (
1799
+ self .infrastructure .CONST_LOG_ID , None
1800
+ )
1792
1801
):
1793
1802
logs [self .infrastructure .CONST_ACCESS ] = {
1794
1803
self .infrastructure .CONST_LOG_GROUP_ID : self .infrastructure .access_log .get (
@@ -1799,9 +1808,13 @@ def _build_category_log_details(self) -> Dict:
1799
1808
),
1800
1809
}
1801
1810
if (
1802
- self .infrastructure .predict_log and
1803
- self .infrastructure .predict_log .get (self .infrastructure .CONST_LOG_GROUP_ID , None )
1804
- and self .infrastructure .predict_log .get (self .infrastructure .CONST_LOG_ID , None )
1811
+ self .infrastructure .predict_log
1812
+ and self .infrastructure .predict_log .get (
1813
+ self .infrastructure .CONST_LOG_GROUP_ID , None
1814
+ )
1815
+ and self .infrastructure .predict_log .get (
1816
+ self .infrastructure .CONST_LOG_ID , None
1817
+ )
1805
1818
):
1806
1819
logs [self .infrastructure .CONST_PREDICT ] = {
1807
1820
self .infrastructure .CONST_LOG_GROUP_ID : self .infrastructure .predict_log .get (
0 commit comments