Skip to content

Commit 1097c9e

Browse files
authored
Merge branch 'main' into feature/recommender_v1
2 parents 49f8cd3 + e1b222b commit 1097c9e

File tree

89 files changed

+5597
-1780
lines changed

Some content is hidden

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

89 files changed

+5597
-1780
lines changed

.github/workflows/run-operators-unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
strategy:
2828
fail-fast: false
2929
matrix:
30-
python-version: ["3.8", "3.9", "3.10"]
30+
python-version: ["3.8", "3.9", "3.10", "3.11"]
3131

3232
steps:
3333
- uses: actions/checkout@v4

.github/workflows/run-unittests-default_setup.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "[Py3.8][Py3.9][Py3.10] tests/unitary/default_setup/**"
1+
name: "[Py3.8-3.11] - Default Tests"
22

33
on:
44
workflow_dispatch:
@@ -33,7 +33,7 @@ jobs:
3333
strategy:
3434
fail-fast: false
3535
matrix:
36-
python-version: ["3.8", "3.9", "3.10"]
36+
python-version: ["3.8", "3.9", "3.10", "3.11"]
3737

3838
steps:
3939
- uses: actions/checkout@v4

.github/workflows/run-unittests-py38-cov-report.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "[Py3.8][COV REPORT] tests/unitary/**"
1+
name: "[Py3.8][COV REPORT] - All Unit Tests"
22

33
on:
44
workflow_dispatch:
@@ -44,6 +44,7 @@ jobs:
4444
ignore-path: |
4545
--ignore tests/unitary/with_extras/model \
4646
--ignore tests/unitary/with_extras/feature_store \
47+
--ignore tests/unitary/with_extras/operator/feature-store \
4748
--ignore tests/unitary/with_extras/operator/forecast \
4849
--ignore tests/unitary/with_extras/hpo
4950
- name: "slow_tests"
@@ -79,7 +80,7 @@ jobs:
7980
run: |
8081
pip install -e ".[feature-store-marketplace]"
8182
- name: "Run unitary tests folder with maximum ADS dependencies"
82-
timeout-minutes: 40
83+
timeout-minutes: 60
8384
shell: bash
8485
env:
8586
CONDA_PREFIX: /usr/share/miniconda
@@ -188,6 +189,7 @@ jobs:
188189
fi
189190
190191
- name: "Add comment with cov diff to PR"
192+
continue-on-error: true
191193
uses: actions/github-script@v7
192194
if: github.event_name == 'pull_request'
193195
with:

.github/workflows/run-unittests-py39-py310.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "[Py3.9][Py3.10] - tests/unitary/**"
1+
name: "[Py3.9-3.11] - All Unit Tests"
22

33
on:
44
workflow_dispatch:
@@ -33,7 +33,7 @@ jobs:
3333
strategy:
3434
fail-fast: false
3535
matrix:
36-
python-version: ["3.9", "3.10"]
36+
python-version: ["3.9", "3.10", "3.11"]
3737
name: ["unitary", "slow_tests"]
3838
include:
3939
- name: "unitary"
@@ -46,6 +46,7 @@ jobs:
4646
ignore-path: |
4747
--ignore tests/unitary/with_extras/model \
4848
--ignore tests/unitary/with_extras/feature_store \
49+
--ignore tests/unitary/with_extras/operator/feature-store \
4950
--ignore tests/unitary/with_extras/operator/forecast \
5051
--ignore tests/unitary/with_extras/operator/pii \
5152
--ignore tests/unitary/with_extras/hpo
@@ -85,7 +86,7 @@ jobs:
8586
tests/unitary/with_extras/hpo
8687
8788
- name: "Run unitary tests folder with maximum ADS dependencies"
88-
timeout-minutes: 30
89+
timeout-minutes: 60
8990
shell: bash
9091
env:
9192
CONDA_PREFIX: /usr/share/miniconda

.github/workflows/test-env-setup/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ runs:
77
using: composite
88
steps:
99
- shell: bash
10+
env:
11+
# torch > v2.1.0 brings nvidia dependency by default, we want to install torch for cpu for tests.
12+
# Fot that --index-url https://download.pytorch.org/whl/cpu needed - https://pytorch.org/get-started/locally/.
13+
# Setting env variable here instead of flag --index-url (docs: https://pip.pypa.io/en/stable/cli/pip_install/):
14+
PIP_EXTRA_INDEX_URL: "https://download.pytorch.org/whl/cpu"
1015
run: |
1116
set -x # print commands that are executed
1217

.pre-commit-config.yaml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
repos:
2+
# ruff
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
rev: v0.5.0
5+
hooks:
6+
- id: ruff
7+
types_or: [ python, pyi, jupyter ]
8+
args: [ --fix ]
9+
files: ^ads
10+
exclude: ^docs/
11+
- id: ruff-format
12+
types_or: [ python, pyi, jupyter ]
13+
exclude: ^docs/
214
# Standard hooks
315
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.4.0
16+
rev: v4.6.0
517
hooks:
618
- id: check-ast
719
exclude: ^docs/
@@ -20,12 +32,6 @@ repos:
2032
- id: trailing-whitespace
2133
args: [--markdown-linebreak-ext=md]
2234
exclude: ^docs/
23-
# Black, the code formatter, natively supports pre-commit
24-
- repo: https://github.com/psf/black
25-
rev: 23.3.0
26-
hooks:
27-
- id: black
28-
exclude: ^docs/
2935
# Regex based rst files common mistakes detector
3036
- repo: https://github.com/pre-commit/pygrep-hooks
3137
rev: v1.10.0
@@ -36,7 +42,7 @@ repos:
3642
files: ^docs/
3743
# Hardcoded secrets and ocids detector
3844
- repo: https://github.com/gitleaks/gitleaks
39-
rev: v8.17.0
45+
rev: v8.18.4
4046
hooks:
4147
- id: gitleaks
4248
exclude: .github/workflows/reusable-actions/set-dummy-conf.yml

ads/aqua/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import os
88

99
from ads import logger, set_auth
10-
from ads.aqua.utils import fetch_service_compartment
10+
from ads.aqua.common.utils import fetch_service_compartment
1111
from ads.config import OCI_RESOURCE_PRINCIPAL_VERSION
1212

1313
ENV_VAR_LOG_LEVEL = "ADS_AQUA_LOG_LEVEL"

ads/aqua/base.py renamed to ads/aqua/app.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
55

66
import os
7+
from dataclasses import fields
78
from typing import Dict, Union
89

910
import oci
1011
from oci.data_science.models import UpdateModelDetails, UpdateModelProvenanceDetails
1112

1213
from ads import set_auth
1314
from ads.aqua import logger
14-
from ads.aqua.data import Tags
15-
from ads.aqua.exception import AquaRuntimeError, AquaValueError
16-
from ads.aqua.utils import (
17-
UNKNOWN,
15+
from ads.aqua.common.enums import Tags
16+
from ads.aqua.common.errors import AquaRuntimeError, AquaValueError
17+
from ads.aqua.common.utils import (
1818
_is_valid_mvs,
1919
get_artifact_path,
2020
is_valid_ocid,
2121
load_config,
2222
)
23+
from ads.aqua.constants import UNKNOWN
2324
from ads.common import oci_client as oc
2425
from ads.common.auth import default_signer
2526
from ads.common.utils import extract_region
@@ -160,7 +161,7 @@ def create_model_version_set(
160161
"""
161162
# TODO: tag should be selected based on which operation (eval/FT) invoke this method
162163
# currently only used by fine-tuning flow.
163-
tag = Tags.AQUA_FINE_TUNING.value
164+
tag = Tags.AQUA_FINE_TUNING
164165

165166
if not model_version_set_id:
166167
try:
@@ -277,8 +278,8 @@ def get_config(self, model_id: str, config_file_name: str) -> Dict:
277278
oci_model = self.ds_client.get_model(model_id).data
278279
oci_aqua = (
279280
(
280-
Tags.AQUA_TAG.value in oci_model.freeform_tags
281-
or Tags.AQUA_TAG.value.lower() in oci_model.freeform_tags
281+
Tags.AQUA_TAG in oci_model.freeform_tags
282+
or Tags.AQUA_TAG.lower() in oci_model.freeform_tags
282283
)
283284
if oci_model.freeform_tags
284285
else False
@@ -302,7 +303,15 @@ def get_config(self, model_id: str, config_file_name: str) -> Dict:
302303
config_file_name=config_file_name,
303304
)
304305
except:
305-
pass
306+
# todo: temp fix for issue related to config load for byom models, update logic to choose the right path
307+
try:
308+
config_path = f"{artifact_path.rstrip('/')}/config/"
309+
config = load_config(
310+
config_path,
311+
config_file_name=config_file_name,
312+
)
313+
except:
314+
pass
306315

307316
if not config:
308317
logger.error(
@@ -319,3 +328,22 @@ def telemetry(self):
319328
bucket=AQUA_TELEMETRY_BUCKET, namespace=AQUA_TELEMETRY_BUCKET_NS
320329
)
321330
return self._telemetry
331+
332+
333+
class CLIBuilderMixin:
334+
"""
335+
CLI builder from API interface. To be used with the DataClass only.
336+
"""
337+
338+
def build_cli(self) -> str:
339+
"""
340+
Method to turn the dataclass attributes to CLI
341+
"""
342+
cmd = f"ads aqua {self._command}"
343+
params = [
344+
f"--{field.name} {getattr(self,field.name)}"
345+
for field in fields(self.__class__)
346+
if getattr(self, field.name)
347+
]
348+
cmd = f"{cmd} {' '.join(params)}"
349+
return cmd

ads/aqua/cli.py

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
# Copyright (c) 2024 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
import os
7-
import sys
87

98
from ads.aqua import (
109
ENV_VAR_LOG_LEVEL,
11-
set_log_level,
1210
ODSC_MODEL_COMPARTMENT_OCID,
1311
logger,
12+
set_log_level,
1413
)
15-
from ads.aqua.deployment import AquaDeploymentApp
14+
from ads.aqua.common.errors import AquaCLIError, AquaConfigError
1615
from ads.aqua.evaluation import AquaEvaluationApp
17-
from ads.aqua.finetune import AquaFineTuningApp
16+
from ads.aqua.finetuning import AquaFineTuningApp
1817
from ads.aqua.model import AquaModelApp
19-
from ads.config import NB_SESSION_OCID
18+
from ads.aqua.modeldeployment import AquaDeploymentApp
2019
from ads.common.utils import LOG_LEVELS
20+
from ads.config import NB_SESSION_OCID
2121

2222

2323
class AquaCommand:
@@ -35,6 +35,8 @@ class AquaCommand:
3535

3636
def __init__(
3737
self,
38+
debug: bool = None,
39+
verbose: bool = None,
3840
log_level: str = os.environ.get(ENV_VAR_LOG_LEVEL, "ERROR").upper(),
3941
):
4042
"""
@@ -44,24 +46,64 @@ def __init__(
4446
-----
4547
log_level (str):
4648
Sets the logging level for the application.
47-
Default is retrieved from environment variable `LOG_LEVEL`,
49+
Default is retrieved from environment variable `ADS_AQUA_LOG_LEVEL`,
4850
or 'ERROR' if not set. Example values include 'DEBUG', 'INFO',
4951
'WARNING', 'ERROR', and 'CRITICAL'.
52+
debug (bool):
53+
Sets the logging level for the application to `DEBUG`.
54+
verbose (bool):
55+
Sets the logging level for the application to `INFO`.
56+
57+
Raises
58+
------
59+
AquaCLIError:
60+
When `--verbose` and `--debug` being used together.
61+
When missing required `ODSC_MODEL_COMPARTMENT_OCID` env var.
5062
"""
51-
if log_level.upper() not in LOG_LEVELS:
52-
logger.error(
53-
f"Log level should be one of {LOG_LEVELS}. Setting default to ERROR."
63+
if verbose is not None and debug is not None:
64+
raise AquaCLIError(
65+
"Cannot use `--debug` and `--verbose` at the same time. "
66+
"Please select either `--debug` for `DEBUG` level logging or "
67+
"`--verbose` for `INFO` level logging."
5468
)
55-
log_level = "ERROR"
56-
set_log_level(log_level)
57-
# gracefully exit if env var is not set
69+
elif verbose is not None:
70+
self._validate_value("--verbose", verbose)
71+
aqua_log_level = "INFO"
72+
elif debug is not None:
73+
self._validate_value("--debug", debug)
74+
aqua_log_level = "DEBUG"
75+
else:
76+
if log_level.upper() not in LOG_LEVELS:
77+
logger.warning(
78+
f"Log level should be one of {LOG_LEVELS}. Setting default to ERROR."
79+
)
80+
log_level = "ERROR"
81+
aqua_log_level = log_level.upper()
82+
83+
set_log_level(aqua_log_level)
84+
5885
if not ODSC_MODEL_COMPARTMENT_OCID:
59-
logger.debug(
60-
"ODSC_MODEL_COMPARTMENT_OCID environment variable is not set for Aqua."
61-
)
6286
if NB_SESSION_OCID:
63-
logger.error(
87+
raise AquaConfigError(
6488
f"Aqua is not available for the notebook session {NB_SESSION_OCID}. For more information, "
6589
f"please refer to the documentation."
6690
)
67-
sys.exit(1)
91+
raise AquaConfigError(
92+
"ODSC_MODEL_COMPARTMENT_OCID environment variable is not set for Aqua."
93+
)
94+
95+
@staticmethod
96+
def _validate_value(flag, value):
97+
"""Check if the given value for bool flag is valid.
98+
99+
Raises
100+
------
101+
AquaCLIError:
102+
When the given value for bool flag is invalid.
103+
"""
104+
if value not in [True, False]:
105+
raise AquaCLIError(
106+
f"Invalid input `{value}` for flag: {flag}, a boolean value is required. "
107+
"If you intend to chain a function call to the result, please separate the "
108+
"flag and the subsequent function call with separator `-`."
109+
)

ads/aqua/common/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*--
3+
4+
# Copyright (c) 2024 Oracle and/or its affiliates.
5+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

0 commit comments

Comments
 (0)