From 58470889f62ff557bb8deb31f63e97eb02bfbc86 Mon Sep 17 00:00:00 2001 From: HarshitR2004 Date: Sat, 25 Oct 2025 04:30:15 +0530 Subject: [PATCH] Fix log_metric() to handle NaN valuesSigned-off-by: HarshitR2004 harshithranjan6971@gmail.com Signed-off-by: HarshitR2004 --- sdk/python/kfp/dsl/types/artifact_types.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sdk/python/kfp/dsl/types/artifact_types.py b/sdk/python/kfp/dsl/types/artifact_types.py index fed21b159c1..5ca3ba0f123 100644 --- a/sdk/python/kfp/dsl/types/artifact_types.py +++ b/sdk/python/kfp/dsl/types/artifact_types.py @@ -14,6 +14,7 @@ """Classes and utilities for using and creating artifacts in components.""" import enum +import math import os from typing import Dict, List, Optional, Type import warnings @@ -121,8 +122,8 @@ def convert_local_path_to_remote_path(path: str) -> str: return RemotePrefix.S3.value + path[len(_S3_LOCAL_MOUNT_PREFIX):] elif path.startswith(_OCI_LOCAL_MOUNT_PREFIX): remote_path = path[len(_OCI_LOCAL_MOUNT_PREFIX):].replace('_', '/') - if remote_path.endswith("/models"): - remote_path = remote_path[:-len("/models")] + if remote_path.endswith('/models'): + remote_path = remote_path[:-len('/models')] return RemotePrefix.OCI.value + remote_path @@ -148,10 +149,10 @@ def _get_framework(self) -> str: @property def path(self) -> str: - if self.uri.startswith("oci://"): + if self.uri.startswith('oci://'): # Modelcar container images are expected to have the model files stored in /models # https://github.com/kserve/kserve/blob/v0.14.1/pkg/webhook/admission/pod/storage_initializer_injector.go#L732 - return self._get_path() + "/models" + return self._get_path() + '/models' return self._get_path() @@ -191,6 +192,10 @@ def log_metric(self, metric: str, value: float) -> None: metric: The metric key. value: The metric value. """ + if math.isnan(value): + warnings.warn(f'Metric "{metric}" is NaN and will be skipped.', stacklevel=2) + return + self.metadata[metric] = value