mlrun 1.7.1rc10__py3-none-any.whl → 1.8.0rc11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mlrun might be problematic. Click here for more details.
- mlrun/__init__.py +23 -21
- mlrun/__main__.py +3 -3
- mlrun/alerts/alert.py +148 -14
- mlrun/artifacts/__init__.py +2 -3
- mlrun/artifacts/base.py +55 -12
- mlrun/artifacts/dataset.py +16 -16
- mlrun/artifacts/document.py +378 -0
- mlrun/artifacts/manager.py +26 -17
- mlrun/artifacts/model.py +66 -53
- mlrun/common/constants.py +8 -0
- mlrun/common/formatters/__init__.py +1 -0
- mlrun/common/formatters/feature_set.py +1 -0
- mlrun/common/formatters/function.py +1 -0
- mlrun/{model_monitoring/db/stores/base/__init__.py → common/formatters/model_endpoint.py} +16 -1
- mlrun/common/formatters/pipeline.py +1 -2
- mlrun/common/formatters/project.py +9 -0
- mlrun/common/model_monitoring/__init__.py +0 -5
- mlrun/common/model_monitoring/helpers.py +1 -29
- mlrun/common/runtimes/constants.py +1 -2
- mlrun/common/schemas/__init__.py +6 -2
- mlrun/common/schemas/alert.py +111 -19
- mlrun/common/schemas/api_gateway.py +3 -3
- mlrun/common/schemas/artifact.py +11 -7
- mlrun/common/schemas/auth.py +6 -4
- mlrun/common/schemas/background_task.py +7 -7
- mlrun/common/schemas/client_spec.py +2 -3
- mlrun/common/schemas/clusterization_spec.py +2 -2
- mlrun/common/schemas/common.py +53 -3
- mlrun/common/schemas/constants.py +15 -0
- mlrun/common/schemas/datastore_profile.py +1 -1
- mlrun/common/schemas/feature_store.py +9 -9
- mlrun/common/schemas/frontend_spec.py +4 -4
- mlrun/common/schemas/function.py +10 -10
- mlrun/common/schemas/hub.py +1 -1
- mlrun/common/schemas/k8s.py +3 -3
- mlrun/common/schemas/memory_reports.py +3 -3
- mlrun/common/schemas/model_monitoring/__init__.py +2 -1
- mlrun/common/schemas/model_monitoring/constants.py +67 -14
- mlrun/common/schemas/model_monitoring/grafana.py +1 -1
- mlrun/common/schemas/model_monitoring/model_endpoints.py +92 -147
- mlrun/common/schemas/notification.py +24 -3
- mlrun/common/schemas/object.py +1 -1
- mlrun/common/schemas/pagination.py +4 -4
- mlrun/common/schemas/partition.py +137 -0
- mlrun/common/schemas/pipeline.py +2 -2
- mlrun/common/schemas/project.py +25 -17
- mlrun/common/schemas/runs.py +2 -2
- mlrun/common/schemas/runtime_resource.py +5 -5
- mlrun/common/schemas/schedule.py +1 -1
- mlrun/common/schemas/secret.py +1 -1
- mlrun/common/schemas/tag.py +3 -3
- mlrun/common/schemas/workflow.py +5 -5
- mlrun/config.py +68 -10
- mlrun/data_types/__init__.py +0 -2
- mlrun/data_types/data_types.py +1 -0
- mlrun/data_types/infer.py +3 -1
- mlrun/data_types/spark.py +5 -3
- mlrun/data_types/to_pandas.py +11 -2
- mlrun/datastore/__init__.py +2 -2
- mlrun/datastore/alibaba_oss.py +4 -1
- mlrun/datastore/azure_blob.py +4 -1
- mlrun/datastore/base.py +12 -4
- mlrun/datastore/datastore.py +9 -3
- mlrun/datastore/datastore_profile.py +79 -20
- mlrun/datastore/dbfs_store.py +4 -1
- mlrun/datastore/filestore.py +4 -1
- mlrun/datastore/google_cloud_storage.py +4 -1
- mlrun/datastore/hdfs.py +4 -1
- mlrun/datastore/inmem.py +4 -1
- mlrun/datastore/redis.py +4 -1
- mlrun/datastore/s3.py +4 -1
- mlrun/datastore/sources.py +52 -51
- mlrun/datastore/store_resources.py +7 -4
- mlrun/datastore/targets.py +23 -22
- mlrun/datastore/utils.py +2 -2
- mlrun/datastore/v3io.py +4 -1
- mlrun/datastore/vectorstore.py +229 -0
- mlrun/datastore/wasbfs/fs.py +13 -12
- mlrun/db/base.py +213 -83
- mlrun/db/factory.py +0 -3
- mlrun/db/httpdb.py +1265 -387
- mlrun/db/nopdb.py +205 -74
- mlrun/errors.py +2 -2
- mlrun/execution.py +136 -50
- mlrun/feature_store/__init__.py +0 -2
- mlrun/feature_store/api.py +41 -40
- mlrun/feature_store/common.py +9 -9
- mlrun/feature_store/feature_set.py +20 -18
- mlrun/feature_store/feature_vector.py +27 -24
- mlrun/feature_store/retrieval/base.py +14 -9
- mlrun/feature_store/retrieval/job.py +2 -1
- mlrun/feature_store/steps.py +2 -2
- mlrun/features.py +30 -13
- mlrun/frameworks/__init__.py +1 -2
- mlrun/frameworks/_common/__init__.py +1 -2
- mlrun/frameworks/_common/artifacts_library.py +2 -2
- mlrun/frameworks/_common/mlrun_interface.py +10 -6
- mlrun/frameworks/_common/model_handler.py +29 -27
- mlrun/frameworks/_common/producer.py +3 -1
- mlrun/frameworks/_dl_common/__init__.py +1 -2
- mlrun/frameworks/_dl_common/loggers/__init__.py +1 -2
- mlrun/frameworks/_dl_common/loggers/mlrun_logger.py +4 -4
- mlrun/frameworks/_dl_common/loggers/tensorboard_logger.py +3 -3
- mlrun/frameworks/_ml_common/__init__.py +1 -2
- mlrun/frameworks/_ml_common/loggers/__init__.py +1 -2
- mlrun/frameworks/_ml_common/model_handler.py +21 -21
- mlrun/frameworks/_ml_common/plans/__init__.py +1 -2
- mlrun/frameworks/_ml_common/plans/confusion_matrix_plan.py +3 -1
- mlrun/frameworks/_ml_common/plans/dataset_plan.py +3 -3
- mlrun/frameworks/_ml_common/plans/roc_curve_plan.py +4 -4
- mlrun/frameworks/auto_mlrun/__init__.py +1 -2
- mlrun/frameworks/auto_mlrun/auto_mlrun.py +22 -15
- mlrun/frameworks/huggingface/__init__.py +1 -2
- mlrun/frameworks/huggingface/model_server.py +9 -9
- mlrun/frameworks/lgbm/__init__.py +47 -44
- mlrun/frameworks/lgbm/callbacks/__init__.py +1 -2
- mlrun/frameworks/lgbm/callbacks/logging_callback.py +4 -2
- mlrun/frameworks/lgbm/callbacks/mlrun_logging_callback.py +4 -2
- mlrun/frameworks/lgbm/mlrun_interfaces/__init__.py +1 -2
- mlrun/frameworks/lgbm/mlrun_interfaces/mlrun_interface.py +5 -5
- mlrun/frameworks/lgbm/model_handler.py +15 -11
- mlrun/frameworks/lgbm/model_server.py +11 -7
- mlrun/frameworks/lgbm/utils.py +2 -2
- mlrun/frameworks/onnx/__init__.py +1 -2
- mlrun/frameworks/onnx/dataset.py +3 -3
- mlrun/frameworks/onnx/mlrun_interface.py +2 -2
- mlrun/frameworks/onnx/model_handler.py +7 -5
- mlrun/frameworks/onnx/model_server.py +8 -6
- mlrun/frameworks/parallel_coordinates.py +11 -11
- mlrun/frameworks/pytorch/__init__.py +22 -23
- mlrun/frameworks/pytorch/callbacks/__init__.py +1 -2
- mlrun/frameworks/pytorch/callbacks/callback.py +2 -1
- mlrun/frameworks/pytorch/callbacks/logging_callback.py +15 -8
- mlrun/frameworks/pytorch/callbacks/mlrun_logging_callback.py +19 -12
- mlrun/frameworks/pytorch/callbacks/tensorboard_logging_callback.py +22 -15
- mlrun/frameworks/pytorch/callbacks_handler.py +36 -30
- mlrun/frameworks/pytorch/mlrun_interface.py +17 -17
- mlrun/frameworks/pytorch/model_handler.py +21 -17
- mlrun/frameworks/pytorch/model_server.py +13 -9
- mlrun/frameworks/sklearn/__init__.py +19 -18
- mlrun/frameworks/sklearn/estimator.py +2 -2
- mlrun/frameworks/sklearn/metric.py +3 -3
- mlrun/frameworks/sklearn/metrics_library.py +8 -6
- mlrun/frameworks/sklearn/mlrun_interface.py +3 -2
- mlrun/frameworks/sklearn/model_handler.py +4 -3
- mlrun/frameworks/tf_keras/__init__.py +11 -12
- mlrun/frameworks/tf_keras/callbacks/__init__.py +1 -2
- mlrun/frameworks/tf_keras/callbacks/logging_callback.py +17 -14
- mlrun/frameworks/tf_keras/callbacks/mlrun_logging_callback.py +15 -12
- mlrun/frameworks/tf_keras/callbacks/tensorboard_logging_callback.py +21 -18
- mlrun/frameworks/tf_keras/model_handler.py +17 -13
- mlrun/frameworks/tf_keras/model_server.py +12 -8
- mlrun/frameworks/xgboost/__init__.py +19 -18
- mlrun/frameworks/xgboost/model_handler.py +13 -9
- mlrun/launcher/base.py +3 -4
- mlrun/launcher/local.py +1 -1
- mlrun/launcher/remote.py +1 -1
- mlrun/lists.py +4 -3
- mlrun/model.py +117 -46
- mlrun/model_monitoring/__init__.py +4 -4
- mlrun/model_monitoring/api.py +72 -59
- mlrun/model_monitoring/applications/_application_steps.py +17 -17
- mlrun/model_monitoring/applications/base.py +165 -6
- mlrun/model_monitoring/applications/context.py +88 -37
- mlrun/model_monitoring/applications/evidently_base.py +0 -1
- mlrun/model_monitoring/applications/histogram_data_drift.py +43 -21
- mlrun/model_monitoring/applications/results.py +55 -3
- mlrun/model_monitoring/controller.py +207 -239
- mlrun/model_monitoring/db/__init__.py +0 -2
- mlrun/model_monitoring/db/_schedules.py +156 -0
- mlrun/model_monitoring/db/_stats.py +189 -0
- mlrun/model_monitoring/db/tsdb/base.py +78 -25
- mlrun/model_monitoring/db/tsdb/tdengine/schemas.py +61 -6
- mlrun/model_monitoring/db/tsdb/tdengine/stream_graph_steps.py +33 -0
- mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connector.py +255 -29
- mlrun/model_monitoring/db/tsdb/v3io/stream_graph_steps.py +1 -0
- mlrun/model_monitoring/db/tsdb/v3io/v3io_connector.py +78 -17
- mlrun/model_monitoring/helpers.py +151 -49
- mlrun/model_monitoring/stream_processing.py +99 -283
- mlrun/model_monitoring/tracking_policy.py +10 -3
- mlrun/model_monitoring/writer.py +48 -36
- mlrun/package/__init__.py +3 -6
- mlrun/package/context_handler.py +1 -1
- mlrun/package/packager.py +12 -9
- mlrun/package/packagers/__init__.py +0 -2
- mlrun/package/packagers/default_packager.py +14 -11
- mlrun/package/packagers/numpy_packagers.py +16 -7
- mlrun/package/packagers/pandas_packagers.py +18 -18
- mlrun/package/packagers/python_standard_library_packagers.py +25 -11
- mlrun/package/packagers_manager.py +31 -14
- mlrun/package/utils/__init__.py +0 -3
- mlrun/package/utils/_pickler.py +6 -6
- mlrun/platforms/__init__.py +47 -16
- mlrun/platforms/iguazio.py +4 -1
- mlrun/projects/operations.py +27 -27
- mlrun/projects/pipelines.py +71 -36
- mlrun/projects/project.py +890 -220
- mlrun/run.py +53 -10
- mlrun/runtimes/__init__.py +1 -3
- mlrun/runtimes/base.py +15 -11
- mlrun/runtimes/daskjob.py +9 -9
- mlrun/runtimes/generators.py +2 -1
- mlrun/runtimes/kubejob.py +4 -5
- mlrun/runtimes/mounts.py +572 -0
- mlrun/runtimes/mpijob/__init__.py +0 -2
- mlrun/runtimes/mpijob/abstract.py +7 -6
- mlrun/runtimes/nuclio/api_gateway.py +7 -7
- mlrun/runtimes/nuclio/application/application.py +11 -11
- mlrun/runtimes/nuclio/function.py +19 -17
- mlrun/runtimes/nuclio/serving.py +18 -13
- mlrun/runtimes/pod.py +154 -45
- mlrun/runtimes/remotesparkjob.py +3 -2
- mlrun/runtimes/sparkjob/__init__.py +0 -2
- mlrun/runtimes/sparkjob/spark3job.py +21 -11
- mlrun/runtimes/utils.py +6 -5
- mlrun/serving/merger.py +6 -4
- mlrun/serving/remote.py +18 -17
- mlrun/serving/routers.py +185 -172
- mlrun/serving/server.py +7 -1
- mlrun/serving/states.py +97 -78
- mlrun/serving/utils.py +13 -2
- mlrun/serving/v1_serving.py +3 -2
- mlrun/serving/v2_serving.py +105 -72
- mlrun/track/__init__.py +1 -1
- mlrun/track/tracker.py +2 -2
- mlrun/track/trackers/mlflow_tracker.py +6 -5
- mlrun/utils/async_http.py +1 -1
- mlrun/utils/clones.py +1 -1
- mlrun/utils/helpers.py +63 -19
- mlrun/utils/logger.py +106 -4
- mlrun/utils/notifications/notification/__init__.py +22 -19
- mlrun/utils/notifications/notification/base.py +33 -14
- mlrun/utils/notifications/notification/console.py +6 -6
- mlrun/utils/notifications/notification/git.py +11 -11
- mlrun/utils/notifications/notification/ipython.py +10 -9
- mlrun/utils/notifications/notification/mail.py +176 -0
- mlrun/utils/notifications/notification/slack.py +6 -6
- mlrun/utils/notifications/notification/webhook.py +6 -6
- mlrun/utils/notifications/notification_pusher.py +86 -44
- mlrun/utils/regex.py +11 -2
- mlrun/utils/version/version.json +2 -2
- {mlrun-1.7.1rc10.dist-info → mlrun-1.8.0rc11.dist-info}/METADATA +29 -24
- mlrun-1.8.0rc11.dist-info/RECORD +347 -0
- mlrun/model_monitoring/db/stores/__init__.py +0 -136
- mlrun/model_monitoring/db/stores/base/store.py +0 -213
- mlrun/model_monitoring/db/stores/sqldb/__init__.py +0 -13
- mlrun/model_monitoring/db/stores/sqldb/models/__init__.py +0 -71
- mlrun/model_monitoring/db/stores/sqldb/models/base.py +0 -190
- mlrun/model_monitoring/db/stores/sqldb/models/mysql.py +0 -103
- mlrun/model_monitoring/db/stores/sqldb/models/sqlite.py +0 -40
- mlrun/model_monitoring/db/stores/sqldb/sql_store.py +0 -659
- mlrun/model_monitoring/db/stores/v3io_kv/__init__.py +0 -13
- mlrun/model_monitoring/db/stores/v3io_kv/kv_store.py +0 -726
- mlrun/model_monitoring/model_endpoint.py +0 -118
- mlrun-1.7.1rc10.dist-info/RECORD +0 -351
- {mlrun-1.7.1rc10.dist-info → mlrun-1.8.0rc11.dist-info}/LICENSE +0 -0
- {mlrun-1.7.1rc10.dist-info → mlrun-1.8.0rc11.dist-info}/WHEEL +0 -0
- {mlrun-1.7.1rc10.dist-info → mlrun-1.8.0rc11.dist-info}/entry_points.txt +0 -0
- {mlrun-1.7.1rc10.dist-info → mlrun-1.8.0rc11.dist-info}/top_level.txt +0 -0
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
import json
|
|
16
15
|
from dataclasses import dataclass
|
|
17
16
|
from typing import Final, Optional, Protocol, Union, cast
|
|
18
17
|
|
|
@@ -25,10 +24,10 @@ import mlrun.model_monitoring.applications.context as mm_context
|
|
|
25
24
|
import mlrun.model_monitoring.applications.results as mm_results
|
|
26
25
|
import mlrun.model_monitoring.features_drift_table as mm_drift_table
|
|
27
26
|
from mlrun.common.schemas.model_monitoring.constants import (
|
|
28
|
-
EventFieldType,
|
|
29
27
|
HistogramDataDriftApplicationConstants,
|
|
30
28
|
ResultKindApp,
|
|
31
29
|
ResultStatusApp,
|
|
30
|
+
StatsKind,
|
|
32
31
|
)
|
|
33
32
|
from mlrun.model_monitoring.applications import (
|
|
34
33
|
ModelMonitoringApplicationBase,
|
|
@@ -114,12 +113,13 @@ class HistogramDataDriftApplication(ModelMonitoringApplicationBase):
|
|
|
114
113
|
|
|
115
114
|
project.enable_model_monitoring()
|
|
116
115
|
|
|
117
|
-
To avoid it, pass
|
|
116
|
+
To avoid it, pass :code:`deploy_histogram_data_drift_app=False`.
|
|
118
117
|
"""
|
|
119
118
|
|
|
120
119
|
NAME: Final[str] = HistogramDataDriftApplicationConstants.NAME
|
|
121
120
|
|
|
122
121
|
_REQUIRED_METRICS = {HellingerDistance, TotalVarianceDistance}
|
|
122
|
+
_STATS_TYPES: tuple[StatsKind] = (StatsKind.CURRENT_STATS, StatsKind.DRIFT_MEASURES)
|
|
123
123
|
|
|
124
124
|
metrics: list[type[HistogramDistanceMetric]] = [
|
|
125
125
|
HellingerDistance,
|
|
@@ -189,21 +189,12 @@ class HistogramDataDriftApplication(ModelMonitoringApplicationBase):
|
|
|
189
189
|
)
|
|
190
190
|
|
|
191
191
|
status = self._value_classifier.value_to_status(value)
|
|
192
|
+
|
|
192
193
|
return mm_results.ModelMonitoringApplicationResult(
|
|
193
194
|
name=HistogramDataDriftApplicationConstants.GENERAL_RESULT_NAME,
|
|
194
195
|
value=value,
|
|
195
196
|
kind=ResultKindApp.data_drift,
|
|
196
197
|
status=status,
|
|
197
|
-
extra_data={
|
|
198
|
-
EventFieldType.CURRENT_STATS: json.dumps(
|
|
199
|
-
monitoring_context.sample_df_stats
|
|
200
|
-
),
|
|
201
|
-
EventFieldType.DRIFT_MEASURES: json.dumps(
|
|
202
|
-
metrics_per_feature.T.to_dict()
|
|
203
|
-
| {metric.name: metric.value for metric in metrics}
|
|
204
|
-
),
|
|
205
|
-
EventFieldType.DRIFT_STATUS: status.value,
|
|
206
|
-
},
|
|
207
198
|
)
|
|
208
199
|
|
|
209
200
|
@staticmethod
|
|
@@ -225,6 +216,35 @@ class HistogramDataDriftApplication(ModelMonitoringApplicationBase):
|
|
|
225
216
|
|
|
226
217
|
return metrics
|
|
227
218
|
|
|
219
|
+
@staticmethod
|
|
220
|
+
def _get_stats(
|
|
221
|
+
metrics: list[mm_results.ModelMonitoringApplicationMetric],
|
|
222
|
+
metrics_per_feature: DataFrame,
|
|
223
|
+
monitoring_context: mm_context.MonitoringApplicationContext,
|
|
224
|
+
) -> list[mm_results._ModelMonitoringApplicationStats]:
|
|
225
|
+
"""
|
|
226
|
+
list the application calculated stats
|
|
227
|
+
:param metrics: the calculated metrics
|
|
228
|
+
:param metrics_per_feature: metric calculated per feature
|
|
229
|
+
:param monitoring_context: context object for current monitoring application
|
|
230
|
+
:returns: list of mm_results._ModelMonitoringApplicationStats for histogram data drift application
|
|
231
|
+
"""
|
|
232
|
+
stats = []
|
|
233
|
+
for stats_type in HistogramDataDriftApplication._STATS_TYPES:
|
|
234
|
+
stats.append(
|
|
235
|
+
mm_results._ModelMonitoringApplicationStats(
|
|
236
|
+
name=stats_type,
|
|
237
|
+
stats=metrics_per_feature.T.to_dict()
|
|
238
|
+
| {metric.name: metric.value for metric in metrics}
|
|
239
|
+
if stats_type == StatsKind.DRIFT_MEASURES
|
|
240
|
+
else monitoring_context.sample_df_stats,
|
|
241
|
+
timestamp=monitoring_context.end_infer_time.isoformat(
|
|
242
|
+
sep=" ", timespec="microseconds"
|
|
243
|
+
),
|
|
244
|
+
)
|
|
245
|
+
)
|
|
246
|
+
return stats
|
|
247
|
+
|
|
228
248
|
@staticmethod
|
|
229
249
|
def _get_shared_features_sample_stats(
|
|
230
250
|
monitoring_context: mm_context.MonitoringApplicationContext,
|
|
@@ -311,19 +331,16 @@ class HistogramDataDriftApplication(ModelMonitoringApplicationBase):
|
|
|
311
331
|
)
|
|
312
332
|
|
|
313
333
|
def do_tracking(
|
|
314
|
-
self,
|
|
315
|
-
monitoring_context: mm_context.MonitoringApplicationContext,
|
|
334
|
+
self, monitoring_context: mm_context.MonitoringApplicationContext
|
|
316
335
|
) -> list[
|
|
317
336
|
Union[
|
|
318
337
|
mm_results.ModelMonitoringApplicationResult,
|
|
319
338
|
mm_results.ModelMonitoringApplicationMetric,
|
|
339
|
+
mm_results._ModelMonitoringApplicationStats,
|
|
320
340
|
]
|
|
321
341
|
]:
|
|
322
342
|
"""
|
|
323
343
|
Calculate and return the data drift metrics, averaged over the features.
|
|
324
|
-
|
|
325
|
-
Refer to `ModelMonitoringApplicationBaseV2` for the meaning of the
|
|
326
|
-
function arguments.
|
|
327
344
|
"""
|
|
328
345
|
monitoring_context.logger.debug("Starting to run the application")
|
|
329
346
|
if not monitoring_context.feature_stats:
|
|
@@ -347,8 +364,13 @@ class HistogramDataDriftApplication(ModelMonitoringApplicationBase):
|
|
|
347
364
|
monitoring_context=monitoring_context,
|
|
348
365
|
metrics_per_feature=metrics_per_feature,
|
|
349
366
|
)
|
|
350
|
-
|
|
367
|
+
stats = self._get_stats(
|
|
368
|
+
metrics=metrics,
|
|
369
|
+
monitoring_context=monitoring_context,
|
|
370
|
+
metrics_per_feature=metrics_per_feature,
|
|
371
|
+
)
|
|
372
|
+
metrics_result_and_stats = metrics + [result] + stats
|
|
351
373
|
monitoring_context.logger.debug(
|
|
352
|
-
"Finished running the application", results=
|
|
374
|
+
"Finished running the application", results=metrics_result_and_stats
|
|
353
375
|
)
|
|
354
|
-
return
|
|
376
|
+
return metrics_result_and_stats
|
|
@@ -17,10 +17,16 @@ import json
|
|
|
17
17
|
import re
|
|
18
18
|
from abc import ABC, abstractmethod
|
|
19
19
|
|
|
20
|
+
from pydantic.v1 import validator
|
|
21
|
+
from pydantic.v1.dataclasses import dataclass
|
|
22
|
+
|
|
20
23
|
import mlrun.common.helpers
|
|
21
24
|
import mlrun.common.model_monitoring.helpers
|
|
22
25
|
import mlrun.common.schemas.model_monitoring.constants as mm_constant
|
|
23
26
|
import mlrun.utils.v3io_clients
|
|
27
|
+
from mlrun.utils import logger
|
|
28
|
+
|
|
29
|
+
_RESULT_EXTRA_DATA_MAX_SIZE = 998
|
|
24
30
|
|
|
25
31
|
|
|
26
32
|
class _ModelMonitoringApplicationDataRes(ABC):
|
|
@@ -38,7 +44,7 @@ class _ModelMonitoringApplicationDataRes(ABC):
|
|
|
38
44
|
raise NotImplementedError
|
|
39
45
|
|
|
40
46
|
|
|
41
|
-
@
|
|
47
|
+
@dataclass
|
|
42
48
|
class ModelMonitoringApplicationResult(_ModelMonitoringApplicationDataRes):
|
|
43
49
|
"""
|
|
44
50
|
Class representing the result of a custom model monitoring application.
|
|
@@ -49,7 +55,10 @@ class ModelMonitoringApplicationResult(_ModelMonitoringApplicationDataRes):
|
|
|
49
55
|
:param value: (float) Value of the application result.
|
|
50
56
|
:param kind: (ResultKindApp) Kind of application result.
|
|
51
57
|
:param status: (ResultStatusApp) Status of the application result.
|
|
52
|
-
:param extra_data: (dict) Extra data associated with the application result.
|
|
58
|
+
:param extra_data: (dict) Extra data associated with the application result. Note that if the extra data is
|
|
59
|
+
exceeding the maximum size of 998 characters, it will be ignored and a message will
|
|
60
|
+
be logged. In this case, we recommend logging the extra data as a separate artifact or
|
|
61
|
+
shortening it.
|
|
53
62
|
"""
|
|
54
63
|
|
|
55
64
|
name: str
|
|
@@ -72,8 +81,23 @@ class ModelMonitoringApplicationResult(_ModelMonitoringApplicationDataRes):
|
|
|
72
81
|
mm_constant.ResultData.RESULT_EXTRA_DATA: json.dumps(self.extra_data),
|
|
73
82
|
}
|
|
74
83
|
|
|
84
|
+
@validator("extra_data")
|
|
85
|
+
@classmethod
|
|
86
|
+
def validate_extra_data_len(cls, result_extra_data: dict):
|
|
87
|
+
"""Ensure that the extra data is not exceeding the maximum size which is important to avoid
|
|
88
|
+
possible storage issues."""
|
|
89
|
+
extra_data_len = len(json.dumps(result_extra_data))
|
|
90
|
+
if extra_data_len > _RESULT_EXTRA_DATA_MAX_SIZE:
|
|
91
|
+
logger.warning(
|
|
92
|
+
f"Extra data is too long and won't be stored: {extra_data_len} characters while the maximum "
|
|
93
|
+
f"is {_RESULT_EXTRA_DATA_MAX_SIZE} characters."
|
|
94
|
+
f"Please shorten the extra data or log it as a separate artifact."
|
|
95
|
+
)
|
|
96
|
+
return {}
|
|
97
|
+
return result_extra_data
|
|
75
98
|
|
|
76
|
-
|
|
99
|
+
|
|
100
|
+
@dataclass
|
|
77
101
|
class ModelMonitoringApplicationMetric(_ModelMonitoringApplicationDataRes):
|
|
78
102
|
"""
|
|
79
103
|
Class representing a single metric of a custom model monitoring application.
|
|
@@ -97,3 +121,31 @@ class ModelMonitoringApplicationMetric(_ModelMonitoringApplicationDataRes):
|
|
|
97
121
|
mm_constant.MetricData.METRIC_NAME: self.name,
|
|
98
122
|
mm_constant.MetricData.METRIC_VALUE: self.value,
|
|
99
123
|
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@dataclasses.dataclass
|
|
127
|
+
class _ModelMonitoringApplicationStats(_ModelMonitoringApplicationDataRes):
|
|
128
|
+
"""
|
|
129
|
+
Class representing the stats of histogram data drift application.
|
|
130
|
+
|
|
131
|
+
:param name (mm_constant.StatsKind) Enum mm_constant.StatsData of the stats data kind of the event
|
|
132
|
+
:param (str) iso format representation of the timestamp the event took place
|
|
133
|
+
:param stats (dict) Dictionary representation of the stats calculated for the event
|
|
134
|
+
|
|
135
|
+
"""
|
|
136
|
+
|
|
137
|
+
name: mm_constant.StatsKind
|
|
138
|
+
timestamp: str
|
|
139
|
+
stats: dict = dataclasses.field(default_factory=dict)
|
|
140
|
+
|
|
141
|
+
def to_dict(self):
|
|
142
|
+
"""
|
|
143
|
+
Convert the object to a dictionary format suitable for writing.
|
|
144
|
+
|
|
145
|
+
:returns: (dict) Dictionary representation of the result.
|
|
146
|
+
"""
|
|
147
|
+
return {
|
|
148
|
+
mm_constant.StatsData.STATS_NAME: self.name,
|
|
149
|
+
mm_constant.StatsData.STATS: self.stats,
|
|
150
|
+
mm_constant.StatsData.TIMESTAMP: self.timestamp,
|
|
151
|
+
}
|