diff --git a/onnxruntime/python/tools/symbolic_shape_infer.py b/onnxruntime/python/tools/symbolic_shape_infer.py index 9bc2328cc71b6..e9499577ffa3d 100755 --- a/onnxruntime/python/tools/symbolic_shape_infer.py +++ b/onnxruntime/python/tools/symbolic_shape_infer.py @@ -603,7 +603,12 @@ def int_or_float(value, allow_float_values): # If casting into int has precision loss: keep float output if allow_float_values and value % 1 != 0: return value - return int(value) + # Handle NaN and inf values explicitly + if np.isinf(value): + # Use the maximum float value as the replacement + return np.finfo(np.float32).max + if np.isnan(value): + return 0 values = [self._try_get_value(node, i) for i in range(len(node.input))] if all([v is not None for v in values]):