Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Model Monitoring] Fix model endpoint labels and tag enrichment #5682

Merged
merged 5 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mlrun/model_monitoring/stream_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,9 @@ def __init__(self, project: str, model_endpoint_store_target: str, **kwargs):
self.model_endpoint_store_target = model_endpoint_store_target

def do(self, event: dict):
# Remove labels from the event
event.pop(EventFieldType.LABELS)

update_endpoint_record(
project=self.project,
endpoint_id=event.pop(EventFieldType.ENDPOINT_ID),
Expand Down
6 changes: 5 additions & 1 deletion mlrun/serving/v2_serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,11 @@ def _init_endpoint_record(
return None

# Generating version model value based on the model name and model version
if model.version:
if model.model_path and model.model_path.startswith("store://"):
# Enrich the model server with the model artifact metadata
model.get_model()
model.version = model.model_spec.tag
model.labels = model.model_spec.labels
versioned_model_name = f"{model.name}:{model.version}"
else:
versioned_model_name = f"{model.name}:latest"
Expand Down
33 changes: 27 additions & 6 deletions tests/system/model_monitoring/test_model_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ class TestBasicModelMonitoring(TestMLRunSystem):
def test_basic_model_monitoring(self) -> None:
# Main validations:
# 1 - a single model endpoint is created
# 2 - stream metrics are recorded as expected under the model endpoint
# 2 - model name, tag and values are recorded as expected under the model endpoint
# 3 - stream metrics are recorded as expected under the model endpoint

# Deploy Model Servers
project = self.project
Expand Down Expand Up @@ -278,6 +279,8 @@ def test_basic_model_monitoring(self) -> None:
)

model_name = "sklearn_RandomForestClassifier"
tag = "some-tag"
labels = {"framework": "sklearn", "mylabel": "l1"}

# Upload the model through the projects API so that it is available to the serving function
project.log_model(
Expand All @@ -286,12 +289,14 @@ def test_basic_model_monitoring(self) -> None:
model_file="model.pkl",
training_set=train_set,
artifact_path=f"v3io:///projects/{project.metadata.name}",
tag=tag,
labels=labels,
)
# Add the model to the serving function's routing spec
serving_fn.add_model(
model_name,
model_path=project.get_artifact_uri(
key=model_name, category="model", tag="latest"
key=model_name, category="model", tag=tag
),
)
if self.image is not None:
Expand All @@ -310,18 +315,34 @@ def test_basic_model_monitoring(self) -> None:
)
sleep(choice([0.01, 0.04]))

# Test metrics
sleep(5)
self._assert_model_endpoint_metrics()

def _assert_model_endpoint_metrics(self) -> None:
endpoints_list = mlrun.get_run_db().list_model_endpoints(
self.project_name, metrics=["predictions_per_second"]
)
assert len(endpoints_list) == 1

endpoint = endpoints_list[0]

self._assert_model_endpoint_tags_and_labels(
endpoint=endpoint, model_name=model_name, tag=tag, labels=labels
)

# Test metrics
self._assert_model_endpoint_metrics(endpoint=endpoint)

def _assert_model_endpoint_tags_and_labels(
self,
endpoint: mlrun.model_monitoring.model_endpoint.ModelEndpoint,
model_name: str,
tag: str,
labels: dict[str, str],
) -> None:
assert endpoint.metadata.labels == labels
assert endpoint.spec.model == f"{model_name}:{tag}"

def _assert_model_endpoint_metrics(
self, endpoint: mlrun.model_monitoring.model_endpoint.ModelEndpoint
) -> None:
assert len(endpoint.status.metrics) > 0
self._logger.debug("Model endpoint metrics", endpoint.status.metrics)

Expand Down
Loading