Skip to content

Commit 7c9c5e3

Browse files
authored
Merge branch 'main' into ODSC-64644/enhance_model_artifact_handler
2 parents 8d18002 + ab684e8 commit 7c9c5e3

31 files changed

+499
-407
lines changed

ads/aqua/common/decorator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ def inner_function(
6969
reason=error.message,
7070
service_payload=error.args[0] if error.args else None,
7171
exc_info=sys.exc_info(),
72+
aqua_api_details=dict(
73+
# __qualname__ gives information of class and name of api
74+
aqua_api_name=func.__qualname__,
75+
oci_api_name=getattr(
76+
error, "operation_name", "Unknown OCI Operation"
77+
),
78+
service_endpoint=getattr(
79+
error, "request_endpoint", "Unknown Request Endpoint"
80+
)
81+
)
7282
)
7383
except (
7484
ClientError,

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/extension/aqua_ws_msg_handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ def write_error(self, status_code, **kwargs):
7878
logger.warning(reply["message"])
7979
# telemetry may not be present if there is an error while initializing
8080
if hasattr(self, "telemetry"):
81+
aqua_api_details = kwargs.get("aqua_api_details", {})
8182
self.telemetry.record_event_async(
8283
category="aqua/error",
8384
action=str(status_code),
8485
value=reason,
86+
**aqua_api_details
8587
)
8688
response = AquaWsError(
8789
status=status_code,

ads/aqua/extension/base_handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ def write_error(self, status_code, **kwargs):
9898

9999
# telemetry may not be present if there is an error while initializing
100100
if hasattr(self, "telemetry"):
101+
aqua_api_details = kwargs.get("aqua_api_details", {})
101102
self.telemetry.record_event_async(
102103
category="aqua/error",
103104
action=str(status_code),
104105
value=reason,
106+
**aqua_api_details
105107
)
106108

107109
self.finish(json.dumps(reply))

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),

0 commit comments

Comments
 (0)