Skip to content

Commit 44a3ae0

Browse files
authored
Merge branch 'main' into ODSC-63977/improve_logging
2 parents 544a223 + 83eb229 commit 44a3ae0

27 files changed

+478
-407
lines changed

ads/aqua/evaluation/entities.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
This module contains dataclasses for aqua evaluation.
1010
"""
1111

12+
from typing import Any, Dict, List, Optional
13+
1214
from pydantic import Field
13-
from typing import Any, Dict, List, Optional, Union
1415

15-
from ads.aqua.data import AquaResourceIdentifier
1616
from ads.aqua.config.utils.serializer import Serializable
17+
from ads.aqua.data import AquaResourceIdentifier
1718

1819

1920
class CreateAquaEvaluationDetails(Serializable):
@@ -87,6 +88,8 @@ class CreateAquaEvaluationDetails(Serializable):
8788

8889
class Config:
8990
extra = "ignore"
91+
protected_namespaces = ()
92+
9093

9194
class AquaEvalReport(Serializable):
9295
evaluation_id: str = ""
@@ -95,6 +98,7 @@ class AquaEvalReport(Serializable):
9598
class Config:
9699
extra = "ignore"
97100

101+
98102
class AquaEvalParams(Serializable):
99103
shape: str = ""
100104
dataset_path: str = ""
@@ -103,6 +107,7 @@ class AquaEvalParams(Serializable):
103107
class Config:
104108
extra = "allow"
105109

110+
106111
class AquaEvalMetric(Serializable):
107112
key: str
108113
name: str
@@ -111,6 +116,7 @@ class AquaEvalMetric(Serializable):
111116
class Config:
112117
extra = "ignore"
113118

119+
114120
class AquaEvalMetricSummary(Serializable):
115121
metric: str = ""
116122
score: str = ""
@@ -119,6 +125,7 @@ class AquaEvalMetricSummary(Serializable):
119125
class Config:
120126
extra = "ignore"
121127

128+
122129
class AquaEvalMetrics(Serializable):
123130
id: str
124131
report: str
@@ -128,6 +135,7 @@ class AquaEvalMetrics(Serializable):
128135
class Config:
129136
extra = "ignore"
130137

138+
131139
class AquaEvaluationCommands(Serializable):
132140
evaluation_id: str
133141
evaluation_target_id: str
@@ -139,6 +147,7 @@ class AquaEvaluationCommands(Serializable):
139147
class Config:
140148
extra = "ignore"
141149

150+
142151
class AquaEvaluationSummary(Serializable):
143152
"""Represents a summary of Aqua evalution."""
144153

@@ -157,6 +166,7 @@ class AquaEvaluationSummary(Serializable):
157166
class Config:
158167
extra = "ignore"
159168

169+
160170
class AquaEvaluationDetail(AquaEvaluationSummary):
161171
"""Represents a details of Aqua evalution."""
162172

ads/aqua/evaluation/evaluation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ def _process(
13051305
"id": model_id,
13061306
"name": model.display_name,
13071307
"console_url": console_url,
1308-
"time_created": model.time_created,
1308+
"time_created": str(model.time_created),
13091309
"tags": tags,
13101310
"experiment": self._build_resource_identifier(
13111311
id=experiment_id,

ads/aqua/finetuning/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ class FineTuneCustomMetadata(str, metaclass=ExtendedEnumMeta):
1515
SERVICE_MODEL_ARTIFACT_LOCATION = "artifact_location"
1616
SERVICE_MODEL_DEPLOYMENT_CONTAINER = "deployment-container"
1717
SERVICE_MODEL_FINE_TUNE_CONTAINER = "finetune-container"
18+
19+
20+
ENV_AQUA_FINE_TUNING_CONTAINER = "AQUA_FINE_TUNING_CONTAINER"

ads/aqua/finetuning/finetuning.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
UNKNOWN_DICT,
3232
)
3333
from ads.aqua.data import AquaResourceIdentifier
34-
from ads.aqua.finetuning.constants import *
34+
from ads.aqua.finetuning.constants import (
35+
ENV_AQUA_FINE_TUNING_CONTAINER,
36+
FineTuneCustomMetadata,
37+
)
3538
from ads.aqua.finetuning.entities import *
3639
from ads.common.auth import default_signer
3740
from ads.common.object_storage_details import ObjectStorageDetails
@@ -310,6 +313,15 @@ def create(
310313
except Exception:
311314
pass
312315

316+
if not is_custom_container and ENV_AQUA_FINE_TUNING_CONTAINER in os.environ:
317+
ft_container = os.environ[ENV_AQUA_FINE_TUNING_CONTAINER]
318+
logger.info(
319+
"Using container set by environment variable %s=%s",
320+
ENV_AQUA_FINE_TUNING_CONTAINER,
321+
ft_container,
322+
)
323+
is_custom_container = True
324+
313325
ft_parameters.batch_size = ft_parameters.batch_size or (
314326
ft_config.get("shape", UNKNOWN_DICT)
315327
.get(create_fine_tuning_details.shape_name, UNKNOWN_DICT)
@@ -559,7 +571,6 @@ def get_finetuning_config(self, model_id: str) -> Dict:
559571
Dict:
560572
A dict of allowed finetuning configs.
561573
"""
562-
563574
config = self.get_config(model_id, AQUA_MODEL_FINETUNING_CONFIG)
564575
if not config:
565576
logger.debug(

ads/opctl/operator/lowcode/anomaly/model/anomaly_merlion.py

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

66
import importlib
7+
import logging
78

89
import numpy as np
910
import pandas as pd
11+
import report_creator as rc
1012
from merlion.post_process.threshold import AggregateAlarms
1113
from merlion.utils import TimeSeries
1214

@@ -21,6 +23,8 @@
2123
from .anomaly_dataset import AnomalyOutput
2224
from .base_model import AnomalyOperatorBaseModel
2325

26+
logging.getLogger("report_creator").setLevel(logging.WARNING)
27+
2428

2529
class AnomalyMerlionOperatorModel(AnomalyOperatorBaseModel):
2630
"""Class representing Merlion Anomaly Detection operator model."""
@@ -84,7 +88,7 @@ def _build_model(self) -> AnomalyOutput:
8488
for target, df in self.datasets.full_data_dict.items():
8589
data = df.set_index(date_column)
8690
data = TimeSeries.from_pd(data)
87-
for model_name, (model_config, model) in model_config_map.items():
91+
for _, (model_config, model) in model_config_map.items():
8892
if self.spec.model == SupportedModels.BOCPD:
8993
model_config = model_config(**self.spec.model_kwargs)
9094
else:
@@ -115,7 +119,7 @@ def _build_model(self) -> AnomalyOutput:
115119
y_pred = (y_pred.to_pd().reset_index()["anom_score"] > 0).astype(
116120
int
117121
)
118-
except Exception as e:
122+
except Exception:
119123
y_pred = (
120124
scores["anom_score"]
121125
> np.percentile(
@@ -135,15 +139,12 @@ def _build_model(self) -> AnomalyOutput:
135139
OutputColumns.SCORE_COL: scores["anom_score"],
136140
}
137141
).reset_index(drop=True)
138-
# model_objects[model_name].append(model)
139142

140143
anomaly_output.add_output(target, anomaly, score)
141144
return anomaly_output
142145

143146
def _generate_report(self):
144147
"""Genreates a report for the model."""
145-
import report_creator as rc
146-
147148
other_sections = [
148149
rc.Heading("Selected Models Overview", level=2),
149150
rc.Text(

ads/opctl/operator/lowcode/anomaly/model/automlx.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*--
32

43
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
54
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
65

6+
import logging
7+
78
import pandas as pd
9+
import report_creator as rc
810

911
from ads.common.decorator.runtime_dependency import runtime_dependency
10-
from .anomaly_dataset import AnomalyOutput
12+
from ads.opctl import logger
13+
from ads.opctl.operator.lowcode.anomaly.const import OutputColumns
1114

15+
from .anomaly_dataset import AnomalyOutput
1216
from .base_model import AnomalyOperatorBaseModel
13-
from ads.opctl.operator.lowcode.anomaly.const import OutputColumns
17+
18+
logging.getLogger("report_creator").setLevel(logging.WARNING)
1419

1520

1621
class AutoMLXOperatorModel(AnomalyOperatorBaseModel):
@@ -25,16 +30,17 @@ class AutoMLXOperatorModel(AnomalyOperatorBaseModel):
2530
),
2631
)
2732
def _build_model(self) -> pd.DataFrame:
28-
from automlx import init
2933
import logging
3034

35+
import automlx
36+
3137
try:
32-
init(
38+
automlx.init(
3339
engine="ray",
3440
engine_opts={"ray_setup": {"_temp_dir": "/tmp/ray-temp"}},
3541
loglevel=logging.CRITICAL,
3642
)
37-
except Exception as e:
43+
except Exception:
3844
logger.info("Ray already initialized")
3945
date_column = self.spec.datetime_column.name
4046
anomaly_output = AnomalyOutput(date_column=date_column)
@@ -73,8 +79,6 @@ def _build_model(self) -> pd.DataFrame:
7379
return anomaly_output
7480

7581
def _generate_report(self):
76-
import report_creator as rc
77-
7882
"""The method that needs to be implemented on the particular model level."""
7983
other_sections = [
8084
rc.Heading("Selected Models Overview", level=2),

ads/opctl/operator/lowcode/anomaly/model/autots.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*--
32

43
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
54
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
65

6+
import logging
7+
8+
import report_creator as rc
9+
710
from ads.common.decorator.runtime_dependency import runtime_dependency
811
from ads.opctl import logger
912
from ads.opctl.operator.lowcode.anomaly.const import OutputColumns
@@ -12,6 +15,8 @@
1215
from .anomaly_dataset import AnomalyOutput
1316
from .base_model import AnomalyOperatorBaseModel
1417

18+
logging.getLogger("report_creator").setLevel(logging.WARNING)
19+
1520

1621
class AutoTSOperatorModel(AnomalyOperatorBaseModel):
1722
"""Class representing AutoTS Anomaly Detection operator model."""
@@ -91,8 +96,6 @@ def _build_model(self) -> AnomalyOutput:
9196
return anomaly_output
9297

9398
def _generate_report(self):
94-
import report_creator as rc
95-
9699
"""The method that needs to be implemented on the particular model level."""
97100
other_sections = [
98101
rc.Heading("Selected Models Overview", level=2),

ads/opctl/operator/lowcode/anomaly/model/base_model.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
44
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
55

6+
import logging
67
import os
78
import tempfile
89
import time
@@ -12,6 +13,7 @@
1213
import fsspec
1314
import numpy as np
1415
import pandas as pd
16+
import report_creator as rc
1517
from sklearn import linear_model
1618

1719
from ads.common.object_storage_details import ObjectStorageDetails
@@ -33,6 +35,8 @@
3335
from ..operator_config import AnomalyOperatorConfig, AnomalyOperatorSpec
3436
from .anomaly_dataset import AnomalyDatasets, AnomalyOutput, TestData
3537

38+
logging.getLogger("report_creator").setLevel(logging.WARNING)
39+
3640

3741
class AnomalyOperatorBaseModel(ABC):
3842
"""The base class for the anomaly detection operator models."""
@@ -59,8 +63,8 @@ def __init__(self, config: AnomalyOperatorConfig, datasets: AnomalyDatasets):
5963
def generate_report(self):
6064
"""Generates the report."""
6165
import matplotlib.pyplot as plt
62-
plt.rcParams.update({'figure.max_open_warning': 0})
63-
import report_creator as rc
66+
67+
plt.rcParams.update({"figure.max_open_warning": 0})
6468

6569
start_time = time.time()
6670
# fallback using sklearn oneclasssvm when the sub model _build_model fails
@@ -84,7 +88,13 @@ def generate_report(self):
8488
anomaly_output, test_data, elapsed_time
8589
)
8690
table_blocks = [
87-
rc.DataTable(df.head(SUBSAMPLE_THRESHOLD) if self.spec.subsample_report_data and len(df) > SUBSAMPLE_THRESHOLD else df, label=col, index=True)
91+
rc.DataTable(
92+
df.head(SUBSAMPLE_THRESHOLD)
93+
if self.spec.subsample_report_data and len(df) > SUBSAMPLE_THRESHOLD
94+
else df,
95+
label=col,
96+
index=True,
97+
)
8898
for col, df in self.datasets.full_data_dict.items()
8999
]
90100
data_table = rc.Select(blocks=table_blocks)
@@ -144,7 +154,9 @@ def generate_report(self):
144154
else:
145155
figure_blocks = None
146156

147-
blocks.append(rc.Group(*figure_blocks, label=target)) if figure_blocks else None
157+
blocks.append(
158+
rc.Group(*figure_blocks, label=target)
159+
) if figure_blocks else None
148160
plots = rc.Select(blocks)
149161

150162
report_sections = []
@@ -154,7 +166,9 @@ def generate_report(self):
154166
yaml_appendix = rc.Yaml(self.config.to_dict())
155167
summary = rc.Block(
156168
rc.Group(
157-
rc.Text(f"You selected the **`{self.spec.model}`** model.\n{model_description.text}\n"),
169+
rc.Text(
170+
f"You selected the **`{self.spec.model}`** model.\n{model_description.text}\n"
171+
),
158172
rc.Text(
159173
"Based on your dataset, you could have also selected "
160174
f"any of the models: `{'`, `'.join(SupportedModels.keys() if self.spec.datetime_column else NonTimeADSupportedModels.keys())}`."
@@ -285,8 +299,6 @@ def _save_report(
285299
test_metrics: pd.DataFrame,
286300
):
287301
"""Saves resulting reports to the given folder."""
288-
import report_creator as rc
289-
290302
unique_output_dir = self.spec.output_directory.url
291303

292304
if ObjectStorageDetails.is_oci_path(unique_output_dir):

0 commit comments

Comments
 (0)