mlrun 1.7.2rc4__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.
- mlrun/__init__.py +26 -22
- mlrun/__main__.py +15 -16
- mlrun/alerts/alert.py +150 -15
- mlrun/api/schemas/__init__.py +1 -9
- mlrun/artifacts/__init__.py +2 -3
- mlrun/artifacts/base.py +62 -19
- mlrun/artifacts/dataset.py +17 -17
- mlrun/artifacts/document.py +454 -0
- mlrun/artifacts/manager.py +28 -18
- mlrun/artifacts/model.py +91 -59
- mlrun/artifacts/plots.py +2 -2
- mlrun/common/constants.py +8 -0
- mlrun/common/formatters/__init__.py +1 -0
- mlrun/common/formatters/artifact.py +1 -1
- mlrun/common/formatters/feature_set.py +2 -0
- mlrun/common/formatters/function.py +1 -0
- mlrun/{model_monitoring/db/stores/v3io_kv/__init__.py → common/formatters/model_endpoint.py} +17 -0
- mlrun/common/formatters/pipeline.py +1 -2
- mlrun/common/formatters/project.py +9 -0
- mlrun/common/model_monitoring/__init__.py +0 -5
- mlrun/common/model_monitoring/helpers.py +12 -62
- mlrun/common/runtimes/constants.py +25 -4
- mlrun/common/schemas/__init__.py +9 -5
- mlrun/common/schemas/alert.py +114 -19
- mlrun/common/schemas/api_gateway.py +3 -3
- mlrun/common/schemas/artifact.py +22 -9
- mlrun/common/schemas/auth.py +8 -4
- mlrun/common/schemas/background_task.py +7 -7
- mlrun/common/schemas/client_spec.py +4 -4
- mlrun/common/schemas/clusterization_spec.py +2 -2
- mlrun/common/schemas/common.py +53 -3
- mlrun/common/schemas/constants.py +15 -0
- mlrun/common/schemas/datastore_profile.py +1 -1
- mlrun/common/schemas/feature_store.py +9 -9
- mlrun/common/schemas/frontend_spec.py +4 -4
- mlrun/common/schemas/function.py +10 -10
- mlrun/common/schemas/hub.py +1 -1
- mlrun/common/schemas/k8s.py +3 -3
- mlrun/common/schemas/memory_reports.py +3 -3
- mlrun/common/schemas/model_monitoring/__init__.py +4 -8
- mlrun/common/schemas/model_monitoring/constants.py +127 -46
- mlrun/common/schemas/model_monitoring/grafana.py +18 -12
- mlrun/common/schemas/model_monitoring/model_endpoints.py +154 -160
- mlrun/common/schemas/notification.py +24 -3
- mlrun/common/schemas/object.py +1 -1
- mlrun/common/schemas/pagination.py +4 -4
- mlrun/common/schemas/partition.py +142 -0
- mlrun/common/schemas/pipeline.py +3 -3
- mlrun/common/schemas/project.py +26 -18
- mlrun/common/schemas/runs.py +3 -3
- mlrun/common/schemas/runtime_resource.py +5 -5
- mlrun/common/schemas/schedule.py +1 -1
- mlrun/common/schemas/secret.py +1 -1
- mlrun/{model_monitoring/db/stores/sqldb/__init__.py → common/schemas/serving.py} +10 -1
- mlrun/common/schemas/tag.py +3 -3
- mlrun/common/schemas/workflow.py +6 -5
- mlrun/common/types.py +1 -0
- mlrun/config.py +157 -89
- mlrun/data_types/__init__.py +5 -3
- mlrun/data_types/infer.py +13 -3
- mlrun/data_types/spark.py +2 -1
- mlrun/datastore/__init__.py +59 -18
- mlrun/datastore/alibaba_oss.py +4 -1
- mlrun/datastore/azure_blob.py +4 -1
- mlrun/datastore/base.py +19 -24
- mlrun/datastore/datastore.py +10 -4
- mlrun/datastore/datastore_profile.py +178 -45
- mlrun/datastore/dbfs_store.py +4 -1
- mlrun/datastore/filestore.py +4 -1
- mlrun/datastore/google_cloud_storage.py +4 -1
- mlrun/datastore/hdfs.py +4 -1
- mlrun/datastore/inmem.py +4 -1
- mlrun/datastore/redis.py +4 -1
- mlrun/datastore/s3.py +14 -3
- mlrun/datastore/sources.py +89 -92
- mlrun/datastore/store_resources.py +7 -4
- mlrun/datastore/storeytargets.py +51 -16
- mlrun/datastore/targets.py +38 -31
- mlrun/datastore/utils.py +87 -4
- mlrun/datastore/v3io.py +4 -1
- mlrun/datastore/vectorstore.py +291 -0
- mlrun/datastore/wasbfs/fs.py +13 -12
- mlrun/db/base.py +286 -100
- mlrun/db/httpdb.py +1562 -490
- mlrun/db/nopdb.py +250 -83
- mlrun/errors.py +6 -2
- mlrun/execution.py +194 -50
- mlrun/feature_store/__init__.py +2 -10
- mlrun/feature_store/api.py +20 -458
- mlrun/feature_store/common.py +9 -9
- mlrun/feature_store/feature_set.py +20 -18
- mlrun/feature_store/feature_vector.py +105 -479
- mlrun/feature_store/feature_vector_utils.py +466 -0
- mlrun/feature_store/retrieval/base.py +15 -11
- mlrun/feature_store/retrieval/job.py +2 -1
- mlrun/feature_store/retrieval/storey_merger.py +1 -1
- mlrun/feature_store/steps.py +3 -3
- mlrun/features.py +30 -13
- mlrun/frameworks/__init__.py +1 -2
- mlrun/frameworks/_common/__init__.py +1 -2
- mlrun/frameworks/_common/artifacts_library.py +2 -2
- mlrun/frameworks/_common/mlrun_interface.py +10 -6
- mlrun/frameworks/_common/model_handler.py +31 -31
- mlrun/frameworks/_common/producer.py +3 -1
- mlrun/frameworks/_dl_common/__init__.py +1 -2
- mlrun/frameworks/_dl_common/loggers/__init__.py +1 -2
- mlrun/frameworks/_dl_common/loggers/mlrun_logger.py +4 -4
- mlrun/frameworks/_dl_common/loggers/tensorboard_logger.py +3 -3
- mlrun/frameworks/_ml_common/__init__.py +1 -2
- mlrun/frameworks/_ml_common/loggers/__init__.py +1 -2
- mlrun/frameworks/_ml_common/model_handler.py +21 -21
- mlrun/frameworks/_ml_common/plans/__init__.py +1 -2
- mlrun/frameworks/_ml_common/plans/confusion_matrix_plan.py +3 -1
- mlrun/frameworks/_ml_common/plans/dataset_plan.py +3 -3
- mlrun/frameworks/_ml_common/plans/roc_curve_plan.py +4 -4
- mlrun/frameworks/auto_mlrun/__init__.py +1 -2
- mlrun/frameworks/auto_mlrun/auto_mlrun.py +22 -15
- mlrun/frameworks/huggingface/__init__.py +1 -2
- mlrun/frameworks/huggingface/model_server.py +9 -9
- mlrun/frameworks/lgbm/__init__.py +47 -44
- mlrun/frameworks/lgbm/callbacks/__init__.py +1 -2
- mlrun/frameworks/lgbm/callbacks/logging_callback.py +4 -2
- mlrun/frameworks/lgbm/callbacks/mlrun_logging_callback.py +4 -2
- mlrun/frameworks/lgbm/mlrun_interfaces/__init__.py +1 -2
- mlrun/frameworks/lgbm/mlrun_interfaces/mlrun_interface.py +5 -5
- mlrun/frameworks/lgbm/model_handler.py +15 -11
- mlrun/frameworks/lgbm/model_server.py +11 -7
- mlrun/frameworks/lgbm/utils.py +2 -2
- mlrun/frameworks/onnx/__init__.py +1 -2
- mlrun/frameworks/onnx/dataset.py +3 -3
- mlrun/frameworks/onnx/mlrun_interface.py +2 -2
- mlrun/frameworks/onnx/model_handler.py +7 -5
- mlrun/frameworks/onnx/model_server.py +8 -6
- mlrun/frameworks/parallel_coordinates.py +11 -11
- mlrun/frameworks/pytorch/__init__.py +22 -23
- mlrun/frameworks/pytorch/callbacks/__init__.py +1 -2
- mlrun/frameworks/pytorch/callbacks/callback.py +2 -1
- mlrun/frameworks/pytorch/callbacks/logging_callback.py +15 -8
- mlrun/frameworks/pytorch/callbacks/mlrun_logging_callback.py +19 -12
- mlrun/frameworks/pytorch/callbacks/tensorboard_logging_callback.py +22 -15
- mlrun/frameworks/pytorch/callbacks_handler.py +36 -30
- mlrun/frameworks/pytorch/mlrun_interface.py +17 -17
- mlrun/frameworks/pytorch/model_handler.py +21 -17
- mlrun/frameworks/pytorch/model_server.py +13 -9
- mlrun/frameworks/sklearn/__init__.py +19 -18
- mlrun/frameworks/sklearn/estimator.py +2 -2
- mlrun/frameworks/sklearn/metric.py +3 -3
- mlrun/frameworks/sklearn/metrics_library.py +8 -6
- mlrun/frameworks/sklearn/mlrun_interface.py +3 -2
- mlrun/frameworks/sklearn/model_handler.py +4 -3
- mlrun/frameworks/tf_keras/__init__.py +11 -12
- mlrun/frameworks/tf_keras/callbacks/__init__.py +1 -2
- mlrun/frameworks/tf_keras/callbacks/logging_callback.py +17 -14
- mlrun/frameworks/tf_keras/callbacks/mlrun_logging_callback.py +15 -12
- mlrun/frameworks/tf_keras/callbacks/tensorboard_logging_callback.py +21 -18
- mlrun/frameworks/tf_keras/model_handler.py +17 -13
- mlrun/frameworks/tf_keras/model_server.py +12 -8
- mlrun/frameworks/xgboost/__init__.py +19 -18
- mlrun/frameworks/xgboost/model_handler.py +13 -9
- mlrun/k8s_utils.py +2 -5
- mlrun/launcher/base.py +3 -4
- mlrun/launcher/client.py +2 -2
- mlrun/launcher/local.py +6 -2
- mlrun/launcher/remote.py +1 -1
- mlrun/lists.py +8 -4
- mlrun/model.py +132 -46
- mlrun/model_monitoring/__init__.py +3 -5
- mlrun/model_monitoring/api.py +113 -98
- mlrun/model_monitoring/applications/__init__.py +0 -5
- mlrun/model_monitoring/applications/_application_steps.py +81 -50
- mlrun/model_monitoring/applications/base.py +467 -14
- mlrun/model_monitoring/applications/context.py +212 -134
- mlrun/model_monitoring/{db/stores/base → applications/evidently}/__init__.py +6 -2
- mlrun/model_monitoring/applications/evidently/base.py +146 -0
- mlrun/model_monitoring/applications/histogram_data_drift.py +89 -56
- mlrun/model_monitoring/applications/results.py +67 -15
- mlrun/model_monitoring/controller.py +701 -315
- mlrun/model_monitoring/db/__init__.py +0 -2
- mlrun/model_monitoring/db/_schedules.py +242 -0
- mlrun/model_monitoring/db/_stats.py +189 -0
- mlrun/model_monitoring/db/tsdb/__init__.py +33 -22
- mlrun/model_monitoring/db/tsdb/base.py +243 -49
- mlrun/model_monitoring/db/tsdb/tdengine/schemas.py +76 -36
- mlrun/model_monitoring/db/tsdb/tdengine/stream_graph_steps.py +33 -0
- mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connection.py +213 -0
- mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connector.py +534 -88
- mlrun/model_monitoring/db/tsdb/v3io/stream_graph_steps.py +1 -0
- mlrun/model_monitoring/db/tsdb/v3io/v3io_connector.py +436 -106
- mlrun/model_monitoring/helpers.py +356 -114
- mlrun/model_monitoring/stream_processing.py +190 -345
- mlrun/model_monitoring/tracking_policy.py +11 -4
- mlrun/model_monitoring/writer.py +49 -90
- mlrun/package/__init__.py +3 -6
- mlrun/package/context_handler.py +2 -2
- mlrun/package/packager.py +12 -9
- mlrun/package/packagers/__init__.py +0 -2
- mlrun/package/packagers/default_packager.py +14 -11
- mlrun/package/packagers/numpy_packagers.py +16 -7
- mlrun/package/packagers/pandas_packagers.py +18 -18
- mlrun/package/packagers/python_standard_library_packagers.py +25 -11
- mlrun/package/packagers_manager.py +35 -32
- mlrun/package/utils/__init__.py +0 -3
- mlrun/package/utils/_pickler.py +6 -6
- mlrun/platforms/__init__.py +47 -16
- mlrun/platforms/iguazio.py +4 -1
- mlrun/projects/operations.py +30 -30
- mlrun/projects/pipelines.py +116 -47
- mlrun/projects/project.py +1292 -329
- mlrun/render.py +5 -9
- mlrun/run.py +57 -14
- mlrun/runtimes/__init__.py +1 -3
- mlrun/runtimes/base.py +30 -22
- mlrun/runtimes/daskjob.py +9 -9
- mlrun/runtimes/databricks_job/databricks_runtime.py +6 -5
- mlrun/runtimes/function_reference.py +5 -2
- mlrun/runtimes/generators.py +3 -2
- mlrun/runtimes/kubejob.py +6 -7
- mlrun/runtimes/mounts.py +574 -0
- mlrun/runtimes/mpijob/__init__.py +0 -2
- mlrun/runtimes/mpijob/abstract.py +7 -6
- mlrun/runtimes/nuclio/api_gateway.py +7 -7
- mlrun/runtimes/nuclio/application/application.py +11 -13
- mlrun/runtimes/nuclio/application/reverse_proxy.go +66 -64
- mlrun/runtimes/nuclio/function.py +127 -70
- mlrun/runtimes/nuclio/serving.py +105 -37
- mlrun/runtimes/pod.py +159 -54
- mlrun/runtimes/remotesparkjob.py +3 -2
- mlrun/runtimes/sparkjob/__init__.py +0 -2
- mlrun/runtimes/sparkjob/spark3job.py +22 -12
- mlrun/runtimes/utils.py +7 -6
- mlrun/secrets.py +2 -2
- mlrun/serving/__init__.py +8 -0
- mlrun/serving/merger.py +7 -5
- mlrun/serving/remote.py +35 -22
- mlrun/serving/routers.py +186 -240
- mlrun/serving/server.py +41 -10
- mlrun/serving/states.py +432 -118
- mlrun/serving/utils.py +13 -2
- mlrun/serving/v1_serving.py +3 -2
- mlrun/serving/v2_serving.py +161 -203
- mlrun/track/__init__.py +1 -1
- mlrun/track/tracker.py +2 -2
- mlrun/track/trackers/mlflow_tracker.py +6 -5
- mlrun/utils/async_http.py +35 -22
- mlrun/utils/clones.py +7 -4
- mlrun/utils/helpers.py +511 -58
- mlrun/utils/logger.py +119 -13
- mlrun/utils/notifications/notification/__init__.py +22 -19
- mlrun/utils/notifications/notification/base.py +39 -15
- mlrun/utils/notifications/notification/console.py +6 -6
- mlrun/utils/notifications/notification/git.py +11 -11
- mlrun/utils/notifications/notification/ipython.py +10 -9
- mlrun/utils/notifications/notification/mail.py +176 -0
- mlrun/utils/notifications/notification/slack.py +16 -8
- mlrun/utils/notifications/notification/webhook.py +24 -8
- mlrun/utils/notifications/notification_pusher.py +191 -200
- mlrun/utils/regex.py +12 -2
- mlrun/utils/version/version.json +2 -2
- {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info}/METADATA +69 -54
- mlrun-1.8.0.dist-info/RECORD +351 -0
- {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info}/WHEEL +1 -1
- mlrun/model_monitoring/applications/evidently_base.py +0 -137
- mlrun/model_monitoring/db/stores/__init__.py +0 -136
- mlrun/model_monitoring/db/stores/base/store.py +0 -213
- mlrun/model_monitoring/db/stores/sqldb/models/__init__.py +0 -71
- mlrun/model_monitoring/db/stores/sqldb/models/base.py +0 -190
- mlrun/model_monitoring/db/stores/sqldb/models/mysql.py +0 -103
- mlrun/model_monitoring/db/stores/sqldb/models/sqlite.py +0 -40
- mlrun/model_monitoring/db/stores/sqldb/sql_store.py +0 -659
- mlrun/model_monitoring/db/stores/v3io_kv/kv_store.py +0 -726
- mlrun/model_monitoring/model_endpoint.py +0 -118
- mlrun-1.7.2rc4.dist-info/RECORD +0 -351
- {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info}/entry_points.txt +0 -0
- {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info/licenses}/LICENSE +0 -0
- {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info}/top_level.txt +0 -0
mlrun/runtimes/nuclio/serving.py
CHANGED
|
@@ -22,7 +22,7 @@ import nuclio
|
|
|
22
22
|
from nuclio import KafkaTrigger
|
|
23
23
|
|
|
24
24
|
import mlrun
|
|
25
|
-
import mlrun.common.schemas
|
|
25
|
+
import mlrun.common.schemas as schemas
|
|
26
26
|
from mlrun.datastore import get_kafka_brokers_from_dict, parse_kafka_url
|
|
27
27
|
from mlrun.model import ObjectList
|
|
28
28
|
from mlrun.runtimes.function_reference import FunctionReference
|
|
@@ -39,19 +39,19 @@ from mlrun.serving.states import (
|
|
|
39
39
|
)
|
|
40
40
|
from mlrun.utils import get_caller_globals, logger, set_paths
|
|
41
41
|
|
|
42
|
-
from .function import NuclioSpec, RemoteRuntime
|
|
42
|
+
from .function import NuclioSpec, RemoteRuntime, min_nuclio_versions
|
|
43
43
|
|
|
44
44
|
serving_subkind = "serving_v2"
|
|
45
45
|
|
|
46
46
|
if TYPE_CHECKING:
|
|
47
|
-
# remove this block in 1.
|
|
47
|
+
# remove this block in 1.10.0
|
|
48
48
|
from mlrun.model_monitoring import TrackingPolicy
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
def new_v2_model_server(
|
|
52
52
|
name,
|
|
53
53
|
model_class: str,
|
|
54
|
-
models: dict = None,
|
|
54
|
+
models: Optional[dict] = None,
|
|
55
55
|
filename="",
|
|
56
56
|
protocol="",
|
|
57
57
|
image="",
|
|
@@ -152,6 +152,7 @@ class ServingSpec(NuclioSpec):
|
|
|
152
152
|
clone_target_dir=None,
|
|
153
153
|
state_thresholds=None,
|
|
154
154
|
disable_default_http_trigger=None,
|
|
155
|
+
model_endpoint_creation_task_name=None,
|
|
155
156
|
):
|
|
156
157
|
super().__init__(
|
|
157
158
|
command=command,
|
|
@@ -209,6 +210,7 @@ class ServingSpec(NuclioSpec):
|
|
|
209
210
|
self.tracking_policy = tracking_policy
|
|
210
211
|
self.secret_sources = secret_sources or []
|
|
211
212
|
self.default_content_type = default_content_type
|
|
213
|
+
self.model_endpoint_creation_task_name = model_endpoint_creation_task_name
|
|
212
214
|
|
|
213
215
|
@property
|
|
214
216
|
def graph(self) -> Union[RouterStep, RootFlowStep]:
|
|
@@ -269,13 +271,14 @@ class ServingRuntime(RemoteRuntime):
|
|
|
269
271
|
can specify special router class and router arguments
|
|
270
272
|
|
|
271
273
|
flow - workflow (DAG) with a chain of states
|
|
272
|
-
flow
|
|
274
|
+
flow supports both "sync" and "async" engines, with "async" being the default.
|
|
275
|
+
Branches are not allowed in sync mode.
|
|
273
276
|
when using async mode calling state.respond() will mark the state as the
|
|
274
277
|
one which generates the (REST) call response
|
|
275
278
|
|
|
276
279
|
:param topology: - graph topology, router or flow
|
|
277
280
|
:param class_name: - optional for router, router class name/path or router object
|
|
278
|
-
:param engine: - optional for flow, sync or async engine
|
|
281
|
+
:param engine: - optional for flow, sync or async engine
|
|
279
282
|
:param exist_ok: - allow overriding existing topology
|
|
280
283
|
:param class_args: - optional, router/flow class init args
|
|
281
284
|
|
|
@@ -298,7 +301,7 @@ class ServingRuntime(RemoteRuntime):
|
|
|
298
301
|
step = RouterStep(class_name=class_name, class_args=class_args)
|
|
299
302
|
self.spec.graph = step
|
|
300
303
|
elif topology == StepKinds.flow:
|
|
301
|
-
self.spec.graph = RootFlowStep(engine=engine)
|
|
304
|
+
self.spec.graph = RootFlowStep(engine=engine or "async")
|
|
302
305
|
else:
|
|
303
306
|
raise mlrun.errors.MLRunInvalidArgumentError(
|
|
304
307
|
f"unsupported topology {topology}, use 'router' or 'flow'"
|
|
@@ -309,7 +312,7 @@ class ServingRuntime(RemoteRuntime):
|
|
|
309
312
|
self,
|
|
310
313
|
stream_path: Optional[str] = None,
|
|
311
314
|
batch: Optional[int] = None,
|
|
312
|
-
|
|
315
|
+
sampling_percentage: float = 100,
|
|
313
316
|
stream_args: Optional[dict] = None,
|
|
314
317
|
tracking_policy: Optional[Union["TrackingPolicy", dict]] = None,
|
|
315
318
|
enable_tracking: bool = True,
|
|
@@ -317,13 +320,13 @@ class ServingRuntime(RemoteRuntime):
|
|
|
317
320
|
"""Apply on your serving function to monitor a deployed model, including real-time dashboards to detect drift
|
|
318
321
|
and analyze performance.
|
|
319
322
|
|
|
320
|
-
:param stream_path:
|
|
321
|
-
|
|
322
|
-
:param batch:
|
|
323
|
-
:param
|
|
324
|
-
|
|
325
|
-
:param
|
|
326
|
-
|
|
323
|
+
:param stream_path: Path/url of the tracking stream e.g. v3io:///users/mike/mystream
|
|
324
|
+
you can use the "dummy://" path for test/simulation.
|
|
325
|
+
:param batch: Deprecated. Micro batch size (send micro batches of N records at a time).
|
|
326
|
+
:param sampling_percentage: Down sampling events that will be pushed to the monitoring stream based on
|
|
327
|
+
a specified percentage. e.g. 50 for 50%. By default, all events are pushed.
|
|
328
|
+
:param stream_args: Stream initialization parameters, e.g. shards, retention_in_hours, ..
|
|
329
|
+
:param enable_tracking: Enabled/Disable model-monitoring tracking. Default True (tracking enabled).
|
|
327
330
|
|
|
328
331
|
Example::
|
|
329
332
|
|
|
@@ -335,19 +338,39 @@ class ServingRuntime(RemoteRuntime):
|
|
|
335
338
|
"""
|
|
336
339
|
# Applying model monitoring configurations
|
|
337
340
|
self.spec.track_models = enable_tracking
|
|
341
|
+
if self._spec and self._spec.function_refs:
|
|
342
|
+
logger.debug(
|
|
343
|
+
"Set tracking for children references", enable_tracking=enable_tracking
|
|
344
|
+
)
|
|
345
|
+
for name in self._spec.function_refs.keys():
|
|
346
|
+
self._spec.function_refs[name].track_models = enable_tracking
|
|
347
|
+
# Check if function_refs _function is filled if so update track_models field:
|
|
348
|
+
if self._spec.function_refs[name]._function:
|
|
349
|
+
self._spec.function_refs[
|
|
350
|
+
name
|
|
351
|
+
]._function.spec.track_models = enable_tracking
|
|
352
|
+
|
|
353
|
+
if not 0 < sampling_percentage <= 100:
|
|
354
|
+
raise mlrun.errors.MLRunInvalidArgumentError(
|
|
355
|
+
"`sampling_percentage` must be greater than 0 and less or equal to 100."
|
|
356
|
+
)
|
|
357
|
+
self.spec.parameters["sampling_percentage"] = sampling_percentage
|
|
338
358
|
|
|
339
359
|
if stream_path:
|
|
340
360
|
self.spec.parameters["log_stream"] = stream_path
|
|
341
361
|
if batch:
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
362
|
+
warnings.warn(
|
|
363
|
+
"The `batch` size parameter was deprecated in version 1.8.0 and is no longer used. "
|
|
364
|
+
"It will be removed in 1.11.",
|
|
365
|
+
# TODO: Remove this in 1.11
|
|
366
|
+
FutureWarning,
|
|
367
|
+
)
|
|
345
368
|
if stream_args:
|
|
346
369
|
self.spec.parameters["stream_args"] = stream_args
|
|
347
370
|
if tracking_policy is not None:
|
|
348
371
|
warnings.warn(
|
|
349
372
|
"The `tracking_policy` argument is deprecated from version 1.7.0 "
|
|
350
|
-
"and has no effect. It will be removed in 1.
|
|
373
|
+
"and has no effect. It will be removed in 1.10.0.\n"
|
|
351
374
|
"To set the desired model monitoring time window and schedule, use "
|
|
352
375
|
"the `base_period` argument in `project.enable_model_monitoring()`.",
|
|
353
376
|
FutureWarning,
|
|
@@ -356,12 +379,16 @@ class ServingRuntime(RemoteRuntime):
|
|
|
356
379
|
def add_model(
|
|
357
380
|
self,
|
|
358
381
|
key: str,
|
|
359
|
-
model_path: str = None,
|
|
360
|
-
class_name: str = None,
|
|
361
|
-
model_url: str = None,
|
|
362
|
-
handler: str = None,
|
|
363
|
-
router_step: str = None,
|
|
364
|
-
child_function: str = None,
|
|
382
|
+
model_path: Optional[str] = None,
|
|
383
|
+
class_name: Optional[str] = None,
|
|
384
|
+
model_url: Optional[str] = None,
|
|
385
|
+
handler: Optional[str] = None,
|
|
386
|
+
router_step: Optional[str] = None,
|
|
387
|
+
child_function: Optional[str] = None,
|
|
388
|
+
creation_strategy: Optional[
|
|
389
|
+
schemas.ModelEndpointCreationStrategy
|
|
390
|
+
] = schemas.ModelEndpointCreationStrategy.INPLACE,
|
|
391
|
+
outputs: Optional[list[str]] = None,
|
|
365
392
|
**class_args,
|
|
366
393
|
):
|
|
367
394
|
"""add ml model and/or route to the function.
|
|
@@ -384,6 +411,19 @@ class ServingRuntime(RemoteRuntime):
|
|
|
384
411
|
:param router_step: router step name (to determine which router we add the model to in graphs
|
|
385
412
|
with multiple router steps)
|
|
386
413
|
:param child_function: child function name, when the model runs in a child function
|
|
414
|
+
:param creation_strategy: Strategy for creating or updating the model endpoint:
|
|
415
|
+
* **overwrite**:
|
|
416
|
+
1. If model endpoints with the same name exist, delete the `latest` one.
|
|
417
|
+
2. Create a new model endpoint entry and set it as `latest`.
|
|
418
|
+
* **inplace** (default):
|
|
419
|
+
1. If model endpoints with the same name exist, update the `latest` entry.
|
|
420
|
+
2. Otherwise, create a new entry.
|
|
421
|
+
* **archive**:
|
|
422
|
+
1. If model endpoints with the same name exist, preserve them.
|
|
423
|
+
2. Create a new model endpoint with the same name and set it to `latest`.
|
|
424
|
+
:param outputs: list of the model outputs (e.g. labels) ,if provided will override the outputs that been
|
|
425
|
+
configured in the model artifact, please note that those outputs need to be equal to the
|
|
426
|
+
model serving function outputs (length, and order)
|
|
387
427
|
:param class_args: extra kwargs to pass to the model serving class __init__
|
|
388
428
|
(can be read in the model using .get_param(key) method)
|
|
389
429
|
"""
|
|
@@ -419,10 +459,15 @@ class ServingRuntime(RemoteRuntime):
|
|
|
419
459
|
if class_name and hasattr(class_name, "to_dict"):
|
|
420
460
|
if model_path:
|
|
421
461
|
class_name.model_path = model_path
|
|
422
|
-
|
|
462
|
+
if outputs:
|
|
463
|
+
class_name.outputs = outputs
|
|
464
|
+
key, state = params_to_step(
|
|
465
|
+
class_name,
|
|
466
|
+
key,
|
|
467
|
+
model_endpoint_creation_strategy=creation_strategy,
|
|
468
|
+
endpoint_type=schemas.EndpointType.LEAF_EP,
|
|
469
|
+
)
|
|
423
470
|
else:
|
|
424
|
-
if not model_path and not model_url:
|
|
425
|
-
raise ValueError("model_path or model_url must be provided")
|
|
426
471
|
class_name = class_name or self.spec.default_class
|
|
427
472
|
if class_name and not isinstance(class_name, str):
|
|
428
473
|
raise ValueError(
|
|
@@ -434,12 +479,23 @@ class ServingRuntime(RemoteRuntime):
|
|
|
434
479
|
model_path = str(model_path)
|
|
435
480
|
|
|
436
481
|
if model_url:
|
|
437
|
-
state = new_remote_endpoint(
|
|
482
|
+
state = new_remote_endpoint(
|
|
483
|
+
model_url,
|
|
484
|
+
creation_strategy=creation_strategy,
|
|
485
|
+
endpoint_type=schemas.EndpointType.LEAF_EP,
|
|
486
|
+
**class_args,
|
|
487
|
+
)
|
|
438
488
|
else:
|
|
439
489
|
class_args = deepcopy(class_args)
|
|
440
490
|
class_args["model_path"] = model_path
|
|
491
|
+
class_args["outputs"] = outputs
|
|
441
492
|
state = TaskStep(
|
|
442
|
-
class_name,
|
|
493
|
+
class_name,
|
|
494
|
+
class_args,
|
|
495
|
+
handler=handler,
|
|
496
|
+
function=child_function,
|
|
497
|
+
model_endpoint_creation_strategy=creation_strategy,
|
|
498
|
+
endpoint_type=schemas.EndpointType.LEAF_EP,
|
|
443
499
|
)
|
|
444
500
|
|
|
445
501
|
return graph.add_route(key, state)
|
|
@@ -462,7 +518,11 @@ class ServingRuntime(RemoteRuntime):
|
|
|
462
518
|
:return function object
|
|
463
519
|
"""
|
|
464
520
|
function_reference = FunctionReference(
|
|
465
|
-
url,
|
|
521
|
+
url,
|
|
522
|
+
image,
|
|
523
|
+
requirements=requirements,
|
|
524
|
+
kind=kind or "serving",
|
|
525
|
+
track_models=self.spec.track_models,
|
|
466
526
|
)
|
|
467
527
|
self._spec.function_refs.update(function_reference, name)
|
|
468
528
|
func = function_reference.to_function(self.kind)
|
|
@@ -509,7 +569,7 @@ class ServingRuntime(RemoteRuntime):
|
|
|
509
569
|
stream.path, group=group, shards=stream.shards, **trigger_args
|
|
510
570
|
)
|
|
511
571
|
|
|
512
|
-
def _deploy_function_refs(self, builder_env: dict = None):
|
|
572
|
+
def _deploy_function_refs(self, builder_env: Optional[dict] = None):
|
|
513
573
|
"""set metadata and deploy child functions"""
|
|
514
574
|
for function_ref in self._spec.function_refs.values():
|
|
515
575
|
logger.info(f"deploy child function {function_ref.name} ...")
|
|
@@ -577,13 +637,14 @@ class ServingRuntime(RemoteRuntime):
|
|
|
577
637
|
self.spec.secret_sources.append({"kind": kind, "source": source})
|
|
578
638
|
return self
|
|
579
639
|
|
|
640
|
+
@min_nuclio_versions("1.12.10")
|
|
580
641
|
def deploy(
|
|
581
642
|
self,
|
|
582
643
|
project="",
|
|
583
644
|
tag="",
|
|
584
645
|
verbose=False,
|
|
585
|
-
auth_info:
|
|
586
|
-
builder_env: dict = None,
|
|
646
|
+
auth_info: schemas.AuthInfo = None,
|
|
647
|
+
builder_env: Optional[dict] = None,
|
|
587
648
|
force_build: bool = False,
|
|
588
649
|
):
|
|
589
650
|
"""deploy model serving function to a local/remote cluster
|
|
@@ -644,12 +705,15 @@ class ServingRuntime(RemoteRuntime):
|
|
|
644
705
|
|
|
645
706
|
def _get_serving_spec(self):
|
|
646
707
|
function_name_uri_map = {f.name: f.uri(self) for f in self.spec.function_refs}
|
|
647
|
-
|
|
648
708
|
serving_spec = {
|
|
709
|
+
"function_name": self.metadata.name,
|
|
710
|
+
"function_tag": self.metadata.tag,
|
|
649
711
|
"function_uri": self._function_uri(),
|
|
712
|
+
"function_hash": self.metadata.hash,
|
|
713
|
+
"project": self.metadata.project,
|
|
650
714
|
"version": "v2",
|
|
651
715
|
"parameters": self.spec.parameters,
|
|
652
|
-
"graph": self.spec.graph.to_dict() if self.spec.graph else {},
|
|
716
|
+
"graph": self.spec.graph.to_dict(strip=True) if self.spec.graph else {},
|
|
653
717
|
"load_mode": self.spec.load_mode,
|
|
654
718
|
"functions": function_name_uri_map,
|
|
655
719
|
"graph_initializer": self.spec.graph_initializer,
|
|
@@ -657,6 +721,7 @@ class ServingRuntime(RemoteRuntime):
|
|
|
657
721
|
"track_models": self.spec.track_models,
|
|
658
722
|
"tracking_policy": None,
|
|
659
723
|
"default_content_type": self.spec.default_content_type,
|
|
724
|
+
"model_endpoint_creation_task_name": self.spec.model_endpoint_creation_task_name,
|
|
660
725
|
}
|
|
661
726
|
|
|
662
727
|
if self.spec.secret_sources:
|
|
@@ -707,6 +772,9 @@ class ServingRuntime(RemoteRuntime):
|
|
|
707
772
|
function_uri=self._function_uri(),
|
|
708
773
|
secret_sources=self.spec.secret_sources,
|
|
709
774
|
default_content_type=self.spec.default_content_type,
|
|
775
|
+
function_name=self.metadata.name,
|
|
776
|
+
function_tag=self.metadata.tag,
|
|
777
|
+
project=self.metadata.project,
|
|
710
778
|
**kwargs,
|
|
711
779
|
)
|
|
712
780
|
server.init_states(
|
|
@@ -714,7 +782,7 @@ class ServingRuntime(RemoteRuntime):
|
|
|
714
782
|
namespace=namespace,
|
|
715
783
|
logger=logger,
|
|
716
784
|
is_mock=True,
|
|
717
|
-
monitoring_mock=track_models,
|
|
785
|
+
monitoring_mock=self.spec.track_models,
|
|
718
786
|
)
|
|
719
787
|
|
|
720
788
|
if workdir:
|