Skip to content

Commit 4a540e7

Browse files
committed
update the ads folder and setup.py
1 parent 5ba8800 commit 4a540e7

File tree

99 files changed

+9863
-3516
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+9863
-3516
lines changed

ads/ads_version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "2.8.1"
2+
"version": "2.8.2"
33
}

ads/automl/driver.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*--
33

4-
# Copyright (c) 2020, 2022 Oracle and/or its affiliates.
4+
# Copyright (c) 2020, 2023 Oracle and/or its affiliates.
55
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66

77
from __future__ import absolute_import, division, print_function
88

9+
import copy
10+
911
import numpy as np
1012
import pandas as pd
1113
import scipy
12-
import copy
14+
1315
from ads.common import logger, utils
16+
from ads.common.decorator.deprecate import deprecated
1417
from ads.common.model import ADSModel
1518
from ads.dataset import helper
1619
from ads.dataset.classification_dataset import (
@@ -37,6 +40,10 @@
3740
}
3841

3942

43+
@deprecated(
44+
details="Working with AutoML has moved from within ADS to working directly with the AutoMLx library. AutoMLx are preinstalled in conda pack automlx_p38_cpu_v2 and later, and can now be updated independently of ADS. AutoMLx documentation may be found at https://docs.oracle.com/en-us/iaas/tools/automlx/latest/html/multiversion/v23.1.1/index.html. Notebook examples are in Oracle's samples repository: https://github.com/oracle-samples/oci-data-science-ai-samples/tree/master/notebook_examples and a migration tutorial can be found at https://accelerated-data-science.readthedocs.io/en/latest/user_guide/model_training/automl/quick_start.html .",
45+
raise_error=True,
46+
)
4047
def get_ml_task_type(X, y, classes):
4148
"""
4249
Gets the ML task type and returns it.
@@ -79,6 +86,10 @@ def get_ml_task_type(X, y, classes):
7986

8087

8188
class AutoML:
89+
@deprecated(
90+
details="Working with AutoML has moved from within ADS to working directly with the AutoMLx library. AutoMLx are preinstalled in conda pack automlx_p38_cpu_v2 and later, and can now be updated independently of ADS. AutoMLx documentation may be found at https://docs.oracle.com/en-us/iaas/tools/automlx/latest/html/multiversion/v23.1.1/index.html. Notebook examples are in Oracle's samples repository: https://github.com/oracle-samples/oci-data-science-ai-samples/tree/master/notebook_examples and a migration tutorial can be found at https://accelerated-data-science.readthedocs.io/en/latest/user_guide/model_training/automl/quick_start.html .",
91+
raise_error=True,
92+
)
8293
def __init__(
8394
self,
8495
training_data,
@@ -87,7 +98,7 @@ def __init__(
8798
baseline="dummy",
8899
client=None,
89100
):
90-
r"""
101+
"""
91102
Creates an Automatic machine learning object.
92103
93104
Parameters

ads/automl/provider.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8; -*-
33

4-
# Copyright (c) 2020, 2022 Oracle and/or its affiliates.
4+
# Copyright (c) 2020, 2023 Oracle and/or its affiliates.
55
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66

77
import logging
@@ -41,6 +41,10 @@ class AutoMLProvider(ABC):
4141
implement train() and get_transformer_pipeline().
4242
"""
4343

44+
@deprecated(
45+
details="Working with AutoML has moved from within ADS to working directly with the AutoMLx library. AutoMLx are preinstalled in conda pack automlx_p38_cpu_v2 and later, and can now be updated independently of ADS. AutoMLx documentation may be found at https://docs.oracle.com/en-us/iaas/tools/automlx/latest/html/multiversion/v23.1.1/index.html. Notebook examples are in Oracle's samples repository: https://github.com/oracle-samples/oci-data-science-ai-samples/tree/master/notebook_examples and a migration tutorial can be found at https://accelerated-data-science.readthedocs.io/en/latest/user_guide/model_training/automl/quick_start.html .",
46+
raise_error=True,
47+
)
4448
def __init__(self):
4549
self.X_train = None
4650
self.y_train = None
@@ -143,6 +147,10 @@ class BaselineModel(object):
143147
interface. Labels (y) are encoded using DataFrameLabelEncoder.
144148
"""
145149

150+
@deprecated(
151+
details="Working with AutoML has moved from within ADS to working directly with the AutoMLx library. AutoMLx are preinstalled in conda pack automlx_p38_cpu_v2 and later, and can now be updated independently of ADS. AutoMLx documentation may be found at https://docs.oracle.com/en-us/iaas/tools/automlx/latest/html/multiversion/v23.1.1/index.html. Notebook examples are in Oracle's samples repository: https://github.com/oracle-samples/oci-data-science-ai-samples/tree/master/notebook_examples and a migration tutorial can be found at https://accelerated-data-science.readthedocs.io/en/latest/user_guide/model_training/automl/quick_start.html .",
152+
raise_error=True,
153+
)
146154
def __init__(self, est):
147155
self.est = est
148156
self.df_label_encoder = DataFrameLabelEncoder()
@@ -250,6 +258,10 @@ def get_transformer_pipeline(self):
250258
msg = "Baseline"
251259
return [("automl_preprocessing", AutoMLPreprocessingTransformer(msg))]
252260

261+
@deprecated(
262+
details="Working with AutoML has moved from within ADS to working directly with the AutoMLx library. AutoMLx are preinstalled in conda pack automlx_p38_cpu_v2 and later, and can now be updated independently of ADS. AutoMLx documentation may be found at https://docs.oracle.com/en-us/iaas/tools/automlx/latest/html/multiversion/v23.1.1/index.html. Notebook examples are in Oracle's samples repository: https://github.com/oracle-samples/oci-data-science-ai-samples/tree/master/notebook_examples and a migration tutorial can be found at https://accelerated-data-science.readthedocs.io/en/latest/user_guide/model_training/automl/quick_start.html .",
263+
raise_error=True,
264+
)
253265
def __init__(self, est):
254266
"""
255267
Generates a baseline model using the Zero Rule algorithm by default. For a classification
@@ -309,6 +321,7 @@ class OracleAutoMLProvider(AutoMLProvider, ABC):
309321
@deprecated(
310322
"2.6.7",
311323
details="Oracle AutoML is recommended to be directly instantiated by importing automlx package",
324+
raise_error=True,
312325
)
313326
def __init__(
314327
self, n_jobs=-1, loglevel=None, logger_override=None, model_n_jobs: int = 1
@@ -870,6 +883,10 @@ def visualize_tuning_trials(self, ylabel=None):
870883

871884

872885
class AutoMLPreprocessingTransformer(object): # pragma: no cover
886+
@deprecated(
887+
details="Working with AutoML has moved from within ADS to working directly with the AutoMLx library. AutoMLx are preinstalled in conda pack automlx_p38_cpu_v2 and later, and can now be updated independently of ADS. AutoMLx documentation may be found at https://docs.oracle.com/en-us/iaas/tools/automlx/latest/html/multiversion/v23.1.1/index.html. Notebook examples are in Oracle's samples repository: https://github.com/oracle-samples/oci-data-science-ai-samples/tree/master/notebook_examples and a migration tutorial can be found at https://accelerated-data-science.readthedocs.io/en/latest/user_guide/model_training/automl/quick_start.html .",
888+
raise_error=True,
889+
)
873890
def __init__(self, msg):
874891
self.msg = msg
875892

@@ -915,6 +932,10 @@ def __repr__(self):
915932

916933

917934
class AutoMLFeatureSelection(object): # pragma: no cover
935+
@deprecated(
936+
details="Working with AutoML has moved from within ADS to working directly with the AutoMLx library. AutoMLx are preinstalled in conda pack automlx_p38_cpu_v2 and later, and can now be updated independently of ADS. AutoMLx documentation may be found at https://docs.oracle.com/en-us/iaas/tools/automlx/latest/html/multiversion/v23.1.1/index.html. Notebook examples are in Oracle's samples repository: https://github.com/oracle-samples/oci-data-science-ai-samples/tree/master/notebook_examples and a migration tutorial can be found at https://accelerated-data-science.readthedocs.io/en/latest/user_guide/model_training/automl/quick_start.html .",
937+
raise_error=True,
938+
)
918939
def __init__(self, msg):
919940
self.msg = msg
920941

ads/catalog/model.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
OCI_REGION_METADATA,
5050
PROJECT_OCID,
5151
)
52-
from ads.dataset.progress import DummyProgressBar, TqdmProgressBar
52+
from ads.dataset.progress import TqdmProgressBar
5353
from ads.feature_engineering.schema import Schema
5454
from ads.model.model_version_set import ModelVersionSet, _extract_model_version_set_id
5555
from ads.model.deployment.model_deployer import ModelDeployer
@@ -1045,7 +1045,7 @@ def _download_large_artifact(
10451045
model_id: str,
10461046
target_dir: str,
10471047
bucket_uri: str,
1048-
progress: Union[TqdmProgressBar, DummyProgressBar],
1048+
progress: TqdmProgressBar,
10491049
remove_existing_artifact: Optional[bool] = True,
10501050
) -> None:
10511051
"""
@@ -1062,7 +1062,7 @@ def _download_large_artifact(
10621062
The OCI Object Storage URI where model artifacts will be copied to.
10631063
The `bucket_uri` is only necessary for downloading large artifacts with
10641064
size is greater than 2GB. Example: `bucket_uri=oci://<bucket_name>@<namespace>/prefix/`.
1065-
progress: Union[TqdmProgressBar, DummyProgressBar]
1065+
progress: TqdmProgressBar
10661066
The progress bar.
10671067
remove_existing_artifact: (bool, optional). Defaults to `True`.
10681068
Whether artifacts uploaded to object storage bucket need to be removed or not.
@@ -1125,7 +1125,7 @@ def _download_small_artifact(
11251125
self,
11261126
model_id: str,
11271127
target_dir: str,
1128-
progress: Union[TqdmProgressBar, DummyProgressBar],
1128+
progress: TqdmProgressBar,
11291129
) -> None:
11301130
"""
11311131
Downloads the model artifacts from model catalog to target_dir based on `model_id`.
@@ -1137,7 +1137,7 @@ def _download_small_artifact(
11371137
The OCID of the model to download.
11381138
target_dir: str
11391139
The target location of model artifacts.
1140-
progress: Union[TqdmProgressBar, DummyProgressBar]
1140+
progress: TqdmProgressBar
11411141
The progress bar.
11421142
11431143
Returns
@@ -1422,9 +1422,7 @@ def upload_model(
14221422
progress.update("Done")
14231423
return self.get_model(model.data.id)
14241424

1425-
def _prepare_model_artifact(
1426-
self, model_artifact, progress: Union[TqdmProgressBar, DummyProgressBar]
1427-
) -> str:
1425+
def _prepare_model_artifact(self, model_artifact, progress: TqdmProgressBar) -> str:
14281426
"""Prepares model artifacts to save in the Model Catalog.
14291427
14301428
Returns

ads/common/auth.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ class AuthState(metaclass=SingletonMeta):
4646
oci_config_path: str = None
4747
oci_key_profile: str = None
4848
oci_config: str = None
49-
oci_signer: str = None
50-
oci_signer_callable: str = None
51-
oci_signer_kwargs: str = None
49+
oci_signer: Any = None
50+
oci_signer_callable: Callable = None
51+
oci_signer_kwargs: Dict = None
52+
oci_client_kwargs: Dict = None
5253

5354
def __post_init__(self):
5455
self.oci_iam_type = self.oci_iam_type or os.environ.get(
@@ -67,6 +68,7 @@ def __post_init__(self):
6768
self.oci_signer = self.oci_signer
6869
self.oci_signer_callable = self.oci_signer_callable
6970
self.oci_signer_kwargs = self.oci_signer_kwargs or {}
71+
self.oci_client_kwargs = self.oci_client_kwargs or {}
7072

7173

7274
def set_auth(
@@ -77,6 +79,7 @@ def set_auth(
7779
signer: Optional[Any] = None,
7880
signer_callable: Optional[Callable] = None,
7981
signer_kwargs: Optional[Dict] = {},
82+
client_kwargs: Optional[Dict] = {},
8083
) -> None:
8184
"""
8285
Save type of authentication, profile, config location, config (keypair identity) or signer, which will be used
@@ -101,6 +104,9 @@ def set_auth(
101104
signer_kwargs: Optional[Dict], default None
102105
parameters accepted by the signer.
103106
Check documentation: https://docs.oracle.com/en-us/iaas/tools/python/latest/api/signing.html
107+
client_kwargs: Optional[Dict], default None
108+
Additional keyword arguments for initializing the OCI client.
109+
Example: client_kwargs = {"timeout": 60}
104110
105111
Examples
106112
--------
@@ -110,6 +116,8 @@ def set_auth(
110116
111117
>>> ads.set_auth("api_key", oci_config_location = "other_config_location") # use non-default oci_config_location
112118
119+
>>> ads.set_auth("api_key", client_kwargs={"timeout": 60}) # default signer with connection and read timeouts set to 60 seconds for the client.
120+
113121
>>> other_config = oci.config.from_file("other_config_location", "OTHER_PROFILE") # Create non-default config
114122
>>> ads.set_auth(config=other_config) # Set api keys type of authentication based on provided config
115123
@@ -149,7 +157,7 @@ def set_auth(
149157

150158
auth_state.oci_config = config
151159
auth_state.oci_key_profile = profile
152-
if auth == AuthType.API_KEY:
160+
if auth == AuthType.API_KEY and not signer and not signer_callable:
153161
if os.path.exists(os.path.expanduser(oci_config_location)):
154162
auth_state.oci_config_path = oci_config_location
155163
else:
@@ -160,6 +168,7 @@ def set_auth(
160168
auth_state.oci_signer = signer
161169
auth_state.oci_signer_callable = signer_callable
162170
auth_state.oci_signer_kwargs = signer_kwargs
171+
auth_state.oci_client_kwargs = client_kwargs
163172

164173

165174
def api_keys(
@@ -326,6 +335,7 @@ def default_signer(client_kwargs: Optional[Dict] = None) -> Dict:
326335
----------
327336
client_kwargs : dict
328337
kwargs that are required to instantiate the Client if we need to override the defaults.
338+
Example: client_kwargs = {"timeout": 60}
329339
330340
Returns
331341
-------
@@ -364,7 +374,10 @@ def default_signer(client_kwargs: Optional[Dict] = None) -> Dict:
364374
signer_dict = {
365375
"config": configuration,
366376
"signer": signer,
367-
"client_kwargs": client_kwargs,
377+
"client_kwargs": {
378+
**(auth_state.oci_client_kwargs or {}),
379+
**(client_kwargs or {}),
380+
},
368381
}
369382
logger.info(f"Using authentication signer type {type(signer)}.")
370383
return signer_dict
@@ -373,7 +386,10 @@ def default_signer(client_kwargs: Optional[Dict] = None) -> Dict:
373386
oci_config_location=auth_state.oci_config_path,
374387
oci_key_profile=auth_state.oci_key_profile,
375388
oci_config=auth_state.oci_config,
376-
client_kwargs=client_kwargs,
389+
client_kwargs={
390+
**(auth_state.oci_client_kwargs or {}),
391+
**(client_kwargs or {}),
392+
},
377393
)
378394
signer_generator = AuthFactory().signerGenerator(auth_state.oci_iam_type)
379395
return signer_generator(signer_args).create_signer()
@@ -778,6 +794,9 @@ def __init__(self, **kwargs):
778794
a callable object that returns signer
779795
signer_kwargs: Optional[Dict], default None
780796
parameters accepted by the signer
797+
client_kwargs: Optional[Dict], default None
798+
Additional keyword arguments for initializing the OCI client.
799+
Example: client_kwargs = {"timeout": 60}
781800
"""
782801
self.kwargs = kwargs
783802

ads/common/decorator/deprecate.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*--
33

4-
# Copyright (c) 2021, 2022 Oracle and/or its affiliates.
4+
# Copyright (c) 2021, 2023 Oracle and/or its affiliates.
55
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66

77
import warnings
88
from enum import Enum
99
from functools import wraps
1010

1111

12+
class NotSupportedError(Exception):
13+
pass
14+
15+
1216
class TARGET_TYPE(Enum):
1317
CLASS = "Class"
1418
METHOD = "Method"
1519
ATTRIBUTE = "Attribute"
1620

1721

1822
def deprecated(
19-
deprecated_in: str,
23+
deprecated_in: str = None,
2024
removed_in: str = None,
2125
details: str = None,
2226
target_type: str = None,
27+
raise_error: bool = False,
2328
):
2429
"""This is a decorator which can be used to mark functions
2530
as deprecated. It will result in a warning being emitted
@@ -44,14 +49,19 @@ def wrapper(*args, **kwargs):
4449
else:
4550
_target_type = target_type or TARGET_TYPE.METHOD.value
4651
target_name = target.__name__
47-
48-
msg = (
49-
f"{_target_type} {target_name} is "
50-
f"deprecated in {deprecated_in} and will be "
51-
f"removed in {removed_in if removed_in else 'a future release'}."
52-
f"{'' if not details else ' ' + details}"
53-
)
54-
warnings.warn(msg, DeprecationWarning, stacklevel=2)
52+
if deprecated_in:
53+
msg = (
54+
f"{_target_type} {target_name} is "
55+
f"deprecated in {deprecated_in} and will be "
56+
f"removed in {removed_in if removed_in else 'a future release'}."
57+
f"{'' if not details else ' ' + details}"
58+
)
59+
else:
60+
msg = details
61+
if raise_error:
62+
raise NotSupportedError(msg)
63+
else:
64+
warnings.warn(msg, DeprecationWarning, stacklevel=2)
5565
return target(*args, **kwargs)
5666

5767
return wrapper

ads/common/decorator/runtime_dependency.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8; -*-
33

4-
# Copyright (c) 2021, 2022 Oracle and/or its affiliates.
4+
# Copyright (c) 2021, 2023 Oracle and/or its affiliates.
55
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66

77
"""
@@ -63,6 +63,7 @@ class OptionalDependency:
6363
ONNX = "oracle-ads[onnx]"
6464
OPTUNA = "oracle-ads[optuna]"
6565
SPARK = "oracle-ads[spark]"
66+
HUGGINGFACE = "oracle-ads[huggingface]"
6667

6768

6869
def runtime_dependency(

0 commit comments

Comments
 (0)