mlrun 1.7.2rc3__py3-none-any.whl → 1.8.0__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 (275) hide show
  1. mlrun/__init__.py +26 -22
  2. mlrun/__main__.py +15 -16
  3. mlrun/alerts/alert.py +150 -15
  4. mlrun/api/schemas/__init__.py +1 -9
  5. mlrun/artifacts/__init__.py +2 -3
  6. mlrun/artifacts/base.py +62 -19
  7. mlrun/artifacts/dataset.py +17 -17
  8. mlrun/artifacts/document.py +454 -0
  9. mlrun/artifacts/manager.py +28 -18
  10. mlrun/artifacts/model.py +91 -59
  11. mlrun/artifacts/plots.py +2 -2
  12. mlrun/common/constants.py +8 -0
  13. mlrun/common/formatters/__init__.py +1 -0
  14. mlrun/common/formatters/artifact.py +1 -1
  15. mlrun/common/formatters/feature_set.py +2 -0
  16. mlrun/common/formatters/function.py +1 -0
  17. mlrun/{model_monitoring/db/stores/v3io_kv/__init__.py → common/formatters/model_endpoint.py} +17 -0
  18. mlrun/common/formatters/pipeline.py +1 -2
  19. mlrun/common/formatters/project.py +9 -0
  20. mlrun/common/model_monitoring/__init__.py +0 -5
  21. mlrun/common/model_monitoring/helpers.py +12 -62
  22. mlrun/common/runtimes/constants.py +25 -4
  23. mlrun/common/schemas/__init__.py +9 -5
  24. mlrun/common/schemas/alert.py +114 -19
  25. mlrun/common/schemas/api_gateway.py +3 -3
  26. mlrun/common/schemas/artifact.py +22 -9
  27. mlrun/common/schemas/auth.py +8 -4
  28. mlrun/common/schemas/background_task.py +7 -7
  29. mlrun/common/schemas/client_spec.py +4 -4
  30. mlrun/common/schemas/clusterization_spec.py +2 -2
  31. mlrun/common/schemas/common.py +53 -3
  32. mlrun/common/schemas/constants.py +15 -0
  33. mlrun/common/schemas/datastore_profile.py +1 -1
  34. mlrun/common/schemas/feature_store.py +9 -9
  35. mlrun/common/schemas/frontend_spec.py +4 -4
  36. mlrun/common/schemas/function.py +10 -10
  37. mlrun/common/schemas/hub.py +1 -1
  38. mlrun/common/schemas/k8s.py +3 -3
  39. mlrun/common/schemas/memory_reports.py +3 -3
  40. mlrun/common/schemas/model_monitoring/__init__.py +4 -8
  41. mlrun/common/schemas/model_monitoring/constants.py +127 -46
  42. mlrun/common/schemas/model_monitoring/grafana.py +18 -12
  43. mlrun/common/schemas/model_monitoring/model_endpoints.py +154 -160
  44. mlrun/common/schemas/notification.py +24 -3
  45. mlrun/common/schemas/object.py +1 -1
  46. mlrun/common/schemas/pagination.py +4 -4
  47. mlrun/common/schemas/partition.py +142 -0
  48. mlrun/common/schemas/pipeline.py +3 -3
  49. mlrun/common/schemas/project.py +26 -18
  50. mlrun/common/schemas/runs.py +3 -3
  51. mlrun/common/schemas/runtime_resource.py +5 -5
  52. mlrun/common/schemas/schedule.py +1 -1
  53. mlrun/common/schemas/secret.py +1 -1
  54. mlrun/{model_monitoring/db/stores/sqldb/__init__.py → common/schemas/serving.py} +10 -1
  55. mlrun/common/schemas/tag.py +3 -3
  56. mlrun/common/schemas/workflow.py +6 -5
  57. mlrun/common/types.py +1 -0
  58. mlrun/config.py +157 -89
  59. mlrun/data_types/__init__.py +5 -3
  60. mlrun/data_types/infer.py +13 -3
  61. mlrun/data_types/spark.py +2 -1
  62. mlrun/datastore/__init__.py +59 -18
  63. mlrun/datastore/alibaba_oss.py +4 -1
  64. mlrun/datastore/azure_blob.py +4 -1
  65. mlrun/datastore/base.py +19 -24
  66. mlrun/datastore/datastore.py +10 -4
  67. mlrun/datastore/datastore_profile.py +178 -45
  68. mlrun/datastore/dbfs_store.py +4 -1
  69. mlrun/datastore/filestore.py +4 -1
  70. mlrun/datastore/google_cloud_storage.py +4 -1
  71. mlrun/datastore/hdfs.py +4 -1
  72. mlrun/datastore/inmem.py +4 -1
  73. mlrun/datastore/redis.py +4 -1
  74. mlrun/datastore/s3.py +14 -3
  75. mlrun/datastore/sources.py +89 -92
  76. mlrun/datastore/store_resources.py +7 -4
  77. mlrun/datastore/storeytargets.py +51 -16
  78. mlrun/datastore/targets.py +38 -31
  79. mlrun/datastore/utils.py +87 -4
  80. mlrun/datastore/v3io.py +4 -1
  81. mlrun/datastore/vectorstore.py +291 -0
  82. mlrun/datastore/wasbfs/fs.py +13 -12
  83. mlrun/db/base.py +286 -100
  84. mlrun/db/httpdb.py +1562 -490
  85. mlrun/db/nopdb.py +250 -83
  86. mlrun/errors.py +6 -2
  87. mlrun/execution.py +194 -50
  88. mlrun/feature_store/__init__.py +2 -10
  89. mlrun/feature_store/api.py +20 -458
  90. mlrun/feature_store/common.py +9 -9
  91. mlrun/feature_store/feature_set.py +20 -18
  92. mlrun/feature_store/feature_vector.py +105 -479
  93. mlrun/feature_store/feature_vector_utils.py +466 -0
  94. mlrun/feature_store/retrieval/base.py +15 -11
  95. mlrun/feature_store/retrieval/job.py +2 -1
  96. mlrun/feature_store/retrieval/storey_merger.py +1 -1
  97. mlrun/feature_store/steps.py +3 -3
  98. mlrun/features.py +30 -13
  99. mlrun/frameworks/__init__.py +1 -2
  100. mlrun/frameworks/_common/__init__.py +1 -2
  101. mlrun/frameworks/_common/artifacts_library.py +2 -2
  102. mlrun/frameworks/_common/mlrun_interface.py +10 -6
  103. mlrun/frameworks/_common/model_handler.py +31 -31
  104. mlrun/frameworks/_common/producer.py +3 -1
  105. mlrun/frameworks/_dl_common/__init__.py +1 -2
  106. mlrun/frameworks/_dl_common/loggers/__init__.py +1 -2
  107. mlrun/frameworks/_dl_common/loggers/mlrun_logger.py +4 -4
  108. mlrun/frameworks/_dl_common/loggers/tensorboard_logger.py +3 -3
  109. mlrun/frameworks/_ml_common/__init__.py +1 -2
  110. mlrun/frameworks/_ml_common/loggers/__init__.py +1 -2
  111. mlrun/frameworks/_ml_common/model_handler.py +21 -21
  112. mlrun/frameworks/_ml_common/plans/__init__.py +1 -2
  113. mlrun/frameworks/_ml_common/plans/confusion_matrix_plan.py +3 -1
  114. mlrun/frameworks/_ml_common/plans/dataset_plan.py +3 -3
  115. mlrun/frameworks/_ml_common/plans/roc_curve_plan.py +4 -4
  116. mlrun/frameworks/auto_mlrun/__init__.py +1 -2
  117. mlrun/frameworks/auto_mlrun/auto_mlrun.py +22 -15
  118. mlrun/frameworks/huggingface/__init__.py +1 -2
  119. mlrun/frameworks/huggingface/model_server.py +9 -9
  120. mlrun/frameworks/lgbm/__init__.py +47 -44
  121. mlrun/frameworks/lgbm/callbacks/__init__.py +1 -2
  122. mlrun/frameworks/lgbm/callbacks/logging_callback.py +4 -2
  123. mlrun/frameworks/lgbm/callbacks/mlrun_logging_callback.py +4 -2
  124. mlrun/frameworks/lgbm/mlrun_interfaces/__init__.py +1 -2
  125. mlrun/frameworks/lgbm/mlrun_interfaces/mlrun_interface.py +5 -5
  126. mlrun/frameworks/lgbm/model_handler.py +15 -11
  127. mlrun/frameworks/lgbm/model_server.py +11 -7
  128. mlrun/frameworks/lgbm/utils.py +2 -2
  129. mlrun/frameworks/onnx/__init__.py +1 -2
  130. mlrun/frameworks/onnx/dataset.py +3 -3
  131. mlrun/frameworks/onnx/mlrun_interface.py +2 -2
  132. mlrun/frameworks/onnx/model_handler.py +7 -5
  133. mlrun/frameworks/onnx/model_server.py +8 -6
  134. mlrun/frameworks/parallel_coordinates.py +11 -11
  135. mlrun/frameworks/pytorch/__init__.py +22 -23
  136. mlrun/frameworks/pytorch/callbacks/__init__.py +1 -2
  137. mlrun/frameworks/pytorch/callbacks/callback.py +2 -1
  138. mlrun/frameworks/pytorch/callbacks/logging_callback.py +15 -8
  139. mlrun/frameworks/pytorch/callbacks/mlrun_logging_callback.py +19 -12
  140. mlrun/frameworks/pytorch/callbacks/tensorboard_logging_callback.py +22 -15
  141. mlrun/frameworks/pytorch/callbacks_handler.py +36 -30
  142. mlrun/frameworks/pytorch/mlrun_interface.py +17 -17
  143. mlrun/frameworks/pytorch/model_handler.py +21 -17
  144. mlrun/frameworks/pytorch/model_server.py +13 -9
  145. mlrun/frameworks/sklearn/__init__.py +19 -18
  146. mlrun/frameworks/sklearn/estimator.py +2 -2
  147. mlrun/frameworks/sklearn/metric.py +3 -3
  148. mlrun/frameworks/sklearn/metrics_library.py +8 -6
  149. mlrun/frameworks/sklearn/mlrun_interface.py +3 -2
  150. mlrun/frameworks/sklearn/model_handler.py +4 -3
  151. mlrun/frameworks/tf_keras/__init__.py +11 -12
  152. mlrun/frameworks/tf_keras/callbacks/__init__.py +1 -2
  153. mlrun/frameworks/tf_keras/callbacks/logging_callback.py +17 -14
  154. mlrun/frameworks/tf_keras/callbacks/mlrun_logging_callback.py +15 -12
  155. mlrun/frameworks/tf_keras/callbacks/tensorboard_logging_callback.py +21 -18
  156. mlrun/frameworks/tf_keras/model_handler.py +17 -13
  157. mlrun/frameworks/tf_keras/model_server.py +12 -8
  158. mlrun/frameworks/xgboost/__init__.py +19 -18
  159. mlrun/frameworks/xgboost/model_handler.py +13 -9
  160. mlrun/k8s_utils.py +2 -5
  161. mlrun/launcher/base.py +3 -4
  162. mlrun/launcher/client.py +2 -2
  163. mlrun/launcher/local.py +6 -2
  164. mlrun/launcher/remote.py +1 -1
  165. mlrun/lists.py +8 -4
  166. mlrun/model.py +132 -46
  167. mlrun/model_monitoring/__init__.py +3 -5
  168. mlrun/model_monitoring/api.py +113 -98
  169. mlrun/model_monitoring/applications/__init__.py +0 -5
  170. mlrun/model_monitoring/applications/_application_steps.py +81 -50
  171. mlrun/model_monitoring/applications/base.py +467 -14
  172. mlrun/model_monitoring/applications/context.py +212 -134
  173. mlrun/model_monitoring/{db/stores/base → applications/evidently}/__init__.py +6 -2
  174. mlrun/model_monitoring/applications/evidently/base.py +146 -0
  175. mlrun/model_monitoring/applications/histogram_data_drift.py +89 -56
  176. mlrun/model_monitoring/applications/results.py +67 -15
  177. mlrun/model_monitoring/controller.py +701 -315
  178. mlrun/model_monitoring/db/__init__.py +0 -2
  179. mlrun/model_monitoring/db/_schedules.py +242 -0
  180. mlrun/model_monitoring/db/_stats.py +189 -0
  181. mlrun/model_monitoring/db/tsdb/__init__.py +33 -22
  182. mlrun/model_monitoring/db/tsdb/base.py +243 -49
  183. mlrun/model_monitoring/db/tsdb/tdengine/schemas.py +76 -36
  184. mlrun/model_monitoring/db/tsdb/tdengine/stream_graph_steps.py +33 -0
  185. mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connection.py +213 -0
  186. mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connector.py +534 -88
  187. mlrun/model_monitoring/db/tsdb/v3io/stream_graph_steps.py +1 -0
  188. mlrun/model_monitoring/db/tsdb/v3io/v3io_connector.py +436 -106
  189. mlrun/model_monitoring/helpers.py +356 -114
  190. mlrun/model_monitoring/stream_processing.py +190 -345
  191. mlrun/model_monitoring/tracking_policy.py +11 -4
  192. mlrun/model_monitoring/writer.py +49 -90
  193. mlrun/package/__init__.py +3 -6
  194. mlrun/package/context_handler.py +2 -2
  195. mlrun/package/packager.py +12 -9
  196. mlrun/package/packagers/__init__.py +0 -2
  197. mlrun/package/packagers/default_packager.py +14 -11
  198. mlrun/package/packagers/numpy_packagers.py +16 -7
  199. mlrun/package/packagers/pandas_packagers.py +18 -18
  200. mlrun/package/packagers/python_standard_library_packagers.py +25 -11
  201. mlrun/package/packagers_manager.py +35 -32
  202. mlrun/package/utils/__init__.py +0 -3
  203. mlrun/package/utils/_pickler.py +6 -6
  204. mlrun/platforms/__init__.py +47 -16
  205. mlrun/platforms/iguazio.py +4 -1
  206. mlrun/projects/operations.py +30 -30
  207. mlrun/projects/pipelines.py +116 -47
  208. mlrun/projects/project.py +1292 -329
  209. mlrun/render.py +5 -9
  210. mlrun/run.py +57 -14
  211. mlrun/runtimes/__init__.py +1 -3
  212. mlrun/runtimes/base.py +30 -22
  213. mlrun/runtimes/daskjob.py +9 -9
  214. mlrun/runtimes/databricks_job/databricks_runtime.py +6 -5
  215. mlrun/runtimes/function_reference.py +5 -2
  216. mlrun/runtimes/generators.py +3 -2
  217. mlrun/runtimes/kubejob.py +6 -7
  218. mlrun/runtimes/mounts.py +574 -0
  219. mlrun/runtimes/mpijob/__init__.py +0 -2
  220. mlrun/runtimes/mpijob/abstract.py +7 -6
  221. mlrun/runtimes/nuclio/api_gateway.py +7 -7
  222. mlrun/runtimes/nuclio/application/application.py +11 -13
  223. mlrun/runtimes/nuclio/application/reverse_proxy.go +66 -64
  224. mlrun/runtimes/nuclio/function.py +127 -70
  225. mlrun/runtimes/nuclio/serving.py +105 -37
  226. mlrun/runtimes/pod.py +159 -54
  227. mlrun/runtimes/remotesparkjob.py +3 -2
  228. mlrun/runtimes/sparkjob/__init__.py +0 -2
  229. mlrun/runtimes/sparkjob/spark3job.py +22 -12
  230. mlrun/runtimes/utils.py +7 -6
  231. mlrun/secrets.py +2 -2
  232. mlrun/serving/__init__.py +8 -0
  233. mlrun/serving/merger.py +7 -5
  234. mlrun/serving/remote.py +35 -22
  235. mlrun/serving/routers.py +186 -240
  236. mlrun/serving/server.py +41 -10
  237. mlrun/serving/states.py +432 -118
  238. mlrun/serving/utils.py +13 -2
  239. mlrun/serving/v1_serving.py +3 -2
  240. mlrun/serving/v2_serving.py +161 -203
  241. mlrun/track/__init__.py +1 -1
  242. mlrun/track/tracker.py +2 -2
  243. mlrun/track/trackers/mlflow_tracker.py +6 -5
  244. mlrun/utils/async_http.py +35 -22
  245. mlrun/utils/clones.py +7 -4
  246. mlrun/utils/helpers.py +511 -58
  247. mlrun/utils/logger.py +119 -13
  248. mlrun/utils/notifications/notification/__init__.py +22 -19
  249. mlrun/utils/notifications/notification/base.py +39 -15
  250. mlrun/utils/notifications/notification/console.py +6 -6
  251. mlrun/utils/notifications/notification/git.py +11 -11
  252. mlrun/utils/notifications/notification/ipython.py +10 -9
  253. mlrun/utils/notifications/notification/mail.py +176 -0
  254. mlrun/utils/notifications/notification/slack.py +16 -8
  255. mlrun/utils/notifications/notification/webhook.py +24 -8
  256. mlrun/utils/notifications/notification_pusher.py +191 -200
  257. mlrun/utils/regex.py +12 -2
  258. mlrun/utils/version/version.json +2 -2
  259. {mlrun-1.7.2rc3.dist-info → mlrun-1.8.0.dist-info}/METADATA +81 -54
  260. mlrun-1.8.0.dist-info/RECORD +351 -0
  261. {mlrun-1.7.2rc3.dist-info → mlrun-1.8.0.dist-info}/WHEEL +1 -1
  262. mlrun/model_monitoring/applications/evidently_base.py +0 -137
  263. mlrun/model_monitoring/db/stores/__init__.py +0 -136
  264. mlrun/model_monitoring/db/stores/base/store.py +0 -213
  265. mlrun/model_monitoring/db/stores/sqldb/models/__init__.py +0 -71
  266. mlrun/model_monitoring/db/stores/sqldb/models/base.py +0 -190
  267. mlrun/model_monitoring/db/stores/sqldb/models/mysql.py +0 -103
  268. mlrun/model_monitoring/db/stores/sqldb/models/sqlite.py +0 -40
  269. mlrun/model_monitoring/db/stores/sqldb/sql_store.py +0 -659
  270. mlrun/model_monitoring/db/stores/v3io_kv/kv_store.py +0 -726
  271. mlrun/model_monitoring/model_endpoint.py +0 -118
  272. mlrun-1.7.2rc3.dist-info/RECORD +0 -351
  273. {mlrun-1.7.2rc3.dist-info → mlrun-1.8.0.dist-info}/entry_points.txt +0 -0
  274. {mlrun-1.7.2rc3.dist-info → mlrun-1.8.0.dist-info/licenses}/LICENSE +0 -0
  275. {mlrun-1.7.2rc3.dist-info → mlrun-1.8.0.dist-info}/top_level.txt +0 -0
mlrun/render.py CHANGED
@@ -361,9 +361,6 @@ def get_tblframe(df, display, classes=None):
361
361
  return ipython_display(html, display)
362
362
 
363
363
 
364
- uid_template = '<div title="{}"><a href="{}/{}/{}/jobs/monitor/{}/overview" target="_blank" >...{}</a></div>'
365
-
366
-
367
364
  def runs_to_html(
368
365
  df: pd.DataFrame,
369
366
  display: bool = True,
@@ -379,15 +376,14 @@ def runs_to_html(
379
376
  df["results"] = df["results"].apply(dict_html)
380
377
  df["start"] = df["start"].apply(time_str)
381
378
  df["parameters"] = df["parameters"].apply(dict_html)
379
+ uid_template = '<div title="{}"><a href="{}" target="_blank" >...{}</a></div>'
380
+
382
381
  if config.resolve_ui_url():
383
382
  df["uid"] = df.apply(
384
383
  lambda x: uid_template.format(
385
- x.uid,
386
- config.resolve_ui_url(),
387
- config.ui.projects_prefix,
388
- x.project,
389
- x.uid,
390
- x.uid[-8:],
384
+ x["uid"],
385
+ mlrun.utils.get_run_url(x["project"], x["uid"], x["name"]),
386
+ x["uid"][-8:],
391
387
  ),
392
388
  axis=1,
393
389
  )
mlrun/run.py CHANGED
@@ -30,15 +30,15 @@ from typing import Optional, Union
30
30
 
31
31
  import nuclio
32
32
  import yaml
33
- from mlrun_pipelines.common.models import RunStatuses
34
- from mlrun_pipelines.common.ops import format_summary_from_kfp_run, show_kfp_run
35
- from mlrun_pipelines.utils import get_client
36
33
 
37
34
  import mlrun.common.constants as mlrun_constants
38
35
  import mlrun.common.formatters
39
36
  import mlrun.common.schemas
40
37
  import mlrun.errors
41
38
  import mlrun.utils.helpers
39
+ import mlrun_pipelines.utils
40
+ from mlrun_pipelines.common.models import RunStatuses
41
+ from mlrun_pipelines.common.ops import format_summary_from_kfp_run, show_kfp_run
42
42
 
43
43
  from .common.helpers import parse_versioned_object_uri
44
44
  from .config import config as mlconf
@@ -73,6 +73,9 @@ from .utils import (
73
73
  update_in,
74
74
  )
75
75
 
76
+ if typing.TYPE_CHECKING:
77
+ from mlrun.datastore import DataItem
78
+
76
79
 
77
80
  def function_to_module(code="", workdir=None, secrets=None, silent=False):
78
81
  """Load code, notebook or mlrun function as .py module
@@ -200,7 +203,7 @@ def get_or_create_ctx(
200
203
  event=None,
201
204
  spec: Optional[dict] = None,
202
205
  with_env: bool = True,
203
- rundb: str = "",
206
+ rundb: Union[str, "mlrun.db.RunDBInterface"] = "",
204
207
  project: str = "",
205
208
  upload_artifacts: bool = False,
206
209
  labels: Optional[dict] = None,
@@ -258,7 +261,7 @@ def get_or_create_ctx(
258
261
  """
259
262
  if labels:
260
263
  warnings.warn(
261
- "The `labels` argument is deprecated and will be removed in 1.9.0. "
264
+ "The `labels` argument is deprecated in 1.7.0 and will be removed in 1.10.0. "
262
265
  "Please use `spec` instead, e.g.:\n"
263
266
  "spec={'metadata': {'labels': {'key': 'value'}}}",
264
267
  FutureWarning,
@@ -306,7 +309,7 @@ def get_or_create_ctx(
306
309
  out = rundb or mlconf.dbpath or environ.get("MLRUN_DBPATH")
307
310
  if out:
308
311
  autocommit = True
309
- logger.info(f"logging run results to: {out}")
312
+ logger.info(f"Logging run results to: {out}")
310
313
 
311
314
  newspec["metadata"]["project"] = (
312
315
  newspec["metadata"].get("project") or project or mlconf.default_project
@@ -434,7 +437,7 @@ def new_function(
434
437
  mode: Optional[str] = None,
435
438
  handler: Optional[str] = None,
436
439
  source: Optional[str] = None,
437
- requirements: Union[str, list[str]] = None,
440
+ requirements: Optional[list[str]] = None,
438
441
  kfp: Optional[bool] = None,
439
442
  requirements_file: str = "",
440
443
  ):
@@ -634,7 +637,7 @@ def code_to_function(
634
637
  - databricks: run code on Databricks cluster (python scripts, Spark etc.)
635
638
  - application: run a long living application (e.g. a web server, UI, etc.)
636
639
 
637
- Learn more about [Kinds of function (runtimes)](../concepts/functions-overview.html).
640
+ Learn more about :doc:`../../concepts/functions-overview`
638
641
 
639
642
  :param name: function name, typically best to use hyphen-case
640
643
  :param project: project used to namespace the function, defaults to 'default'
@@ -906,13 +909,53 @@ def _run_pipeline(
906
909
  return pipeline_run_id
907
910
 
908
911
 
912
+ def retry_pipeline(
913
+ run_id: str,
914
+ project: str,
915
+ namespace: Optional[str] = None,
916
+ ) -> str:
917
+ """Retry a pipeline run.
918
+
919
+ This function retries a previously executed pipeline run using the specified run ID. If the run is not in a
920
+ retryable state, a new run is created as a clone of the original run.
921
+
922
+ :param run_id: ID of the pipeline run to retry.
923
+ :param project: name of the project associated with the pipeline run.
924
+ :param namespace: Optional; Kubernetes namespace to use if not the default.
925
+
926
+ :returns: ID of the retried pipeline run or the ID of a cloned run if the original run is not retryable.
927
+ :raises ValueError: If access to the remote API service is not available.
928
+ """
929
+ mldb = mlrun.db.get_run_db()
930
+ if mldb.kind != "http":
931
+ raise ValueError(
932
+ "Retrying a pipeline requires access to remote API service. "
933
+ "Please set the dbpath URL."
934
+ )
935
+
936
+ pipeline_run_id = mldb.retry_pipeline(
937
+ run_id=run_id,
938
+ project=project,
939
+ namespace=namespace,
940
+ )
941
+ if pipeline_run_id == run_id:
942
+ logger.info(
943
+ f"Retried pipeline run ID={pipeline_run_id}, check UI for progress."
944
+ )
945
+ else:
946
+ logger.info(
947
+ f"Copy of pipeline {run_id} was retried as run ID={pipeline_run_id}, check UI for progress."
948
+ )
949
+ return pipeline_run_id
950
+
951
+
909
952
  def wait_for_pipeline_completion(
910
953
  run_id,
911
954
  timeout=60 * 60,
912
- expected_statuses: list[str] = None,
955
+ expected_statuses: Optional[list[str]] = None,
913
956
  namespace=None,
914
957
  remote=True,
915
- project: str = None,
958
+ project: Optional[str] = None,
916
959
  ):
917
960
  """Wait for Pipeline status, timeout in sec
918
961
 
@@ -972,7 +1015,7 @@ def wait_for_pipeline_completion(
972
1015
  _wait_for_pipeline_completion,
973
1016
  )
974
1017
  else:
975
- client = get_client(namespace=namespace)
1018
+ client = mlrun_pipelines.utils.get_client(namespace=namespace)
976
1019
  resp = client.wait_for_run_completion(run_id, timeout)
977
1020
  if resp:
978
1021
  resp = resp.to_dict()
@@ -1004,7 +1047,7 @@ def get_pipeline(
1004
1047
  format_: Union[
1005
1048
  str, mlrun.common.formatters.PipelineFormat
1006
1049
  ] = mlrun.common.formatters.PipelineFormat.summary,
1007
- project: str = None,
1050
+ project: Optional[str] = None,
1008
1051
  remote: bool = True,
1009
1052
  ):
1010
1053
  """Get Pipeline status
@@ -1033,7 +1076,7 @@ def get_pipeline(
1033
1076
  )
1034
1077
 
1035
1078
  else:
1036
- client = get_client(namespace=namespace)
1079
+ client = mlrun_pipelines.utils.get_client(namespace=namespace)
1037
1080
  resp = client.get_run(run_id)
1038
1081
  if resp:
1039
1082
  resp = resp.to_dict()
@@ -1089,7 +1132,7 @@ def get_object(url, secrets=None, size=None, offset=0, db=None):
1089
1132
  return stores.object(url=url).get(size, offset)
1090
1133
 
1091
1134
 
1092
- def get_dataitem(url, secrets=None, db=None) -> mlrun.datastore.DataItem:
1135
+ def get_dataitem(url, secrets=None, db=None) -> "DataItem":
1093
1136
  """get mlrun dataitem object (from path/url)"""
1094
1137
  stores = store_manager.set(secrets, db=db)
1095
1138
  return stores.object(url=url)
@@ -12,8 +12,6 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # flake8: noqa - this is until we take care of the F401 violations with respect to __all__ & sphinx
16
-
17
15
  __all__ = [
18
16
  "BaseRuntime",
19
17
  "KubejobRuntime",
@@ -60,7 +58,7 @@ from ..serving import MLModelServer, new_v1_model_server # noqa isort: skip
60
58
  def new_model_server(
61
59
  name,
62
60
  model_class: str,
63
- models: dict = None,
61
+ models: typing.Optional[dict] = None,
64
62
  filename="",
65
63
  protocol="",
66
64
  image="",
mlrun/runtimes/base.py CHANGED
@@ -16,31 +16,38 @@ import http
16
16
  import re
17
17
  import typing
18
18
  import warnings
19
- from base64 import b64encode
20
19
  from os import environ
21
20
  from typing import Callable, Optional, Union
22
21
 
23
22
  import requests.exceptions
24
- from mlrun_pipelines.common.ops import mlrun_op
25
23
  from nuclio.build import mlrun_footer
26
24
 
27
25
  import mlrun.common.constants
28
26
  import mlrun.common.constants as mlrun_constants
27
+ import mlrun.common.formatters
28
+ import mlrun.common.runtimes
29
29
  import mlrun.common.schemas
30
30
  import mlrun.common.schemas.model_monitoring.constants as mm_constants
31
- import mlrun.db
32
31
  import mlrun.errors
33
32
  import mlrun.launcher.factory
34
33
  import mlrun.utils.helpers
35
34
  import mlrun.utils.notifications
36
35
  import mlrun.utils.regex
36
+ from mlrun.model import (
37
+ BaseMetadata,
38
+ HyperParamOptions,
39
+ ImageBuilder,
40
+ ModelObj,
41
+ RunObject,
42
+ RunTemplate,
43
+ )
37
44
  from mlrun.utils.helpers import generate_object_uri, verify_field_regex
45
+ from mlrun_pipelines.common.ops import mlrun_op
38
46
 
39
47
  from ..config import config
40
48
  from ..datastore import store_manager
41
49
  from ..errors import err_to_str
42
50
  from ..lists import RunList
43
- from ..model import BaseMetadata, HyperParamOptions, ImageBuilder, ModelObj, RunObject
44
51
  from ..utils import (
45
52
  dict_to_json,
46
53
  dict_to_yaml,
@@ -141,10 +148,10 @@ class FunctionSpec(ModelObj):
141
148
 
142
149
  @property
143
150
  def clone_target_dir(self):
144
- # TODO: remove this property in 1.9.0
151
+ # TODO: remove this property in 1.10.0
145
152
  if self.build.source_code_target_dir:
146
153
  warnings.warn(
147
- "The clone_target_dir attribute is deprecated in 1.6.2 and will be removed in 1.9.0. "
154
+ "The clone_target_dir attribute is deprecated in 1.6.2 and will be removed in 1.10.0. "
148
155
  "Use spec.build.source_code_target_dir instead.",
149
156
  FutureWarning,
150
157
  )
@@ -152,10 +159,10 @@ class FunctionSpec(ModelObj):
152
159
 
153
160
  @clone_target_dir.setter
154
161
  def clone_target_dir(self, clone_target_dir):
155
- # TODO: remove this property in 1.9.0
162
+ # TODO: remove this property in 1.10.0
156
163
  if clone_target_dir:
157
164
  warnings.warn(
158
- "The clone_target_dir attribute is deprecated in 1.6.2 and will be removed in 1.9.0. "
165
+ "The clone_target_dir attribute is deprecated in 1.6.2 and will be removed in 1.10.0. "
159
166
  "Use spec.build.source_code_target_dir instead.",
160
167
  FutureWarning,
161
168
  )
@@ -517,7 +524,7 @@ class BaseRuntime(ModelObj):
517
524
  run_results = resp["status"].get("results", {})
518
525
  if generator.eval_stop_condition(run_results):
519
526
  logger.info(
520
- f"reached early stop condition ({generator.options.stop_condition}), stopping iterations!"
527
+ f"Reached early stop condition ({generator.options.stop_condition}), stopping iterations!"
521
528
  )
522
529
  results.append(resp)
523
530
  break
@@ -529,7 +536,7 @@ class BaseRuntime(ModelObj):
529
536
  resp = self._update_run_state(task=task, err=error_string)
530
537
  num_errors += 1
531
538
  if num_errors > generator.max_errors:
532
- logger.error("too many errors, stopping iterations!")
539
+ logger.error("Too many errors, stopping iterations!")
533
540
  results.append(resp)
534
541
  break
535
542
 
@@ -553,9 +560,9 @@ class BaseRuntime(ModelObj):
553
560
 
554
561
  def _update_run_state(
555
562
  self,
556
- resp: dict = None,
563
+ resp: Optional[dict] = None,
557
564
  task: RunObject = None,
558
- err: Union[Exception, str] = None,
565
+ err: Optional[Union[Exception, str]] = None,
559
566
  run_format: mlrun.common.formatters.RunFormat = mlrun.common.formatters.RunFormat.full,
560
567
  ) -> typing.Optional[dict]:
561
568
  """update the task state in the DB"""
@@ -644,7 +651,10 @@ class BaseRuntime(ModelObj):
644
651
  return updates
645
652
 
646
653
  def full_image_path(
647
- self, image=None, client_version: str = None, client_python_version: str = None
654
+ self,
655
+ image=None,
656
+ client_version: Optional[str] = None,
657
+ client_python_version: Optional[str] = None,
648
658
  ):
649
659
  image = image or self.spec.image or ""
650
660
 
@@ -665,20 +675,20 @@ class BaseRuntime(ModelObj):
665
675
 
666
676
  def as_step(
667
677
  self,
668
- runspec: RunObject = None,
678
+ runspec: Union[RunObject, RunTemplate] = None,
669
679
  handler=None,
670
680
  name: str = "",
671
681
  project: str = "",
672
- params: dict = None,
682
+ params: Optional[dict] = None,
673
683
  hyperparams=None,
674
684
  selector="",
675
685
  hyper_param_options: HyperParamOptions = None,
676
- inputs: dict = None,
677
- outputs: list = None,
686
+ inputs: Optional[dict] = None,
687
+ outputs: Optional[list] = None,
678
688
  workdir: str = "",
679
689
  artifact_path: str = "",
680
690
  image: str = "",
681
- labels: dict = None,
691
+ labels: Optional[dict] = None,
682
692
  use_db=True,
683
693
  verbose=None,
684
694
  scrape_metrics=False,
@@ -791,9 +801,7 @@ class BaseRuntime(ModelObj):
791
801
  mlrun.runtimes.nuclio.serving.serving_subkind
792
802
  )
793
803
 
794
- self.spec.build.functionSourceCode = b64encode(body.encode("utf-8")).decode(
795
- "utf-8"
796
- )
804
+ self.spec.build.functionSourceCode = mlrun.utils.helpers.encode_user_code(body)
797
805
  if with_doc:
798
806
  update_function_entry_points(self, body)
799
807
  return self
@@ -851,7 +859,7 @@ class BaseRuntime(ModelObj):
851
859
 
852
860
  def requires_build(self) -> bool:
853
861
  build = self.spec.build
854
- return (
862
+ return bool(
855
863
  build.commands
856
864
  or build.requirements
857
865
  or (build.source and not build.load_source_on_run)
mlrun/runtimes/daskjob.py CHANGED
@@ -363,7 +363,7 @@ class DaskCluster(KubejobRuntime):
363
363
  skip_deployed=False,
364
364
  is_kfp=False,
365
365
  mlrun_version_specifier=None,
366
- builder_env: dict = None,
366
+ builder_env: Optional[dict] = None,
367
367
  show_on_failure: bool = False,
368
368
  force_build: bool = False,
369
369
  ):
@@ -406,9 +406,9 @@ class DaskCluster(KubejobRuntime):
406
406
 
407
407
  def with_scheduler_limits(
408
408
  self,
409
- mem: str = None,
410
- cpu: str = None,
411
- gpus: int = None,
409
+ mem: Optional[str] = None,
410
+ cpu: Optional[str] = None,
411
+ gpus: Optional[int] = None,
412
412
  gpu_type: str = "nvidia.com/gpu",
413
413
  patch: bool = False,
414
414
  ):
@@ -422,9 +422,9 @@ class DaskCluster(KubejobRuntime):
422
422
 
423
423
  def with_worker_limits(
424
424
  self,
425
- mem: str = None,
426
- cpu: str = None,
427
- gpus: int = None,
425
+ mem: Optional[str] = None,
426
+ cpu: Optional[str] = None,
427
+ gpus: Optional[int] = None,
428
428
  gpu_type: str = "nvidia.com/gpu",
429
429
  patch: bool = False,
430
430
  ):
@@ -442,7 +442,7 @@ class DaskCluster(KubejobRuntime):
442
442
  )
443
443
 
444
444
  def with_scheduler_requests(
445
- self, mem: str = None, cpu: str = None, patch: bool = False
445
+ self, mem: Optional[str] = None, cpu: Optional[str] = None, patch: bool = False
446
446
  ):
447
447
  """
448
448
  set scheduler pod resources requests
@@ -451,7 +451,7 @@ class DaskCluster(KubejobRuntime):
451
451
  self.spec._verify_and_set_requests("scheduler_resources", mem, cpu, patch=patch)
452
452
 
453
453
  def with_worker_requests(
454
- self, mem: str = None, cpu: str = None, patch: bool = False
454
+ self, mem: Optional[str] = None, cpu: Optional[str] = None, patch: bool = False
455
455
  ):
456
456
  """
457
457
  set worker pod resources requests
@@ -11,14 +11,15 @@
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
-
14
+ import typing
15
15
  from ast import FunctionDef, parse, unparse
16
- from base64 import b64decode, b64encode
16
+ from base64 import b64decode
17
17
  from typing import Callable, Optional, Union
18
18
 
19
19
  import mlrun
20
20
  import mlrun.runtimes.kubejob as kubejob
21
21
  import mlrun.runtimes.pod as pod
22
+ import mlrun.utils.helpers
22
23
  from mlrun.errors import MLRunInvalidArgumentError
23
24
  from mlrun.model import HyperParamOptions, RunObject
24
25
 
@@ -138,7 +139,7 @@ class DatabricksRuntime(kubejob.KubejobRuntime):
138
139
  )
139
140
 
140
141
  def _get_modified_user_code(self, original_handler: str, log_artifacts_code: str):
141
- encoded_code = (
142
+ encoded_code: typing.Optional[str] = (
142
143
  self.spec.build.functionSourceCode if hasattr(self.spec, "build") else None
143
144
  )
144
145
  if not encoded_code:
@@ -162,7 +163,7 @@ class DatabricksRuntime(kubejob.KubejobRuntime):
162
163
  if original_handler:
163
164
  decoded_code += f"\nresult = {original_handler}(**handler_arguments)\n"
164
165
  decoded_code += _return_artifacts_code
165
- return b64encode(decoded_code.encode("utf-8")).decode("utf-8")
166
+ return mlrun.utils.helpers.encode_user_code(decoded_code)
166
167
 
167
168
  def get_internal_parameters(self, runobj: RunObject):
168
169
  """
@@ -202,7 +203,7 @@ from mlrun.runtimes.databricks_job import databricks_wrapper
202
203
  def run_mlrun_databricks_job(context,task_parameters: dict, **kwargs):
203
204
  databricks_wrapper.run_mlrun_databricks_job(context, task_parameters, **kwargs)
204
205
  """
205
- wrap_code = b64encode(wrap_code).decode("utf-8")
206
+ wrap_code = mlrun.utils.helpers.encode_user_code(wrap_code)
206
207
  self.spec.build.functionSourceCode = wrap_code
207
208
  runspec.spec.handler = "run_mlrun_databricks_job"
208
209
 
@@ -13,11 +13,11 @@
13
13
  # limitations under the License.
14
14
 
15
15
  import os
16
- from base64 import b64encode
17
16
 
18
17
  from nuclio.build import mlrun_footer
19
18
 
20
19
  import mlrun
20
+ import mlrun.utils.helpers
21
21
 
22
22
  from ..model import ModelObj
23
23
  from ..utils import generate_object_uri
@@ -36,6 +36,7 @@ class FunctionReference(ModelObj):
36
36
  spec=None,
37
37
  kind=None,
38
38
  name=None,
39
+ track_models=None,
39
40
  ):
40
41
  self.url = url
41
42
  self.kind = kind
@@ -46,6 +47,7 @@ class FunctionReference(ModelObj):
46
47
  spec = spec.to_dict()
47
48
  self.spec = spec
48
49
  self.code = code
50
+ self.track_models = track_models
49
51
 
50
52
  self._function = None
51
53
  self._address = None
@@ -116,7 +118,7 @@ class FunctionReference(ModelObj):
116
118
  func = mlrun.new_function(
117
119
  self.name, kind=kind, image=self.image or default_image
118
120
  )
119
- data = b64encode(code.encode("utf-8")).decode("utf-8")
121
+ data = mlrun.utils.helpers.encode_user_code(code)
120
122
  func.spec.build.functionSourceCode = data
121
123
  if kind not in mlrun.runtimes.RuntimeKinds.nuclio_runtimes():
122
124
  func.spec.default_handler = "handler"
@@ -130,6 +132,7 @@ class FunctionReference(ModelObj):
130
132
  if self.requirements:
131
133
  func.with_requirements(self.requirements)
132
134
  self._function = func
135
+ func.spec.track_models = self.track_models
133
136
  return func
134
137
 
135
138
  @property
@@ -15,6 +15,7 @@ import json
15
15
  import random
16
16
  import sys
17
17
  from copy import deepcopy
18
+ from typing import Optional
18
19
 
19
20
  import pandas as pd
20
21
 
@@ -26,7 +27,7 @@ default_max_iterations = 10
26
27
  default_max_errors = 3
27
28
 
28
29
 
29
- def get_generator(spec: RunSpec, execution, param_file_secrets: dict = None):
30
+ def get_generator(spec: RunSpec, execution, param_file_secrets: Optional[dict] = None):
30
31
  options = spec.hyper_param_options
31
32
  strategy = spec.strategy or options.strategy
32
33
  if not spec.is_hyper_job() or strategy == "custom":
@@ -181,7 +182,7 @@ class ListGenerator(TaskGenerator):
181
182
  yield newrun
182
183
 
183
184
 
184
- def get_run_copy(run):
185
+ def get_run_copy(run: RunObject):
185
186
  newrun = deepcopy(run)
186
187
  newrun.spec.hyperparams = None
187
188
  newrun.spec.param_file = None
mlrun/runtimes/kubejob.py CHANGED
@@ -14,11 +14,10 @@
14
14
  import typing
15
15
  import warnings
16
16
 
17
- from mlrun_pipelines.common.ops import build_op
18
-
19
17
  import mlrun.common.schemas
20
18
  import mlrun.db
21
19
  import mlrun.errors
20
+ from mlrun_pipelines.common.ops import build_op
22
21
 
23
22
  from ..model import RunObject
24
23
  from .pod import KubeResource
@@ -76,7 +75,7 @@ class KubejobRuntime(KubeResource):
76
75
  self,
77
76
  image="",
78
77
  base_image=None,
79
- commands: list = None,
78
+ commands: typing.Optional[list] = None,
80
79
  secret=None,
81
80
  source=None,
82
81
  extra=None,
@@ -115,9 +114,9 @@ class KubejobRuntime(KubeResource):
115
114
  e.g. builder_env={"GIT_TOKEN": token}
116
115
  """
117
116
  if not overwrite:
118
- # TODO: change overwrite default to True in 1.8.0
117
+ # TODO: change overwrite default to True in 1.10.0
119
118
  warnings.warn(
120
- "The `overwrite` parameter default will change from 'False' to 'True' in 1.8.0.",
119
+ "The `overwrite` parameter default will change from 'False' to 'True' in 1.10.0.",
121
120
  mlrun.utils.OverwriteBuildParamsWarning,
122
121
  )
123
122
  image = mlrun.utils.helpers.remove_image_protocol_prefix(image)
@@ -148,7 +147,7 @@ class KubejobRuntime(KubeResource):
148
147
  skip_deployed: bool = False,
149
148
  is_kfp: bool = False,
150
149
  mlrun_version_specifier: typing.Optional[bool] = None,
151
- builder_env: dict = None,
150
+ builder_env: typing.Optional[dict] = None,
152
151
  show_on_failure: bool = False,
153
152
  force_build: bool = False,
154
153
  ) -> bool:
@@ -190,7 +189,7 @@ class KubejobRuntime(KubeResource):
190
189
  self,
191
190
  image=None,
192
191
  base_image=None,
193
- commands: list = None,
192
+ commands: typing.Optional[list] = None,
194
193
  secret_name="",
195
194
  with_mlrun=True,
196
195
  skip_deployed=False,