mlrun 1.7.0rc14__py3-none-any.whl → 1.7.0rc22__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.

Files changed (160) hide show
  1. mlrun/__init__.py +10 -1
  2. mlrun/__main__.py +23 -111
  3. mlrun/alerts/__init__.py +15 -0
  4. mlrun/alerts/alert.py +169 -0
  5. mlrun/api/schemas/__init__.py +4 -3
  6. mlrun/artifacts/__init__.py +8 -3
  7. mlrun/artifacts/base.py +36 -253
  8. mlrun/artifacts/dataset.py +9 -190
  9. mlrun/artifacts/manager.py +46 -42
  10. mlrun/artifacts/model.py +9 -141
  11. mlrun/artifacts/plots.py +14 -375
  12. mlrun/common/constants.py +65 -3
  13. mlrun/common/formatters/__init__.py +19 -0
  14. mlrun/{runtimes/mpijob/v1alpha1.py → common/formatters/artifact.py} +6 -14
  15. mlrun/common/formatters/base.py +113 -0
  16. mlrun/common/formatters/function.py +46 -0
  17. mlrun/common/formatters/pipeline.py +53 -0
  18. mlrun/common/formatters/project.py +51 -0
  19. mlrun/{runtimes → common/runtimes}/constants.py +32 -4
  20. mlrun/common/schemas/__init__.py +10 -5
  21. mlrun/common/schemas/alert.py +92 -11
  22. mlrun/common/schemas/api_gateway.py +56 -0
  23. mlrun/common/schemas/artifact.py +15 -5
  24. mlrun/common/schemas/auth.py +2 -0
  25. mlrun/common/schemas/client_spec.py +1 -0
  26. mlrun/common/schemas/frontend_spec.py +1 -0
  27. mlrun/common/schemas/function.py +4 -0
  28. mlrun/common/schemas/model_monitoring/__init__.py +15 -3
  29. mlrun/common/schemas/model_monitoring/constants.py +58 -7
  30. mlrun/common/schemas/model_monitoring/grafana.py +9 -5
  31. mlrun/common/schemas/model_monitoring/model_endpoints.py +86 -2
  32. mlrun/common/schemas/pipeline.py +0 -9
  33. mlrun/common/schemas/project.py +5 -11
  34. mlrun/common/types.py +1 -0
  35. mlrun/config.py +30 -9
  36. mlrun/data_types/to_pandas.py +9 -9
  37. mlrun/datastore/base.py +41 -9
  38. mlrun/datastore/datastore.py +6 -2
  39. mlrun/datastore/datastore_profile.py +56 -4
  40. mlrun/datastore/inmem.py +2 -2
  41. mlrun/datastore/redis.py +2 -2
  42. mlrun/datastore/s3.py +5 -0
  43. mlrun/datastore/sources.py +147 -7
  44. mlrun/datastore/store_resources.py +7 -7
  45. mlrun/datastore/targets.py +110 -42
  46. mlrun/datastore/utils.py +42 -0
  47. mlrun/db/base.py +54 -10
  48. mlrun/db/httpdb.py +282 -79
  49. mlrun/db/nopdb.py +52 -10
  50. mlrun/errors.py +11 -0
  51. mlrun/execution.py +26 -9
  52. mlrun/feature_store/__init__.py +0 -2
  53. mlrun/feature_store/api.py +12 -47
  54. mlrun/feature_store/feature_set.py +9 -0
  55. mlrun/feature_store/feature_vector.py +8 -0
  56. mlrun/feature_store/ingestion.py +7 -6
  57. mlrun/feature_store/retrieval/base.py +9 -4
  58. mlrun/feature_store/retrieval/conversion.py +9 -9
  59. mlrun/feature_store/retrieval/dask_merger.py +2 -0
  60. mlrun/feature_store/retrieval/job.py +9 -3
  61. mlrun/feature_store/retrieval/local_merger.py +2 -0
  62. mlrun/feature_store/retrieval/spark_merger.py +16 -0
  63. mlrun/frameworks/__init__.py +6 -0
  64. mlrun/frameworks/_dl_common/loggers/tensorboard_logger.py +7 -12
  65. mlrun/frameworks/parallel_coordinates.py +2 -1
  66. mlrun/frameworks/tf_keras/__init__.py +4 -1
  67. mlrun/k8s_utils.py +10 -11
  68. mlrun/launcher/base.py +4 -3
  69. mlrun/launcher/client.py +5 -3
  70. mlrun/launcher/local.py +12 -2
  71. mlrun/launcher/remote.py +9 -2
  72. mlrun/lists.py +6 -2
  73. mlrun/model.py +47 -21
  74. mlrun/model_monitoring/__init__.py +1 -1
  75. mlrun/model_monitoring/api.py +42 -18
  76. mlrun/model_monitoring/application.py +5 -305
  77. mlrun/model_monitoring/applications/__init__.py +11 -0
  78. mlrun/model_monitoring/applications/_application_steps.py +157 -0
  79. mlrun/model_monitoring/applications/base.py +280 -0
  80. mlrun/model_monitoring/applications/context.py +214 -0
  81. mlrun/model_monitoring/applications/evidently_base.py +211 -0
  82. mlrun/model_monitoring/applications/histogram_data_drift.py +132 -91
  83. mlrun/model_monitoring/applications/results.py +99 -0
  84. mlrun/model_monitoring/controller.py +3 -1
  85. mlrun/model_monitoring/db/__init__.py +2 -0
  86. mlrun/model_monitoring/db/stores/__init__.py +0 -2
  87. mlrun/model_monitoring/db/stores/base/store.py +22 -37
  88. mlrun/model_monitoring/db/stores/sqldb/models/__init__.py +43 -21
  89. mlrun/model_monitoring/db/stores/sqldb/models/base.py +39 -8
  90. mlrun/model_monitoring/db/stores/sqldb/models/mysql.py +27 -7
  91. mlrun/model_monitoring/db/stores/sqldb/models/sqlite.py +5 -0
  92. mlrun/model_monitoring/db/stores/sqldb/sql_store.py +246 -224
  93. mlrun/model_monitoring/db/stores/v3io_kv/kv_store.py +232 -216
  94. mlrun/model_monitoring/db/tsdb/__init__.py +100 -0
  95. mlrun/model_monitoring/db/tsdb/base.py +316 -0
  96. mlrun/model_monitoring/db/tsdb/helpers.py +30 -0
  97. mlrun/model_monitoring/db/tsdb/tdengine/__init__.py +15 -0
  98. mlrun/model_monitoring/db/tsdb/tdengine/schemas.py +240 -0
  99. mlrun/model_monitoring/db/tsdb/tdengine/stream_graph_steps.py +45 -0
  100. mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connector.py +401 -0
  101. mlrun/model_monitoring/db/tsdb/v3io/__init__.py +15 -0
  102. mlrun/model_monitoring/db/tsdb/v3io/stream_graph_steps.py +117 -0
  103. mlrun/model_monitoring/db/tsdb/v3io/v3io_connector.py +658 -0
  104. mlrun/model_monitoring/evidently_application.py +6 -118
  105. mlrun/model_monitoring/helpers.py +63 -1
  106. mlrun/model_monitoring/model_endpoint.py +3 -2
  107. mlrun/model_monitoring/stream_processing.py +57 -216
  108. mlrun/model_monitoring/writer.py +134 -124
  109. mlrun/package/__init__.py +13 -1
  110. mlrun/package/packagers/__init__.py +6 -1
  111. mlrun/package/utils/_formatter.py +2 -2
  112. mlrun/platforms/__init__.py +10 -9
  113. mlrun/platforms/iguazio.py +21 -202
  114. mlrun/projects/operations.py +24 -12
  115. mlrun/projects/pipelines.py +79 -102
  116. mlrun/projects/project.py +271 -103
  117. mlrun/render.py +15 -14
  118. mlrun/run.py +16 -46
  119. mlrun/runtimes/__init__.py +6 -3
  120. mlrun/runtimes/base.py +14 -7
  121. mlrun/runtimes/daskjob.py +1 -0
  122. mlrun/runtimes/databricks_job/databricks_runtime.py +1 -0
  123. mlrun/runtimes/databricks_job/databricks_wrapper.py +1 -1
  124. mlrun/runtimes/funcdoc.py +0 -28
  125. mlrun/runtimes/kubejob.py +2 -1
  126. mlrun/runtimes/local.py +12 -3
  127. mlrun/runtimes/mpijob/__init__.py +0 -20
  128. mlrun/runtimes/mpijob/v1.py +1 -1
  129. mlrun/runtimes/nuclio/api_gateway.py +194 -84
  130. mlrun/runtimes/nuclio/application/application.py +170 -8
  131. mlrun/runtimes/nuclio/function.py +39 -49
  132. mlrun/runtimes/pod.py +16 -36
  133. mlrun/runtimes/remotesparkjob.py +9 -3
  134. mlrun/runtimes/sparkjob/spark3job.py +1 -1
  135. mlrun/runtimes/utils.py +6 -45
  136. mlrun/serving/__init__.py +8 -1
  137. mlrun/serving/server.py +2 -1
  138. mlrun/serving/states.py +51 -8
  139. mlrun/serving/utils.py +19 -11
  140. mlrun/serving/v2_serving.py +5 -1
  141. mlrun/track/tracker.py +2 -1
  142. mlrun/utils/async_http.py +25 -5
  143. mlrun/utils/helpers.py +157 -83
  144. mlrun/utils/logger.py +39 -7
  145. mlrun/utils/notifications/notification/__init__.py +14 -9
  146. mlrun/utils/notifications/notification/base.py +1 -1
  147. mlrun/utils/notifications/notification/slack.py +34 -7
  148. mlrun/utils/notifications/notification/webhook.py +1 -1
  149. mlrun/utils/notifications/notification_pusher.py +147 -16
  150. mlrun/utils/regex.py +9 -0
  151. mlrun/utils/v3io_clients.py +0 -1
  152. mlrun/utils/version/version.json +2 -2
  153. {mlrun-1.7.0rc14.dist-info → mlrun-1.7.0rc22.dist-info}/METADATA +14 -6
  154. {mlrun-1.7.0rc14.dist-info → mlrun-1.7.0rc22.dist-info}/RECORD +158 -138
  155. mlrun/kfpops.py +0 -865
  156. mlrun/platforms/other.py +0 -305
  157. {mlrun-1.7.0rc14.dist-info → mlrun-1.7.0rc22.dist-info}/LICENSE +0 -0
  158. {mlrun-1.7.0rc14.dist-info → mlrun-1.7.0rc22.dist-info}/WHEEL +0 -0
  159. {mlrun-1.7.0rc14.dist-info → mlrun-1.7.0rc22.dist-info}/entry_points.txt +0 -0
  160. {mlrun-1.7.0rc14.dist-info → mlrun-1.7.0rc22.dist-info}/top_level.txt +0 -0
@@ -12,121 +12,9 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- import uuid
16
- import warnings
17
- from typing import Union
18
-
19
- import pandas as pd
20
- import semver
21
-
22
- from mlrun.errors import MLRunIncompatibleVersionError
23
- from mlrun.model_monitoring.application import ModelMonitoringApplicationBase
24
-
25
- SUPPORTED_EVIDENTLY_VERSION = semver.Version.parse("0.4.11")
26
-
27
-
28
- def _check_evidently_version(*, cur: semver.Version, ref: semver.Version) -> None:
29
- if ref.is_compatible(cur) or (
30
- cur.major == ref.major == 0 and cur.minor == ref.minor and cur.patch > ref.patch
31
- ):
32
- return
33
- if cur.major == ref.major == 0 and cur.minor > ref.minor:
34
- warnings.warn(
35
- f"Evidently version {cur} is not compatible with the tested "
36
- f"version {ref}, use at your own risk."
37
- )
38
- else:
39
- raise MLRunIncompatibleVersionError(
40
- f"Evidently version {cur} is not supported, please change to "
41
- f"{ref} (or another compatible version)."
42
- )
43
-
44
-
45
- _HAS_EVIDENTLY = False
46
- try:
47
- import evidently # noqa: F401
48
-
49
- _check_evidently_version(
50
- cur=semver.Version.parse(evidently.__version__),
51
- ref=SUPPORTED_EVIDENTLY_VERSION,
52
- )
53
- _HAS_EVIDENTLY = True
54
- except ModuleNotFoundError:
55
- pass
56
-
57
-
58
- if _HAS_EVIDENTLY:
59
- from evidently.renderers.notebook_utils import determine_template
60
- from evidently.report.report import Report
61
- from evidently.suite.base_suite import Suite
62
- from evidently.ui.type_aliases import STR_UUID
63
- from evidently.ui.workspace import Workspace
64
- from evidently.utils.dashboard import TemplateParams
65
-
66
-
67
- class EvidentlyModelMonitoringApplicationBase(ModelMonitoringApplicationBase):
68
- def __init__(
69
- self, evidently_workspace_path: str, evidently_project_id: "STR_UUID"
70
- ) -> None:
71
- """
72
- A class for integrating Evidently for mlrun model monitoring within a monitoring application.
73
- Note: evidently is not installed by default in the mlrun/mlrun image.
74
- It must be installed separately to use this class.
75
-
76
- :param evidently_workspace_path: (str) The path to the Evidently workspace.
77
- :param evidently_project_id: (str) The ID of the Evidently project.
78
-
79
- """
80
- if not _HAS_EVIDENTLY:
81
- raise ModuleNotFoundError("Evidently is not installed - the app cannot run")
82
- self.evidently_workspace = Workspace.create(evidently_workspace_path)
83
- self.evidently_project_id = evidently_project_id
84
- self.evidently_project = self.evidently_workspace.get_project(
85
- evidently_project_id
86
- )
87
-
88
- def log_evidently_object(
89
- self, evidently_object: Union["Report", "Suite"], artifact_name: str
90
- ):
91
- """
92
- Logs an Evidently report or suite as an artifact.
93
-
94
- :param evidently_object: (Union[Report, Suite]) The Evidently report or suite object.
95
- :param artifact_name: (str) The name for the logged artifact.
96
- """
97
- evidently_object_html = evidently_object.get_html()
98
- self.context.log_artifact(
99
- artifact_name, body=evidently_object_html.encode("utf-8"), format="html"
100
- )
101
-
102
- def log_project_dashboard(
103
- self,
104
- timestamp_start: pd.Timestamp,
105
- timestamp_end: pd.Timestamp,
106
- artifact_name: str = "dashboard",
107
- ):
108
- """
109
- Logs an Evidently project dashboard.
110
-
111
- :param timestamp_start: (pd.Timestamp) The start timestamp for the dashboard data.
112
- :param timestamp_end: (pd.Timestamp) The end timestamp for the dashboard data.
113
- :param artifact_name: (str) The name for the logged artifact.
114
- """
115
-
116
- dashboard_info = self.evidently_project.build_dashboard_info(
117
- timestamp_start, timestamp_end
118
- )
119
- template_params = TemplateParams(
120
- dashboard_id="pd_" + str(uuid.uuid4()).replace("-", ""),
121
- dashboard_info=dashboard_info,
122
- additional_graphs={},
123
- )
124
-
125
- dashboard_html = self._render(determine_template("inline"), template_params)
126
- self.context.log_artifact(
127
- artifact_name, body=dashboard_html.encode("utf-8"), format="html"
128
- )
129
-
130
- @staticmethod
131
- def _render(temple_func, template_params: "TemplateParams"):
132
- return temple_func(params=template_params)
15
+ # TODO : delete this file in 1.9.0
16
+ from mlrun.model_monitoring.applications import ( # noqa: F401
17
+ _HAS_EVIDENTLY,
18
+ SUPPORTED_EVIDENTLY_VERSION,
19
+ EvidentlyModelMonitoringApplicationBase,
20
+ )
@@ -24,6 +24,11 @@ import mlrun.common.schemas
24
24
  from mlrun.common.schemas.model_monitoring import (
25
25
  EventFieldType,
26
26
  )
27
+ from mlrun.common.schemas.model_monitoring.model_endpoints import (
28
+ ModelEndpointMonitoringMetric,
29
+ ModelEndpointMonitoringMetricType,
30
+ _compose_full_name,
31
+ )
27
32
  from mlrun.model_monitoring.model_endpoint import ModelEndpoint
28
33
  from mlrun.utils import logger
29
34
 
@@ -111,6 +116,24 @@ def get_connection_string(secret_provider: typing.Callable = None) -> str:
111
116
  )
112
117
 
113
118
 
119
+ def get_tsdb_connection_string(
120
+ secret_provider: typing.Optional[typing.Callable] = None,
121
+ ) -> str:
122
+ """Get TSDB connection string from the project secret. If wasn't set, take it from the system
123
+ configurations.
124
+ :param secret_provider: An optional secret provider to get the connection string secret.
125
+ :return: Valid TSDB connection string.
126
+ """
127
+
128
+ return (
129
+ mlrun.get_secret_or_env(
130
+ key=mlrun.common.schemas.model_monitoring.ProjectSecretKeys.TSDB_CONNECTION,
131
+ secret_provider=secret_provider,
132
+ )
133
+ or mlrun.mlconf.model_endpoint_monitoring.tsdb_connection
134
+ )
135
+
136
+
114
137
  def batch_dict2timedelta(batch_dict: _BatchDict) -> datetime.timedelta:
115
138
  """
116
139
  Convert a batch dictionary to timedelta.
@@ -215,7 +238,7 @@ def update_model_endpoint_last_request(
215
238
 
216
239
  def calculate_inputs_statistics(
217
240
  sample_set_statistics: dict, inputs: pd.DataFrame
218
- ) -> dict:
241
+ ) -> mlrun.common.model_monitoring.helpers.FeatureStats:
219
242
  """
220
243
  Calculate the inputs data statistics for drift monitoring purpose.
221
244
 
@@ -260,3 +283,42 @@ def get_endpoint_record(project: str, endpoint_id: str):
260
283
  project=project,
261
284
  )
262
285
  return model_endpoint_store.get_model_endpoint(endpoint_id=endpoint_id)
286
+
287
+
288
+ def get_result_instance_fqn(
289
+ model_endpoint_id: str, app_name: str, result_name: str
290
+ ) -> str:
291
+ return f"{model_endpoint_id}.{app_name}.result.{result_name}"
292
+
293
+
294
+ def get_default_result_instance_fqn(model_endpoint_id: str) -> str:
295
+ return get_result_instance_fqn(
296
+ model_endpoint_id,
297
+ mm_constants.HistogramDataDriftApplicationConstants.NAME,
298
+ mm_constants.HistogramDataDriftApplicationConstants.GENERAL_RESULT_NAME,
299
+ )
300
+
301
+
302
+ def get_invocations_fqn(project: str) -> str:
303
+ return _compose_full_name(
304
+ project=project,
305
+ app=mm_constants.SpecialApps.MLRUN_INFRA,
306
+ name=mm_constants.PredictionsQueryConstants.INVOCATIONS,
307
+ type=ModelEndpointMonitoringMetricType.METRIC,
308
+ )
309
+
310
+
311
+ def get_invocations_metric(project: str) -> ModelEndpointMonitoringMetric:
312
+ """
313
+ Return the invocations metric of any model endpoint in the given project.
314
+
315
+ :param project: The project name.
316
+ :returns: The model monitoring metric object.
317
+ """
318
+ return ModelEndpointMonitoringMetric(
319
+ project=project,
320
+ app=mm_constants.SpecialApps.MLRUN_INFRA,
321
+ type=ModelEndpointMonitoringMetricType.METRIC,
322
+ name=mm_constants.PredictionsQueryConstants.INVOCATIONS,
323
+ full_name=get_invocations_fqn(project),
324
+ )
@@ -17,6 +17,7 @@ from dataclasses import dataclass, field
17
17
  from typing import Any
18
18
 
19
19
  import mlrun.model
20
+ from mlrun.common.model_monitoring.helpers import FeatureStats
20
21
  from mlrun.common.schemas.model_monitoring.constants import (
21
22
  EndpointType,
22
23
  EventKeyMetrics,
@@ -42,8 +43,8 @@ class ModelEndpointSpec(mlrun.model.ModelObj):
42
43
 
43
44
  @dataclass
44
45
  class ModelEndpointStatus(mlrun.model.ModelObj):
45
- feature_stats: dict = field(default_factory=dict)
46
- current_stats: dict = field(default_factory=dict)
46
+ feature_stats: FeatureStats = field(default_factory=dict)
47
+ current_stats: FeatureStats = field(default_factory=dict)
47
48
  first_request: str = ""
48
49
  last_request: str = ""
49
50
  error_count: int = 0