mlrun 1.7.1rc4__py3-none-any.whl → 1.8.0rc8__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 (257) hide show
  1. mlrun/__init__.py +23 -21
  2. mlrun/__main__.py +3 -3
  3. mlrun/alerts/alert.py +148 -14
  4. mlrun/artifacts/__init__.py +1 -2
  5. mlrun/artifacts/base.py +46 -12
  6. mlrun/artifacts/dataset.py +16 -16
  7. mlrun/artifacts/document.py +334 -0
  8. mlrun/artifacts/manager.py +15 -13
  9. mlrun/artifacts/model.py +66 -53
  10. mlrun/common/constants.py +7 -0
  11. mlrun/common/formatters/__init__.py +1 -0
  12. mlrun/common/formatters/feature_set.py +1 -0
  13. mlrun/common/formatters/function.py +1 -0
  14. mlrun/{model_monitoring/db/stores/base/__init__.py → common/formatters/model_endpoint.py} +16 -1
  15. mlrun/common/formatters/pipeline.py +1 -2
  16. mlrun/common/formatters/project.py +9 -0
  17. mlrun/common/model_monitoring/__init__.py +0 -5
  18. mlrun/common/model_monitoring/helpers.py +1 -29
  19. mlrun/common/runtimes/constants.py +1 -2
  20. mlrun/common/schemas/__init__.py +6 -2
  21. mlrun/common/schemas/alert.py +111 -19
  22. mlrun/common/schemas/api_gateway.py +3 -3
  23. mlrun/common/schemas/artifact.py +11 -7
  24. mlrun/common/schemas/auth.py +6 -4
  25. mlrun/common/schemas/background_task.py +7 -7
  26. mlrun/common/schemas/client_spec.py +2 -3
  27. mlrun/common/schemas/clusterization_spec.py +2 -2
  28. mlrun/common/schemas/common.py +53 -3
  29. mlrun/common/schemas/constants.py +15 -0
  30. mlrun/common/schemas/datastore_profile.py +1 -1
  31. mlrun/common/schemas/feature_store.py +9 -9
  32. mlrun/common/schemas/frontend_spec.py +4 -4
  33. mlrun/common/schemas/function.py +10 -10
  34. mlrun/common/schemas/hub.py +1 -1
  35. mlrun/common/schemas/k8s.py +3 -3
  36. mlrun/common/schemas/memory_reports.py +3 -3
  37. mlrun/common/schemas/model_monitoring/__init__.py +2 -1
  38. mlrun/common/schemas/model_monitoring/constants.py +66 -14
  39. mlrun/common/schemas/model_monitoring/grafana.py +1 -1
  40. mlrun/common/schemas/model_monitoring/model_endpoints.py +91 -147
  41. mlrun/common/schemas/notification.py +24 -3
  42. mlrun/common/schemas/object.py +1 -1
  43. mlrun/common/schemas/pagination.py +4 -4
  44. mlrun/common/schemas/partition.py +137 -0
  45. mlrun/common/schemas/pipeline.py +2 -2
  46. mlrun/common/schemas/project.py +25 -17
  47. mlrun/common/schemas/runs.py +2 -2
  48. mlrun/common/schemas/runtime_resource.py +5 -5
  49. mlrun/common/schemas/schedule.py +1 -1
  50. mlrun/common/schemas/secret.py +1 -1
  51. mlrun/common/schemas/tag.py +3 -3
  52. mlrun/common/schemas/workflow.py +5 -5
  53. mlrun/config.py +67 -10
  54. mlrun/data_types/__init__.py +0 -2
  55. mlrun/data_types/infer.py +3 -1
  56. mlrun/data_types/spark.py +2 -1
  57. mlrun/datastore/__init__.py +0 -2
  58. mlrun/datastore/alibaba_oss.py +4 -1
  59. mlrun/datastore/azure_blob.py +4 -1
  60. mlrun/datastore/base.py +12 -4
  61. mlrun/datastore/datastore.py +9 -3
  62. mlrun/datastore/datastore_profile.py +79 -20
  63. mlrun/datastore/dbfs_store.py +4 -1
  64. mlrun/datastore/filestore.py +4 -1
  65. mlrun/datastore/google_cloud_storage.py +4 -1
  66. mlrun/datastore/hdfs.py +4 -1
  67. mlrun/datastore/inmem.py +4 -1
  68. mlrun/datastore/redis.py +4 -1
  69. mlrun/datastore/s3.py +4 -1
  70. mlrun/datastore/sources.py +52 -51
  71. mlrun/datastore/store_resources.py +0 -2
  72. mlrun/datastore/targets.py +21 -21
  73. mlrun/datastore/utils.py +2 -2
  74. mlrun/datastore/v3io.py +4 -1
  75. mlrun/datastore/vectorstore.py +194 -0
  76. mlrun/datastore/wasbfs/fs.py +13 -12
  77. mlrun/db/base.py +208 -82
  78. mlrun/db/factory.py +0 -3
  79. mlrun/db/httpdb.py +1237 -386
  80. mlrun/db/nopdb.py +201 -74
  81. mlrun/errors.py +2 -2
  82. mlrun/execution.py +136 -50
  83. mlrun/feature_store/__init__.py +0 -2
  84. mlrun/feature_store/api.py +41 -40
  85. mlrun/feature_store/common.py +9 -9
  86. mlrun/feature_store/feature_set.py +20 -18
  87. mlrun/feature_store/feature_vector.py +27 -24
  88. mlrun/feature_store/retrieval/base.py +14 -9
  89. mlrun/feature_store/retrieval/job.py +2 -1
  90. mlrun/feature_store/steps.py +2 -2
  91. mlrun/features.py +30 -13
  92. mlrun/frameworks/__init__.py +1 -2
  93. mlrun/frameworks/_common/__init__.py +1 -2
  94. mlrun/frameworks/_common/artifacts_library.py +2 -2
  95. mlrun/frameworks/_common/mlrun_interface.py +10 -6
  96. mlrun/frameworks/_common/model_handler.py +29 -27
  97. mlrun/frameworks/_common/producer.py +3 -1
  98. mlrun/frameworks/_dl_common/__init__.py +1 -2
  99. mlrun/frameworks/_dl_common/loggers/__init__.py +1 -2
  100. mlrun/frameworks/_dl_common/loggers/mlrun_logger.py +4 -4
  101. mlrun/frameworks/_dl_common/loggers/tensorboard_logger.py +3 -3
  102. mlrun/frameworks/_ml_common/__init__.py +1 -2
  103. mlrun/frameworks/_ml_common/loggers/__init__.py +1 -2
  104. mlrun/frameworks/_ml_common/model_handler.py +21 -21
  105. mlrun/frameworks/_ml_common/plans/__init__.py +1 -2
  106. mlrun/frameworks/_ml_common/plans/confusion_matrix_plan.py +3 -1
  107. mlrun/frameworks/_ml_common/plans/dataset_plan.py +3 -3
  108. mlrun/frameworks/_ml_common/plans/roc_curve_plan.py +4 -4
  109. mlrun/frameworks/auto_mlrun/__init__.py +1 -2
  110. mlrun/frameworks/auto_mlrun/auto_mlrun.py +22 -15
  111. mlrun/frameworks/huggingface/__init__.py +1 -2
  112. mlrun/frameworks/huggingface/model_server.py +9 -9
  113. mlrun/frameworks/lgbm/__init__.py +47 -44
  114. mlrun/frameworks/lgbm/callbacks/__init__.py +1 -2
  115. mlrun/frameworks/lgbm/callbacks/logging_callback.py +4 -2
  116. mlrun/frameworks/lgbm/callbacks/mlrun_logging_callback.py +4 -2
  117. mlrun/frameworks/lgbm/mlrun_interfaces/__init__.py +1 -2
  118. mlrun/frameworks/lgbm/mlrun_interfaces/mlrun_interface.py +5 -5
  119. mlrun/frameworks/lgbm/model_handler.py +15 -11
  120. mlrun/frameworks/lgbm/model_server.py +11 -7
  121. mlrun/frameworks/lgbm/utils.py +2 -2
  122. mlrun/frameworks/onnx/__init__.py +1 -2
  123. mlrun/frameworks/onnx/dataset.py +3 -3
  124. mlrun/frameworks/onnx/mlrun_interface.py +2 -2
  125. mlrun/frameworks/onnx/model_handler.py +7 -5
  126. mlrun/frameworks/onnx/model_server.py +8 -6
  127. mlrun/frameworks/parallel_coordinates.py +11 -11
  128. mlrun/frameworks/pytorch/__init__.py +22 -23
  129. mlrun/frameworks/pytorch/callbacks/__init__.py +1 -2
  130. mlrun/frameworks/pytorch/callbacks/callback.py +2 -1
  131. mlrun/frameworks/pytorch/callbacks/logging_callback.py +15 -8
  132. mlrun/frameworks/pytorch/callbacks/mlrun_logging_callback.py +19 -12
  133. mlrun/frameworks/pytorch/callbacks/tensorboard_logging_callback.py +22 -15
  134. mlrun/frameworks/pytorch/callbacks_handler.py +36 -30
  135. mlrun/frameworks/pytorch/mlrun_interface.py +17 -17
  136. mlrun/frameworks/pytorch/model_handler.py +21 -17
  137. mlrun/frameworks/pytorch/model_server.py +13 -9
  138. mlrun/frameworks/sklearn/__init__.py +19 -18
  139. mlrun/frameworks/sklearn/estimator.py +2 -2
  140. mlrun/frameworks/sklearn/metric.py +3 -3
  141. mlrun/frameworks/sklearn/metrics_library.py +8 -6
  142. mlrun/frameworks/sklearn/mlrun_interface.py +3 -2
  143. mlrun/frameworks/sklearn/model_handler.py +4 -3
  144. mlrun/frameworks/tf_keras/__init__.py +11 -12
  145. mlrun/frameworks/tf_keras/callbacks/__init__.py +1 -2
  146. mlrun/frameworks/tf_keras/callbacks/logging_callback.py +17 -14
  147. mlrun/frameworks/tf_keras/callbacks/mlrun_logging_callback.py +15 -12
  148. mlrun/frameworks/tf_keras/callbacks/tensorboard_logging_callback.py +21 -18
  149. mlrun/frameworks/tf_keras/model_handler.py +17 -13
  150. mlrun/frameworks/tf_keras/model_server.py +12 -8
  151. mlrun/frameworks/xgboost/__init__.py +19 -18
  152. mlrun/frameworks/xgboost/model_handler.py +13 -9
  153. mlrun/launcher/base.py +3 -4
  154. mlrun/launcher/local.py +1 -1
  155. mlrun/launcher/remote.py +1 -1
  156. mlrun/lists.py +4 -3
  157. mlrun/model.py +117 -46
  158. mlrun/model_monitoring/__init__.py +4 -4
  159. mlrun/model_monitoring/api.py +61 -59
  160. mlrun/model_monitoring/applications/_application_steps.py +17 -17
  161. mlrun/model_monitoring/applications/base.py +165 -6
  162. mlrun/model_monitoring/applications/context.py +88 -37
  163. mlrun/model_monitoring/applications/evidently_base.py +1 -2
  164. mlrun/model_monitoring/applications/histogram_data_drift.py +43 -21
  165. mlrun/model_monitoring/applications/results.py +55 -3
  166. mlrun/model_monitoring/controller.py +207 -239
  167. mlrun/model_monitoring/db/__init__.py +0 -2
  168. mlrun/model_monitoring/db/_schedules.py +156 -0
  169. mlrun/model_monitoring/db/_stats.py +189 -0
  170. mlrun/model_monitoring/db/tsdb/base.py +78 -25
  171. mlrun/model_monitoring/db/tsdb/tdengine/schemas.py +90 -16
  172. mlrun/model_monitoring/db/tsdb/tdengine/stream_graph_steps.py +33 -0
  173. mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connector.py +279 -59
  174. mlrun/model_monitoring/db/tsdb/v3io/stream_graph_steps.py +1 -0
  175. mlrun/model_monitoring/db/tsdb/v3io/v3io_connector.py +78 -17
  176. mlrun/model_monitoring/helpers.py +152 -49
  177. mlrun/model_monitoring/stream_processing.py +99 -283
  178. mlrun/model_monitoring/tracking_policy.py +10 -3
  179. mlrun/model_monitoring/writer.py +48 -36
  180. mlrun/package/__init__.py +3 -6
  181. mlrun/package/context_handler.py +1 -1
  182. mlrun/package/packager.py +12 -9
  183. mlrun/package/packagers/__init__.py +0 -2
  184. mlrun/package/packagers/default_packager.py +14 -11
  185. mlrun/package/packagers/numpy_packagers.py +16 -7
  186. mlrun/package/packagers/pandas_packagers.py +18 -18
  187. mlrun/package/packagers/python_standard_library_packagers.py +25 -11
  188. mlrun/package/packagers_manager.py +31 -14
  189. mlrun/package/utils/__init__.py +0 -3
  190. mlrun/package/utils/_pickler.py +6 -6
  191. mlrun/platforms/__init__.py +47 -16
  192. mlrun/platforms/iguazio.py +4 -1
  193. mlrun/projects/operations.py +27 -27
  194. mlrun/projects/pipelines.py +75 -38
  195. mlrun/projects/project.py +865 -206
  196. mlrun/run.py +53 -10
  197. mlrun/runtimes/__init__.py +1 -3
  198. mlrun/runtimes/base.py +15 -11
  199. mlrun/runtimes/daskjob.py +9 -9
  200. mlrun/runtimes/generators.py +2 -1
  201. mlrun/runtimes/kubejob.py +4 -5
  202. mlrun/runtimes/mounts.py +572 -0
  203. mlrun/runtimes/mpijob/__init__.py +0 -2
  204. mlrun/runtimes/mpijob/abstract.py +7 -6
  205. mlrun/runtimes/nuclio/api_gateway.py +7 -7
  206. mlrun/runtimes/nuclio/application/application.py +11 -11
  207. mlrun/runtimes/nuclio/function.py +19 -17
  208. mlrun/runtimes/nuclio/serving.py +18 -11
  209. mlrun/runtimes/pod.py +154 -45
  210. mlrun/runtimes/remotesparkjob.py +3 -2
  211. mlrun/runtimes/sparkjob/__init__.py +0 -2
  212. mlrun/runtimes/sparkjob/spark3job.py +21 -11
  213. mlrun/runtimes/utils.py +6 -5
  214. mlrun/serving/merger.py +6 -4
  215. mlrun/serving/remote.py +18 -17
  216. mlrun/serving/routers.py +185 -172
  217. mlrun/serving/server.py +7 -1
  218. mlrun/serving/states.py +97 -78
  219. mlrun/serving/utils.py +13 -2
  220. mlrun/serving/v1_serving.py +3 -2
  221. mlrun/serving/v2_serving.py +74 -65
  222. mlrun/track/__init__.py +1 -1
  223. mlrun/track/tracker.py +2 -2
  224. mlrun/track/trackers/mlflow_tracker.py +6 -5
  225. mlrun/utils/async_http.py +1 -1
  226. mlrun/utils/clones.py +1 -1
  227. mlrun/utils/helpers.py +66 -18
  228. mlrun/utils/logger.py +106 -4
  229. mlrun/utils/notifications/notification/__init__.py +22 -19
  230. mlrun/utils/notifications/notification/base.py +33 -14
  231. mlrun/utils/notifications/notification/console.py +6 -6
  232. mlrun/utils/notifications/notification/git.py +11 -11
  233. mlrun/utils/notifications/notification/ipython.py +10 -9
  234. mlrun/utils/notifications/notification/mail.py +176 -0
  235. mlrun/utils/notifications/notification/slack.py +6 -6
  236. mlrun/utils/notifications/notification/webhook.py +6 -6
  237. mlrun/utils/notifications/notification_pusher.py +86 -44
  238. mlrun/utils/regex.py +3 -1
  239. mlrun/utils/version/version.json +2 -2
  240. {mlrun-1.7.1rc4.dist-info → mlrun-1.8.0rc8.dist-info}/METADATA +191 -186
  241. mlrun-1.8.0rc8.dist-info/RECORD +347 -0
  242. {mlrun-1.7.1rc4.dist-info → mlrun-1.8.0rc8.dist-info}/WHEEL +1 -1
  243. mlrun/model_monitoring/db/stores/__init__.py +0 -136
  244. mlrun/model_monitoring/db/stores/base/store.py +0 -213
  245. mlrun/model_monitoring/db/stores/sqldb/__init__.py +0 -13
  246. mlrun/model_monitoring/db/stores/sqldb/models/__init__.py +0 -71
  247. mlrun/model_monitoring/db/stores/sqldb/models/base.py +0 -190
  248. mlrun/model_monitoring/db/stores/sqldb/models/mysql.py +0 -103
  249. mlrun/model_monitoring/db/stores/sqldb/models/sqlite.py +0 -40
  250. mlrun/model_monitoring/db/stores/sqldb/sql_store.py +0 -659
  251. mlrun/model_monitoring/db/stores/v3io_kv/__init__.py +0 -13
  252. mlrun/model_monitoring/db/stores/v3io_kv/kv_store.py +0 -726
  253. mlrun/model_monitoring/model_endpoint.py +0 -118
  254. mlrun-1.7.1rc4.dist-info/RECORD +0 -351
  255. {mlrun-1.7.1rc4.dist-info → mlrun-1.8.0rc8.dist-info}/LICENSE +0 -0
  256. {mlrun-1.7.1rc4.dist-info → mlrun-1.8.0rc8.dist-info}/entry_points.txt +0 -0
  257. {mlrun-1.7.1rc4.dist-info → mlrun-1.8.0rc8.dist-info}/top_level.txt +0 -0
mlrun/serving/states.py CHANGED
@@ -25,7 +25,7 @@ import pathlib
25
25
  import traceback
26
26
  from copy import copy, deepcopy
27
27
  from inspect import getfullargspec, signature
28
- from typing import Any, Union
28
+ from typing import Any, Optional, Union
29
29
 
30
30
  import storey.utils
31
31
 
@@ -104,7 +104,12 @@ class BaseStep(ModelObj):
104
104
  default_shape = "ellipse"
105
105
  _dict_fields = ["kind", "comment", "after", "on_error"]
106
106
 
107
- def __init__(self, name: str = None, after: list = None, shape: str = None):
107
+ def __init__(
108
+ self,
109
+ name: Optional[str] = None,
110
+ after: Optional[list] = None,
111
+ shape: Optional[str] = None,
112
+ ):
108
113
  self.name = name
109
114
  self._parent = None
110
115
  self.comment = None
@@ -154,14 +159,14 @@ class BaseStep(ModelObj):
154
159
 
155
160
  def error_handler(
156
161
  self,
157
- name: str = None,
162
+ name: Optional[str] = None,
158
163
  class_name=None,
159
164
  handler=None,
160
165
  before=None,
161
166
  function=None,
162
- full_event: bool = None,
163
- input_path: str = None,
164
- result_path: str = None,
167
+ full_event: Optional[bool] = None,
168
+ input_path: Optional[str] = None,
169
+ result_path: Optional[str] = None,
165
170
  **class_args,
166
171
  ):
167
172
  """set error handler on a step or the entire graph (to be executed on failure/raise)
@@ -297,13 +302,13 @@ class BaseStep(ModelObj):
297
302
  def to(
298
303
  self,
299
304
  class_name: Union[str, StepToDict] = None,
300
- name: str = None,
301
- handler: str = None,
302
- graph_shape: str = None,
303
- function: str = None,
304
- full_event: bool = None,
305
- input_path: str = None,
306
- result_path: str = None,
305
+ name: Optional[str] = None,
306
+ handler: Optional[str] = None,
307
+ graph_shape: Optional[str] = None,
308
+ function: Optional[str] = None,
309
+ full_event: Optional[bool] = None,
310
+ input_path: Optional[str] = None,
311
+ result_path: Optional[str] = None,
307
312
  **class_args,
308
313
  ):
309
314
  """add a step right after this step and return the new step
@@ -404,16 +409,16 @@ class TaskStep(BaseStep):
404
409
 
405
410
  def __init__(
406
411
  self,
407
- class_name: Union[str, type] = None,
408
- class_args: dict = None,
409
- handler: str = None,
410
- name: str = None,
411
- after: list = None,
412
- full_event: bool = None,
413
- function: str = None,
414
- responder: bool = None,
415
- input_path: str = None,
416
- result_path: str = None,
412
+ class_name: Optional[Union[str, type]] = None,
413
+ class_args: Optional[dict] = None,
414
+ handler: Optional[str] = None,
415
+ name: Optional[str] = None,
416
+ after: Optional[list] = None,
417
+ full_event: Optional[bool] = None,
418
+ function: Optional[str] = None,
419
+ responder: Optional[bool] = None,
420
+ input_path: Optional[str] = None,
421
+ result_path: Optional[str] = None,
417
422
  ):
418
423
  super().__init__(name, after)
419
424
  self.class_name = class_name
@@ -552,6 +557,8 @@ class TaskStep(BaseStep):
552
557
  self._object.post_init(mode)
553
558
  if hasattr(self._object, "model_endpoint_uid"):
554
559
  self.endpoint_uid = self._object.model_endpoint_uid
560
+ if hasattr(self._object, "name"):
561
+ self.endpoint_name = self._object.name
555
562
 
556
563
  def respond(self):
557
564
  """mark this step as the responder.
@@ -607,16 +614,16 @@ class MonitoringApplicationStep(TaskStep):
607
614
 
608
615
  def __init__(
609
616
  self,
610
- class_name: Union[str, type] = None,
611
- class_args: dict = None,
612
- handler: str = None,
613
- name: str = None,
614
- after: list = None,
615
- full_event: bool = None,
616
- function: str = None,
617
- responder: bool = None,
618
- input_path: str = None,
619
- result_path: str = None,
617
+ class_name: Optional[Union[str, type]] = None,
618
+ class_args: Optional[dict] = None,
619
+ handler: Optional[str] = None,
620
+ name: Optional[str] = None,
621
+ after: Optional[list] = None,
622
+ full_event: Optional[bool] = None,
623
+ function: Optional[str] = None,
624
+ responder: Optional[bool] = None,
625
+ input_path: Optional[str] = None,
626
+ result_path: Optional[str] = None,
620
627
  ):
621
628
  super().__init__(
622
629
  class_name=class_name,
@@ -641,16 +648,16 @@ class ErrorStep(TaskStep):
641
648
 
642
649
  def __init__(
643
650
  self,
644
- class_name: Union[str, type] = None,
645
- class_args: dict = None,
646
- handler: str = None,
647
- name: str = None,
648
- after: list = None,
649
- full_event: bool = None,
650
- function: str = None,
651
- responder: bool = None,
652
- input_path: str = None,
653
- result_path: str = None,
651
+ class_name: Optional[Union[str, type]] = None,
652
+ class_args: Optional[dict] = None,
653
+ handler: Optional[str] = None,
654
+ name: Optional[str] = None,
655
+ after: Optional[list] = None,
656
+ full_event: Optional[bool] = None,
657
+ function: Optional[str] = None,
658
+ responder: Optional[bool] = None,
659
+ input_path: Optional[str] = None,
660
+ result_path: Optional[str] = None,
654
661
  ):
655
662
  super().__init__(
656
663
  class_name=class_name,
@@ -678,14 +685,14 @@ class RouterStep(TaskStep):
678
685
 
679
686
  def __init__(
680
687
  self,
681
- class_name: Union[str, type] = None,
682
- class_args: dict = None,
683
- handler: str = None,
684
- routes: list = None,
685
- name: str = None,
686
- function: str = None,
687
- input_path: str = None,
688
- result_path: str = None,
688
+ class_name: Optional[Union[str, type]] = None,
689
+ class_args: Optional[dict] = None,
690
+ handler: Optional[str] = None,
691
+ routes: Optional[list] = None,
692
+ name: Optional[str] = None,
693
+ function: Optional[str] = None,
694
+ input_path: Optional[str] = None,
695
+ result_path: Optional[str] = None,
689
696
  ):
690
697
  super().__init__(
691
698
  class_name,
@@ -813,12 +820,12 @@ class QueueStep(BaseStep):
813
820
 
814
821
  def __init__(
815
822
  self,
816
- name: str = None,
817
- path: str = None,
818
- after: list = None,
819
- shards: int = None,
820
- retention_in_hours: int = None,
821
- trigger_args: dict = None,
823
+ name: Optional[str] = None,
824
+ path: Optional[str] = None,
825
+ after: Optional[list] = None,
826
+ shards: Optional[int] = None,
827
+ retention_in_hours: Optional[int] = None,
828
+ trigger_args: Optional[dict] = None,
822
829
  **options,
823
830
  ):
824
831
  super().__init__(name, after)
@@ -850,13 +857,13 @@ class QueueStep(BaseStep):
850
857
  def to(
851
858
  self,
852
859
  class_name: Union[str, StepToDict] = None,
853
- name: str = None,
854
- handler: str = None,
855
- graph_shape: str = None,
856
- function: str = None,
857
- full_event: bool = None,
858
- input_path: str = None,
859
- result_path: str = None,
860
+ name: Optional[str] = None,
861
+ handler: Optional[str] = None,
862
+ graph_shape: Optional[str] = None,
863
+ function: Optional[str] = None,
864
+ full_event: Optional[bool] = None,
865
+ input_path: Optional[str] = None,
866
+ result_path: Optional[str] = None,
860
867
  **class_args,
861
868
  ):
862
869
  if not function:
@@ -905,7 +912,7 @@ class FlowStep(BaseStep):
905
912
  self,
906
913
  name=None,
907
914
  steps=None,
908
- after: list = None,
915
+ after: Optional[list] = None,
909
916
  engine=None,
910
917
  final_step=None,
911
918
  ):
@@ -948,9 +955,9 @@ class FlowStep(BaseStep):
948
955
  before=None,
949
956
  graph_shape=None,
950
957
  function=None,
951
- full_event: bool = None,
952
- input_path: str = None,
953
- result_path: str = None,
958
+ full_event: Optional[bool] = None,
959
+ input_path: Optional[str] = None,
960
+ result_path: Optional[str] = None,
954
961
  **class_args,
955
962
  ):
956
963
  """add task, queue or router step/class to the flow
@@ -1037,7 +1044,7 @@ class FlowStep(BaseStep):
1037
1044
  self._last_added = step
1038
1045
  return step
1039
1046
 
1040
- def clear_children(self, steps: list = None):
1047
+ def clear_children(self, steps: Optional[list] = None):
1041
1048
  """remove some or all of the states, empty/None for all"""
1042
1049
  if not steps:
1043
1050
  steps = self._steps.keys()
@@ -1282,11 +1289,19 @@ class FlowStep(BaseStep):
1282
1289
  if self._controller:
1283
1290
  # async flow (using storey)
1284
1291
  event._awaitable_result = None
1285
- resp = self._controller.emit(
1286
- event, return_awaitable_result=self._wait_for_result
1287
- )
1288
- if self._wait_for_result and resp:
1289
- return resp.await_result()
1292
+ if self.context.is_mock:
1293
+ resp = self._controller.emit(
1294
+ event, return_awaitable_result=self._wait_for_result
1295
+ )
1296
+ if self._wait_for_result and resp:
1297
+ return resp.await_result()
1298
+ else:
1299
+ resp_awaitable = self._controller.emit(
1300
+ event, await_result=self._wait_for_result
1301
+ )
1302
+ if self._wait_for_result:
1303
+ return resp_awaitable
1304
+ return self._await_and_return_id(resp_awaitable, event)
1290
1305
  event = copy(event)
1291
1306
  event.body = {"id": event.id}
1292
1307
  return event
@@ -1554,8 +1569,8 @@ def params_to_step(
1554
1569
  graph_shape=None,
1555
1570
  function=None,
1556
1571
  full_event=None,
1557
- input_path: str = None,
1558
- result_path: str = None,
1572
+ input_path: Optional[str] = None,
1573
+ result_path: Optional[str] = None,
1559
1574
  class_args=None,
1560
1575
  ):
1561
1576
  """return step object from provided params or classes/objects"""
@@ -1703,8 +1718,12 @@ def _init_async_objects(context, steps):
1703
1718
  is_explicit_ack_supported(context) and mlrun.mlconf.is_explicit_ack_enabled()
1704
1719
  )
1705
1720
 
1706
- # TODO: Change to AsyncEmitSource once we can drop support for nuclio<1.12.10
1707
- default_source = storey.SyncEmitSource(
1721
+ if context.is_mock:
1722
+ source_class = storey.SyncEmitSource
1723
+ else:
1724
+ source_class = storey.AsyncEmitSource
1725
+
1726
+ default_source = source_class(
1708
1727
  context=context,
1709
1728
  explicit_ack=explicit_ack,
1710
1729
  **source_args,
mlrun/serving/utils.py CHANGED
@@ -13,6 +13,7 @@
13
13
  # limitations under the License.
14
14
  #
15
15
  import inspect
16
+ from typing import Optional
16
17
 
17
18
  from mlrun.utils import get_in, update_in
18
19
 
@@ -55,7 +56,12 @@ class StepToDict:
55
56
  "kwargs",
56
57
  ]
57
58
 
58
- def to_dict(self, fields: list = None, exclude: list = None, strip: bool = False):
59
+ def to_dict(
60
+ self,
61
+ fields: Optional[list] = None,
62
+ exclude: Optional[list] = None,
63
+ strip: bool = False,
64
+ ):
59
65
  """convert the step object to a python dictionary"""
60
66
  fields = fields or getattr(self, "_dict_fields", None)
61
67
  if not fields:
@@ -105,5 +111,10 @@ class MonitoringApplicationToDict(StepToDict):
105
111
  class RouterToDict(StepToDict):
106
112
  _STEP_KIND = "router"
107
113
 
108
- def to_dict(self, fields: list = None, exclude: list = None, strip: bool = False):
114
+ def to_dict(
115
+ self,
116
+ fields: Optional[list] = None,
117
+ exclude: Optional[list] = None,
118
+ strip: bool = False,
119
+ ):
109
120
  return super().to_dict(exclude=["routes"], strip=strip)
@@ -18,6 +18,7 @@ import socket
18
18
  from copy import deepcopy
19
19
  from datetime import datetime
20
20
  from io import BytesIO
21
+ from typing import Optional
21
22
  from urllib.request import urlopen
22
23
 
23
24
  import nuclio
@@ -33,7 +34,7 @@ serving_handler = "handler"
33
34
  def new_v1_model_server(
34
35
  name,
35
36
  model_class: str,
36
- models: dict = None,
37
+ models: Optional[dict] = None,
37
38
  filename="",
38
39
  protocol="",
39
40
  image="",
@@ -68,7 +69,7 @@ def new_v1_model_server(
68
69
 
69
70
 
70
71
  class MLModelServer:
71
- def __init__(self, name: str, model_dir: str = None, model=None):
72
+ def __init__(self, name: str, model_dir: Optional[str] = None, model=None):
72
73
  self.name = name
73
74
  self.ready = False
74
75
  self.model_dir = model_dir
@@ -21,10 +21,9 @@ import mlrun.artifacts
21
21
  import mlrun.common.model_monitoring.helpers
22
22
  import mlrun.common.schemas.model_monitoring
23
23
  import mlrun.model_monitoring
24
- from mlrun.errors import err_to_str
25
24
  from mlrun.utils import logger, now_date
26
25
 
27
- from ..common.helpers import parse_versioned_object_uri
26
+ from ..common.schemas.model_monitoring import ModelEndpointSchema
28
27
  from .server import GraphServer
29
28
  from .utils import StepToDict, _extract_input_data, _update_result_body
30
29
 
@@ -33,12 +32,12 @@ class V2ModelServer(StepToDict):
33
32
  def __init__(
34
33
  self,
35
34
  context=None,
36
- name: str = None,
37
- model_path: str = None,
35
+ name: Optional[str] = None,
36
+ model_path: Optional[str] = None,
38
37
  model=None,
39
38
  protocol=None,
40
- input_path: str = None,
41
- result_path: str = None,
39
+ input_path: Optional[str] = None,
40
+ result_path: Optional[str] = None,
42
41
  shard_by_endpoint: Optional[bool] = None,
43
42
  **kwargs,
44
43
  ):
@@ -110,12 +109,6 @@ class V2ModelServer(StepToDict):
110
109
  self._result_path = result_path
111
110
  self._kwargs = kwargs # for to_dict()
112
111
  self._params = kwargs
113
- self._model_logger = (
114
- _ModelLogPusher(self, context)
115
- if context and context.stream.enabled
116
- else None
117
- )
118
-
119
112
  self.metrics = {}
120
113
  self.labels = {}
121
114
  self.model = None
@@ -125,6 +118,7 @@ class V2ModelServer(StepToDict):
125
118
  self._versioned_model_name = None
126
119
  self.model_endpoint_uid = None
127
120
  self.shard_by_endpoint = shard_by_endpoint
121
+ self._model_logger = None
128
122
 
129
123
  def _load_and_update_state(self):
130
124
  try:
@@ -157,6 +151,11 @@ class V2ModelServer(StepToDict):
157
151
  self.model_endpoint_uid = _init_endpoint_record(
158
152
  graph_server=server, model=self
159
153
  )
154
+ self._model_logger = (
155
+ _ModelLogPusher(self, self.context)
156
+ if self.context and self.context.stream.enabled
157
+ else None
158
+ )
160
159
 
161
160
  def get_param(self, key: str, default=None):
162
161
  """get param by key (specified in the model or the function)"""
@@ -474,7 +473,7 @@ class V2ModelServer(StepToDict):
474
473
 
475
474
 
476
475
  class _ModelLogPusher:
477
- def __init__(self, model, context, output_stream=None):
476
+ def __init__(self, model: V2ModelServer, context, output_stream=None):
478
477
  self.model = model
479
478
  self.verbose = context.verbose
480
479
  self.hostname = context.stream.hostname
@@ -496,6 +495,7 @@ class _ModelLogPusher:
496
495
  "version": self.model.version,
497
496
  "host": self.hostname,
498
497
  "function_uri": self.function_uri,
498
+ "endpoint_id": self.model.model_endpoint_uid,
499
499
  }
500
500
  if getattr(self.model, "labels", None):
501
501
  base_data["labels"] = self.model.labels
@@ -567,26 +567,13 @@ def _init_endpoint_record(
567
567
  """
568
568
 
569
569
  logger.info("Initializing endpoint records")
570
-
571
- # Generate required values for the model endpoint record
572
- try:
573
- # Getting project name from the function uri
574
- project, uri, tag, hash_key = parse_versioned_object_uri(
575
- graph_server.function_uri
576
- )
577
- except Exception as e:
578
- logger.error("Failed to parse function URI", exc=err_to_str(e))
579
- return None
580
-
581
- # Generating model endpoint ID based on function uri and model version
582
- uid = mlrun.common.model_monitoring.create_model_endpoint_uid(
583
- function_uri=graph_server.function_uri,
584
- versioned_model=model.versioned_model_name,
585
- ).uid
586
-
570
+ if not model.model_spec:
571
+ model.get_model()
587
572
  try:
588
573
  model_ep = mlrun.get_run_db().get_model_endpoint(
589
- project=project, endpoint_id=uid
574
+ project=graph_server.project,
575
+ name=model.name,
576
+ function_name=graph_server.function_name,
590
577
  )
591
578
  except mlrun.errors.MLRunNotFoundError:
592
579
  model_ep = None
@@ -596,62 +583,84 @@ def _init_endpoint_record(
596
583
  )
597
584
  return
598
585
 
599
- if model.context.server.track_models and not model_ep:
600
- logger.info("Creating a new model endpoint record", endpoint_id=uid)
601
- model_endpoint = mlrun.common.schemas.ModelEndpoint(
586
+ function = mlrun.get_run_db().get_function(
587
+ name=graph_server.function_name,
588
+ project=graph_server.project,
589
+ tag=graph_server.function_tag or "latest",
590
+ )
591
+ function_uid = function.get("metadata", {}).get("uid")
592
+ if not model_ep and model.context.server.track_models:
593
+ logger.info(
594
+ "Creating a new model endpoint record",
595
+ name=model.name,
596
+ project=graph_server.project,
597
+ function_name=graph_server.function_name,
598
+ function_uid=function_uid,
599
+ model_name=model.model_spec.metadata.key,
600
+ model_uid=model.model_spec.metadata.uid,
601
+ model_class=model.__class__.__name__,
602
+ model_tag=model.model_spec.tag,
603
+ )
604
+ model_ep = mlrun.common.schemas.ModelEndpoint(
602
605
  metadata=mlrun.common.schemas.ModelEndpointMetadata(
603
- project=project, labels=model.labels, uid=uid
606
+ project=graph_server.project,
607
+ labels=model.model_spec.labels,
608
+ name=model.name,
609
+ endpoint_type=mlrun.common.schemas.model_monitoring.EndpointType.NODE_EP,
604
610
  ),
605
611
  spec=mlrun.common.schemas.ModelEndpointSpec(
606
- function_uri=graph_server.function_uri,
607
- model=model.versioned_model_name,
612
+ function_name=graph_server.function_name,
613
+ function_uid=function_uid,
614
+ function_tag=graph_server.function_tag or "latest",
615
+ model_name=model.model_spec.metadata.key,
616
+ model_uid=model.model_spec.metadata.uid,
608
617
  model_class=model.__class__.__name__,
609
- model_uri=model.model_path,
610
- stream_path=model.context.stream.stream_uri,
611
- active=True,
612
- monitoring_mode=mlrun.common.schemas.model_monitoring.ModelMonitoringMode.enabled,
613
618
  ),
614
619
  status=mlrun.common.schemas.ModelEndpointStatus(
615
- endpoint_type=mlrun.common.schemas.model_monitoring.EndpointType.NODE_EP
620
+ monitoring_mode=mlrun.common.schemas.model_monitoring.ModelMonitoringMode.enabled
621
+ if model.context.server.track_models
622
+ else mlrun.common.schemas.model_monitoring.ModelMonitoringMode.disabled,
616
623
  ),
617
624
  )
618
-
619
625
  db = mlrun.get_run_db()
620
- db.create_model_endpoint(
621
- project=project,
622
- endpoint_id=uid,
623
- model_endpoint=model_endpoint.dict(),
624
- )
626
+ db.create_model_endpoint(model_endpoint=model_ep)
625
627
 
626
628
  elif model_ep:
627
629
  attributes = {}
628
- old_model_uri = model_ep.spec.model_uri
629
- mlrun.model_monitoring.helpers.enrich_model_endpoint_with_model_uri(
630
- model_endpoint=model_ep,
631
- model_obj=model.model_spec,
632
- )
633
- if model_ep.spec.model_uri != old_model_uri:
634
- attributes["model_uri"] = model_ep.spec.model_uri
630
+ if function_uid != model_ep.spec.function_uid:
631
+ attributes[ModelEndpointSchema.FUNCTION_UID] = function_uid
632
+ if model.model_spec.metadata.key != model_ep.spec.model_name:
633
+ attributes[ModelEndpointSchema.MODEL_NAME] = model.model_spec.metadata.key
634
+ if model.model_spec.metadata.uid != model_ep.spec.model_uid:
635
+ attributes[ModelEndpointSchema.MODEL_UID] = model.model_spec.metadata.uid
636
+ if model.__class__.__name__ != model_ep.spec.model_class:
637
+ attributes[ModelEndpointSchema.MODEL_CLASS] = model.__class__.__name__
635
638
  if (
636
- model_ep.spec.monitoring_mode
639
+ model_ep.status.monitoring_mode
637
640
  == mlrun.common.schemas.model_monitoring.ModelMonitoringMode.enabled
638
641
  ) != model.context.server.track_models:
639
- attributes["monitoring_mode"] = (
642
+ attributes[ModelEndpointSchema.MONITORING_MODE] = (
640
643
  mlrun.common.schemas.model_monitoring.ModelMonitoringMode.enabled
641
644
  if model.context.server.track_models
642
645
  else mlrun.common.schemas.model_monitoring.ModelMonitoringMode.disabled
643
646
  )
644
647
  if attributes:
645
- db = mlrun.get_run_db()
646
- db.patch_model_endpoint(
647
- project=project,
648
- endpoint_id=uid,
649
- attributes=attributes,
650
- )
651
648
  logger.info(
652
649
  "Updating model endpoint attributes",
653
650
  attributes=attributes,
654
- endpoint_id=uid,
651
+ project=model_ep.metadata.project,
652
+ name=model_ep.metadata.name,
653
+ function_name=model_ep.spec.function_name,
654
+ )
655
+ db = mlrun.get_run_db()
656
+ model_ep = db.patch_model_endpoint(
657
+ project=model_ep.metadata.project,
658
+ name=model_ep.metadata.name,
659
+ function_name=model_ep.spec.function_name,
660
+ endpoint_id=model_ep.metadata.uid,
661
+ attributes=attributes,
655
662
  )
663
+ else:
664
+ return None
656
665
 
657
- return uid
666
+ return model_ep.metadata.uid
mlrun/track/__init__.py CHANGED
@@ -11,6 +11,6 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
- # flake8: noqa - this is until we take care of the F401 violations with respect to __all__ & sphinx
14
+
15
15
  from mlrun.track.tracker import Tracker
16
16
  from mlrun.track.tracker_manager import TrackerManager
mlrun/track/tracker.py CHANGED
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
 
15
15
  from abc import ABC, abstractmethod
16
- from typing import Any, Union
16
+ from typing import Any, Optional, Union
17
17
 
18
18
  from mlrun.artifacts import Artifact, ModelArtifact
19
19
  from mlrun.execution import MLClientCtx
@@ -63,7 +63,7 @@ class Tracker(ABC):
63
63
  project: MlrunProject,
64
64
  reference_id: Any,
65
65
  function_name: str,
66
- handler: str = None,
66
+ handler: Optional[str] = None,
67
67
  **kwargs,
68
68
  ) -> RunObject:
69
69
  """
@@ -15,6 +15,7 @@ import os
15
15
  import pathlib
16
16
  import tempfile
17
17
  import zipfile
18
+ from typing import Optional
18
19
 
19
20
  import mlflow
20
21
  import mlflow.entities
@@ -190,7 +191,7 @@ class MLFlowTracker(Tracker):
190
191
  project: MlrunProject,
191
192
  reference_id: str,
192
193
  function_name: str,
193
- handler: str = None,
194
+ handler: Optional[str] = None,
194
195
  **kwargs,
195
196
  ) -> RunObject:
196
197
  """
@@ -251,9 +252,9 @@ class MLFlowTracker(Tracker):
251
252
  self,
252
253
  project: MlrunProject,
253
254
  reference_id: str,
254
- key: str = None,
255
- metrics: dict = None,
256
- extra_data: dict = None,
255
+ key: Optional[str] = None,
256
+ metrics: Optional[dict] = None,
257
+ extra_data: Optional[dict] = None,
257
258
  ) -> ModelArtifact:
258
259
  """
259
260
  Import a model from MLFlow to MLRun.
@@ -290,7 +291,7 @@ class MLFlowTracker(Tracker):
290
291
  return model
291
292
 
292
293
  def import_artifact(
293
- self, project: MlrunProject, reference_id: str, key: str = None
294
+ self, project: MlrunProject, reference_id: str, key: Optional[str] = None
294
295
  ) -> Artifact:
295
296
  """
296
297
  Import an artifact from MLFlow to MLRun.
mlrun/utils/async_http.py CHANGED
@@ -42,7 +42,7 @@ class AsyncClientWithRetry(RetryClient):
42
42
  retry_on_exception: bool = True,
43
43
  raise_for_status: bool = True,
44
44
  blacklisted_methods: typing.Optional[list[str]] = None,
45
- logger: logging.Logger = None,
45
+ logger: Optional[logging.Logger] = None,
46
46
  *args,
47
47
  **kwargs,
48
48
  ):
mlrun/utils/clones.py CHANGED
@@ -122,7 +122,7 @@ def add_credentials_git_remote_url(url: str, secrets=None) -> tuple[str, bool]:
122
122
  username, password = get_git_username_password_from_token(token)
123
123
 
124
124
  if username:
125
- return f"https://{username}:{password}@{url_obj.hostname}{url_obj.path}", True
125
+ return f"https://{username}:{password}@{url_obj.netloc}{url_obj.path}", True
126
126
  return url, False
127
127
 
128
128