mlrun 1.7.0rc6__py3-none-any.whl → 1.7.0rc7__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 (59) hide show
  1. mlrun/common/constants.py +6 -0
  2. mlrun/common/schemas/__init__.py +2 -0
  3. mlrun/common/schemas/model_monitoring/__init__.py +4 -0
  4. mlrun/common/schemas/model_monitoring/constants.py +35 -18
  5. mlrun/common/schemas/project.py +1 -0
  6. mlrun/common/types.py +7 -1
  7. mlrun/config.py +11 -4
  8. mlrun/data_types/data_types.py +4 -0
  9. mlrun/datastore/alibaba_oss.py +130 -0
  10. mlrun/datastore/azure_blob.py +4 -5
  11. mlrun/datastore/base.py +22 -16
  12. mlrun/datastore/datastore.py +4 -0
  13. mlrun/datastore/google_cloud_storage.py +1 -1
  14. mlrun/datastore/sources.py +2 -3
  15. mlrun/db/base.py +14 -6
  16. mlrun/db/httpdb.py +61 -56
  17. mlrun/db/nopdb.py +3 -0
  18. mlrun/model.py +1 -0
  19. mlrun/model_monitoring/__init__.py +1 -1
  20. mlrun/model_monitoring/api.py +104 -295
  21. mlrun/model_monitoring/controller.py +25 -25
  22. mlrun/model_monitoring/db/__init__.py +16 -0
  23. mlrun/model_monitoring/{stores → db/stores}/__init__.py +43 -34
  24. mlrun/model_monitoring/db/stores/base/__init__.py +15 -0
  25. mlrun/model_monitoring/{stores/model_endpoint_store.py → db/stores/base/store.py} +47 -6
  26. mlrun/model_monitoring/db/stores/sqldb/__init__.py +13 -0
  27. mlrun/model_monitoring/db/stores/sqldb/models/__init__.py +49 -0
  28. mlrun/model_monitoring/{stores → db/stores/sqldb}/models/base.py +76 -3
  29. mlrun/model_monitoring/db/stores/sqldb/models/mysql.py +68 -0
  30. mlrun/model_monitoring/{stores → db/stores/sqldb}/models/sqlite.py +13 -1
  31. mlrun/model_monitoring/db/stores/sqldb/sql_store.py +662 -0
  32. mlrun/model_monitoring/db/stores/v3io_kv/__init__.py +13 -0
  33. mlrun/model_monitoring/{stores/kv_model_endpoint_store.py → db/stores/v3io_kv/kv_store.py} +134 -3
  34. mlrun/model_monitoring/helpers.py +0 -2
  35. mlrun/model_monitoring/stream_processing.py +41 -9
  36. mlrun/model_monitoring/tracking_policy.py +7 -1
  37. mlrun/model_monitoring/writer.py +4 -36
  38. mlrun/projects/pipelines.py +13 -1
  39. mlrun/projects/project.py +109 -101
  40. mlrun/run.py +3 -1
  41. mlrun/runtimes/base.py +6 -0
  42. mlrun/runtimes/nuclio/api_gateway.py +188 -61
  43. mlrun/runtimes/nuclio/function.py +3 -0
  44. mlrun/runtimes/nuclio/serving.py +28 -32
  45. mlrun/runtimes/pod.py +26 -0
  46. mlrun/serving/server.py +4 -6
  47. mlrun/serving/states.py +34 -14
  48. mlrun/utils/helpers.py +34 -0
  49. mlrun/utils/version/version.json +2 -2
  50. {mlrun-1.7.0rc6.dist-info → mlrun-1.7.0rc7.dist-info}/METADATA +14 -5
  51. {mlrun-1.7.0rc6.dist-info → mlrun-1.7.0rc7.dist-info}/RECORD +55 -51
  52. mlrun/model_monitoring/batch.py +0 -933
  53. mlrun/model_monitoring/stores/models/__init__.py +0 -27
  54. mlrun/model_monitoring/stores/models/mysql.py +0 -34
  55. mlrun/model_monitoring/stores/sql_model_endpoint_store.py +0 -382
  56. {mlrun-1.7.0rc6.dist-info → mlrun-1.7.0rc7.dist-info}/LICENSE +0 -0
  57. {mlrun-1.7.0rc6.dist-info → mlrun-1.7.0rc7.dist-info}/WHEEL +0 -0
  58. {mlrun-1.7.0rc6.dist-info → mlrun-1.7.0rc7.dist-info}/entry_points.txt +0 -0
  59. {mlrun-1.7.0rc6.dist-info → mlrun-1.7.0rc7.dist-info}/top_level.txt +0 -0
mlrun/projects/project.py CHANGED
@@ -11,6 +11,7 @@
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
15
  import datetime
15
16
  import getpass
16
17
  import glob
@@ -44,6 +45,7 @@ import mlrun.runtimes
44
45
  import mlrun.runtimes.nuclio.api_gateway
45
46
  import mlrun.runtimes.pod
46
47
  import mlrun.runtimes.utils
48
+ import mlrun.serving
47
49
  import mlrun.utils.regex
48
50
  from mlrun.datastore.datastore_profile import DatastoreProfile, DatastoreProfile2Json
49
51
  from mlrun.runtimes.nuclio.function import RemoteRuntime
@@ -55,7 +57,6 @@ from ..features import Feature
55
57
  from ..model import EntrypointParam, ImageBuilder, ModelObj
56
58
  from ..model_monitoring.application import (
57
59
  ModelMonitoringApplicationBase,
58
- PushToMonitoringWriter,
59
60
  )
60
61
  from ..run import code_to_function, get_object, import_function, new_function
61
62
  from ..secrets import SecretsStore
@@ -760,6 +761,7 @@ class ProjectSpec(ModelObj):
760
761
  default_image=None,
761
762
  build=None,
762
763
  custom_packagers: list[tuple[str, bool]] = None,
764
+ default_function_node_selector=None,
763
765
  ):
764
766
  self.repo = None
765
767
 
@@ -799,6 +801,7 @@ class ProjectSpec(ModelObj):
799
801
  # in a tuple where the first index is the packager module's path (str) and the second is a flag (bool) for
800
802
  # whether it is mandatory for a run (raise exception on collection error) or not.
801
803
  self.custom_packagers = custom_packagers or []
804
+ self.default_function_node_selector = default_function_node_selector or {}
802
805
 
803
806
  @property
804
807
  def source(self) -> str:
@@ -1844,10 +1847,10 @@ class MlrunProject(ModelObj):
1844
1847
  monitoring application's constructor.
1845
1848
  """
1846
1849
 
1847
- if name in mm_constants.MonitoringFunctionNames.all():
1850
+ if name in mm_constants.MonitoringFunctionNames.list():
1848
1851
  raise mlrun.errors.MLRunInvalidArgumentError(
1849
- f"Application name can not be on of the following name : "
1850
- f"{mm_constants.MonitoringFunctionNames.all()}"
1852
+ f"An application cannot have the following names: "
1853
+ f"{mm_constants.MonitoringFunctionNames.list()}"
1851
1854
  )
1852
1855
  function_object: RemoteRuntime = None
1853
1856
  (
@@ -1866,16 +1869,6 @@ class MlrunProject(ModelObj):
1866
1869
  requirements_file,
1867
1870
  **application_kwargs,
1868
1871
  )
1869
- models_names = "all"
1870
- function_object.set_label(
1871
- mm_constants.ModelMonitoringAppLabel.KEY,
1872
- mm_constants.ModelMonitoringAppLabel.VAL,
1873
- )
1874
- function_object.set_label("models", models_names)
1875
-
1876
- if not mlrun.mlconf.is_ce_mode():
1877
- function_object.apply(mlrun.mount_v3io())
1878
-
1879
1872
  # save to project spec
1880
1873
  self.spec.set_function(resolved_function_name, function_object, func)
1881
1874
 
@@ -1934,49 +1927,38 @@ class MlrunProject(ModelObj):
1934
1927
 
1935
1928
  def _instantiate_model_monitoring_function(
1936
1929
  self,
1937
- func: typing.Union[str, mlrun.runtimes.BaseRuntime] = None,
1938
- application_class: typing.Union[str, ModelMonitoringApplicationBase] = None,
1939
- name: str = None,
1940
- image: str = None,
1941
- handler: str = None,
1942
- with_repo: bool = None,
1943
- tag: str = None,
1944
- requirements: typing.Union[str, list[str]] = None,
1930
+ func: typing.Union[str, mlrun.runtimes.BaseRuntime, None] = None,
1931
+ application_class: typing.Union[
1932
+ str, ModelMonitoringApplicationBase, None
1933
+ ] = None,
1934
+ name: typing.Optional[str] = None,
1935
+ image: typing.Optional[str] = None,
1936
+ handler: typing.Optional[str] = None,
1937
+ with_repo: typing.Optional[bool] = None,
1938
+ tag: typing.Optional[str] = None,
1939
+ requirements: typing.Union[str, list[str], None] = None,
1945
1940
  requirements_file: str = "",
1946
1941
  **application_kwargs,
1947
1942
  ) -> tuple[str, mlrun.runtimes.BaseRuntime, dict]:
1943
+ import mlrun.model_monitoring.api
1944
+
1948
1945
  function_object: RemoteRuntime = None
1949
1946
  kind = None
1950
1947
  if (isinstance(func, str) or func is None) and application_class is not None:
1951
- kind = "serving"
1952
- if func is None:
1953
- func = ""
1954
- func = mlrun.code_to_function(
1955
- filename=func,
1948
+ kind = mlrun.run.RuntimeKinds.serving
1949
+ func = mlrun.model_monitoring.api._create_model_monitoring_function_base(
1950
+ project=self.name,
1951
+ func=func,
1952
+ application_class=application_class,
1956
1953
  name=name,
1957
- project=self.metadata.name,
1958
- tag=tag,
1959
- kind=kind,
1960
1954
  image=image,
1955
+ tag=tag,
1961
1956
  requirements=requirements,
1962
1957
  requirements_file=requirements_file,
1958
+ **application_kwargs,
1963
1959
  )
1964
- graph = func.set_topology("flow")
1965
- if isinstance(application_class, str):
1966
- first_step = graph.to(
1967
- class_name=application_class, **application_kwargs
1968
- )
1969
- else:
1970
- first_step = graph.to(class_name=application_class)
1971
- first_step.to(
1972
- class_name=PushToMonitoringWriter(
1973
- project=self.metadata.name,
1974
- writer_application_name=mm_constants.MonitoringFunctionNames.WRITER,
1975
- stream_uri=None,
1976
- ),
1977
- ).respond()
1978
1960
  elif isinstance(func, str) and isinstance(handler, str):
1979
- kind = "nuclio"
1961
+ kind = mlrun.run.RuntimeKinds.nuclio
1980
1962
 
1981
1963
  (
1982
1964
  resolved_function_name,
@@ -1994,12 +1976,10 @@ class MlrunProject(ModelObj):
1994
1976
  requirements,
1995
1977
  requirements_file,
1996
1978
  )
1997
- models_names = "all"
1998
1979
  function_object.set_label(
1999
1980
  mm_constants.ModelMonitoringAppLabel.KEY,
2000
1981
  mm_constants.ModelMonitoringAppLabel.VAL,
2001
1982
  )
2002
- function_object.set_label("models", models_names)
2003
1983
 
2004
1984
  if not mlrun.mlconf.is_ce_mode():
2005
1985
  function_object.apply(mlrun.mount_v3io())
@@ -2029,8 +2009,6 @@ class MlrunProject(ModelObj):
2029
2009
  stream & histogram data drift functions, which are real time nuclio
2030
2010
  functions. By default, the image is mlrun/mlrun.
2031
2011
  :param deploy_histogram_data_drift_app: If true, deploy the default histogram-based data drift application.
2032
-
2033
- :returns: model monitoring controller job as a dictionary.
2034
2012
  """
2035
2013
  if default_controller_image != "mlrun/mlrun":
2036
2014
  # TODO: Remove this in 1.9.0
@@ -2045,18 +2023,24 @@ class MlrunProject(ModelObj):
2045
2023
  project=self.name,
2046
2024
  image=image,
2047
2025
  base_period=base_period,
2026
+ deploy_histogram_data_drift_app=deploy_histogram_data_drift_app,
2048
2027
  )
2049
- if deploy_histogram_data_drift_app:
2050
- fn = self.set_model_monitoring_function(
2051
- func=str(
2052
- pathlib.Path(__file__).parent.parent
2053
- / "model_monitoring/applications/histogram_data_drift.py"
2054
- ),
2055
- name=mm_constants.MLRUN_HISTOGRAM_DATA_DRIFT_APP_NAME,
2056
- application_class="HistogramDataDriftApplication",
2057
- image=image,
2058
- )
2059
- fn.deploy()
2028
+
2029
+ def deploy_histogram_data_drift_app(
2030
+ self,
2031
+ *,
2032
+ image: str = "mlrun/mlrun",
2033
+ db: Optional[mlrun.db.RunDBInterface] = None,
2034
+ ) -> None:
2035
+ """
2036
+ Deploy the histogram data drift application.
2037
+
2038
+ :param image: The image on which the application will run.
2039
+ :param db: An optional DB object.
2040
+ """
2041
+ if db is None:
2042
+ db = mlrun.db.get_run_db(secrets=self._secrets)
2043
+ db.deploy_histogram_data_drift_app(project=self.name, image=image)
2060
2044
 
2061
2045
  def update_model_monitoring_controller(
2062
2046
  self,
@@ -2081,20 +2065,22 @@ class MlrunProject(ModelObj):
2081
2065
  image=image,
2082
2066
  )
2083
2067
 
2084
- def disable_model_monitoring(self):
2068
+ def disable_model_monitoring(
2069
+ self, *, delete_histogram_data_drift_app: bool = True
2070
+ ) -> None:
2071
+ """
2072
+ Note: This method is currently not advised for use. See ML-3432.
2073
+ Disable model monitoring by deleting the underlying functions infrastructure from MLRun database.
2074
+
2075
+ :param delete_histogram_data_drift_app: Whether to delete the histogram data drift app.
2076
+ """
2085
2077
  db = mlrun.db.get_run_db(secrets=self._secrets)
2086
- db.delete_function(
2087
- project=self.name,
2088
- name=mm_constants.MonitoringFunctionNames.APPLICATION_CONTROLLER,
2089
- )
2090
- db.delete_function(
2091
- project=self.name,
2092
- name=mm_constants.MonitoringFunctionNames.WRITER,
2093
- )
2094
- db.delete_function(
2095
- project=self.name,
2096
- name=mm_constants.MonitoringFunctionNames.STREAM,
2097
- )
2078
+ for fn_name in mm_constants.MonitoringFunctionNames.list():
2079
+ db.delete_function(project=self.name, name=fn_name)
2080
+ if delete_histogram_data_drift_app:
2081
+ db.delete_function(
2082
+ project=self.name, name=mm_constants.MLRUN_HISTOGRAM_DATA_DRIFT_APP_NAME
2083
+ )
2098
2084
 
2099
2085
  def set_function(
2100
2086
  self,
@@ -2747,40 +2733,41 @@ class MlrunProject(ModelObj):
2747
2733
  cleanup_ttl: int = None,
2748
2734
  notifications: list[mlrun.model.Notification] = None,
2749
2735
  ) -> _PipelineRunStatus:
2750
- """run a workflow using kubeflow pipelines
2751
-
2752
- :param name: name of the workflow
2753
- :param workflow_path:
2754
- url to a workflow file, if not a project workflow
2755
- :param arguments:
2756
- kubeflow pipelines arguments (parameters)
2757
- :param artifact_path:
2758
- target path/url for workflow artifacts, the string
2759
- '{{workflow.uid}}' will be replaced by workflow id
2760
- :param workflow_handler:
2761
- workflow function handler (for running workflow function directly)
2762
- :param namespace: kubernetes namespace if other than default
2763
- :param sync: force functions sync before run
2764
- :param watch: wait for pipeline completion
2765
- :param dirty: allow running the workflow when the git repo is dirty
2766
- :param engine: workflow engine running the workflow.
2767
- supported values are 'kfp' (default), 'local' or 'remote'.
2768
- for setting engine for remote running use 'remote:local' or 'remote:kfp'.
2769
- :param local: run local pipeline with local functions (set local=True in function.run())
2736
+ """Run a workflow using kubeflow pipelines
2737
+
2738
+ :param name: Name of the workflow
2739
+ :param workflow_path: URL to a workflow file, if not a project workflow
2740
+ :param arguments: Kubeflow pipelines arguments (parameters)
2741
+ :param artifact_path: Target path/URL for workflow artifacts, the string '{{workflow.uid}}' will be
2742
+ replaced by workflow id.
2743
+ :param workflow_handler: Workflow function handler (for running workflow function directly)
2744
+ :param namespace: Kubernetes namespace if other than default
2745
+ :param sync: Force functions sync before run
2746
+ :param watch: Wait for pipeline completion
2747
+ :param dirty: Allow running the workflow when the git repo is dirty
2748
+ :param engine: Workflow engine running the workflow.
2749
+ Supported values are 'kfp' (default), 'local' or 'remote'.
2750
+ For setting engine for remote running use 'remote:local' or 'remote:kfp'.
2751
+ :param local: Run local pipeline with local functions (set local=True in function.run())
2770
2752
  :param schedule: ScheduleCronTrigger class instance or a standard crontab expression string
2771
2753
  (which will be converted to the class using its `from_crontab` constructor),
2772
2754
  see this link for help:
2773
2755
  https://apscheduler.readthedocs.io/en/3.x/modules/triggers/cron.html#module-apscheduler.triggers.cron
2774
2756
  for using the pre-defined workflow's schedule, set `schedule=True`
2775
- :param timeout: timeout in seconds to wait for pipeline completion (watch will be activated)
2776
- :param source: remote source to use instead of the actual `project.spec.source` (used when engine is remote).
2777
- for other engines the source is to validate that the code is up-to-date
2757
+ :param timeout: Timeout in seconds to wait for pipeline completion (watch will be activated)
2758
+ :param source: Source to use instead of the actual `project.spec.source` (used when engine is remote).
2759
+ Can be a one of:
2760
+ 1. Remote URL which is loaded dynamically to the workflow runner.
2761
+ 2. A path to the project's context on the workflow runner's image.
2762
+ Path can be absolute or relative to `project.spec.build.source_code_target_dir` if defined
2763
+ (enriched when building a project image with source, see `MlrunProject.build_image`).
2764
+ For other engines the source is used to validate that the code is up-to-date.
2778
2765
  :param cleanup_ttl:
2779
- pipeline cleanup ttl in secs (time to wait after workflow completion, at which point the
2780
- workflow and all its resources are deleted)
2766
+ Pipeline cleanup ttl in secs (time to wait after workflow completion, at which point the
2767
+ Workflow and all its resources are deleted)
2781
2768
  :param notifications:
2782
- list of notifications to send for workflow completion
2783
- :returns: run id
2769
+ List of notifications to send for workflow completion
2770
+ :returns: Run id
2784
2771
  """
2785
2772
 
2786
2773
  arguments = arguments or {}
@@ -3179,6 +3166,7 @@ class MlrunProject(ModelObj):
3179
3166
  requirements_file: str = None,
3180
3167
  builder_env: dict = None,
3181
3168
  extra_args: str = None,
3169
+ source_code_target_dir: str = None,
3182
3170
  ):
3183
3171
  """specify builder configuration for the project
3184
3172
 
@@ -3199,6 +3187,8 @@ class MlrunProject(ModelObj):
3199
3187
  e.g. builder_env={"GIT_TOKEN": token}, does not work yet in KFP
3200
3188
  :param extra_args: A string containing additional builder arguments in the format of command-line options,
3201
3189
  e.g. extra_args="--skip-tls-verify --build-arg A=val"
3190
+ :param source_code_target_dir: Path on the image where source code would be extracted
3191
+ (by default `/home/mlrun_code`)
3202
3192
  """
3203
3193
  if not overwrite_build_params:
3204
3194
  # TODO: change overwrite_build_params default to True in 1.8.0
@@ -3222,6 +3212,7 @@ class MlrunProject(ModelObj):
3222
3212
  overwrite=overwrite_build_params,
3223
3213
  builder_env=builder_env,
3224
3214
  extra_args=extra_args,
3215
+ source_code_target_dir=source_code_target_dir,
3225
3216
  )
3226
3217
 
3227
3218
  if set_as_default and image != self.default_image:
@@ -3268,7 +3259,7 @@ class MlrunProject(ModelObj):
3268
3259
  * False: The new params are merged with the existing
3269
3260
  * True: The existing params are replaced by the new ones
3270
3261
  :param extra_args: A string containing additional builder arguments in the format of command-line options,
3271
- e.g. extra_args="--skip-tls-verify --build-arg A=val"r
3262
+ e.g. extra_args="--skip-tls-verify --build-arg A=val"
3272
3263
  :param target_dir: Path on the image where source code would be extracted (by default `/home/mlrun_code`)
3273
3264
  """
3274
3265
  if not base_image:
@@ -3336,6 +3327,11 @@ class MlrunProject(ModelObj):
3336
3327
  force_build=True,
3337
3328
  )
3338
3329
 
3330
+ # Get the enriched target dir from the function
3331
+ self.spec.build.source_code_target_dir = (
3332
+ function.spec.build.source_code_target_dir
3333
+ )
3334
+
3339
3335
  try:
3340
3336
  mlrun.db.get_run_db(secrets=self._secrets).delete_function(
3341
3337
  name=function.metadata.name
@@ -3749,6 +3745,18 @@ class MlrunProject(ModelObj):
3749
3745
 
3750
3746
  return mlrun.db.get_run_db().get_api_gateway(name=name, project=self.name)
3751
3747
 
3748
+ def delete_api_gateway(
3749
+ self,
3750
+ name: str,
3751
+ ):
3752
+ """
3753
+ Deletes an API gateway by name.
3754
+
3755
+ :param name: The name of the API gateway to delete.
3756
+ """
3757
+
3758
+ mlrun.db.get_run_db().delete_api_gateway(name=name, project=self.name)
3759
+
3752
3760
  def _run_authenticated_git_action(
3753
3761
  self,
3754
3762
  action: Callable,
mlrun/run.py CHANGED
@@ -847,6 +847,7 @@ def _run_pipeline(
847
847
  ops=None,
848
848
  url=None,
849
849
  cleanup_ttl=None,
850
+ timeout=60,
850
851
  ):
851
852
  """remote KubeFlow pipeline execution
852
853
 
@@ -884,6 +885,7 @@ def _run_pipeline(
884
885
  ops=ops,
885
886
  artifact_path=artifact_path,
886
887
  cleanup_ttl=cleanup_ttl,
888
+ timeout=timeout,
887
889
  )
888
890
  logger.info(f"Pipeline run id={pipeline_run_id}, check UI for progress")
889
891
  return pipeline_run_id
@@ -961,7 +963,7 @@ def wait_for_pipeline_completion(
961
963
  show_kfp_run(resp)
962
964
 
963
965
  status = resp["run"]["status"] if resp else "unknown"
964
- message = resp["run"].get("message", "")
966
+ message = resp["run"].get("message", "") if resp else ""
965
967
  if expected_statuses:
966
968
  if status not in expected_statuses:
967
969
  raise RuntimeError(
mlrun/runtimes/base.py CHANGED
@@ -840,6 +840,12 @@ class BaseRuntime(ModelObj):
840
840
  or (build.source and not build.load_source_on_run)
841
841
  )
842
842
 
843
+ def enrich_runtime_spec(
844
+ self,
845
+ project_node_selector: dict[str, str],
846
+ ):
847
+ pass
848
+
843
849
  def prepare_image_for_deploy(self):
844
850
  """
845
851
  if a function has a 'spec.image' it is considered to be deployed,