Skip to content

Commit 3468efc

Browse files
committed
Fix log_metric() to handle NaN valuesSigned-off-by: HarshitR2004 [email protected]
1 parent 716818b commit 3468efc

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

sdk/python/kfp/dsl/types/artifact_types.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""Classes and utilities for using and creating artifacts in components."""
1515

1616
import enum
17+
import math
1718
import os
1819
from typing import Dict, List, Optional, Type
1920
import warnings
@@ -121,8 +122,8 @@ def convert_local_path_to_remote_path(path: str) -> str:
121122
return RemotePrefix.S3.value + path[len(_S3_LOCAL_MOUNT_PREFIX):]
122123
elif path.startswith(_OCI_LOCAL_MOUNT_PREFIX):
123124
remote_path = path[len(_OCI_LOCAL_MOUNT_PREFIX):].replace('_', '/')
124-
if remote_path.endswith("/models"):
125-
remote_path = remote_path[:-len("/models")]
125+
if remote_path.endswith('/models'):
126+
remote_path = remote_path[:-len('/models')]
126127

127128
return RemotePrefix.OCI.value + remote_path
128129

@@ -148,10 +149,10 @@ def _get_framework(self) -> str:
148149

149150
@property
150151
def path(self) -> str:
151-
if self.uri.startswith("oci://"):
152+
if self.uri.startswith('oci://'):
152153
# Modelcar container images are expected to have the model files stored in /models
153154
# https://github.com/kserve/kserve/blob/v0.14.1/pkg/webhook/admission/pod/storage_initializer_injector.go#L732
154-
return self._get_path() + "/models"
155+
return self._get_path() + '/models'
155156

156157
return self._get_path()
157158

@@ -191,6 +192,10 @@ def log_metric(self, metric: str, value: float) -> None:
191192
metric: The metric key.
192193
value: The metric value.
193194
"""
195+
if math.isnan(value):
196+
warnings.warn(f'Metric "{metric}" is NaN and will be skipped.', stacklevel=2)
197+
return
198+
194199
self.metadata[metric] = value
195200

196201

0 commit comments

Comments
 (0)