Skip to content

[Bug]: Float64 Infinity values are clamped to MAX_FLOAT on CPU backend #34138

@goyaladitya05

Description

@goyaladitya05

OpenVINO Version

2025.4.1

Operating System

Windows System

Device used for inference

CPU

Framework

None

Model used

No response

Issue description

I noticed an issue where float64 infinity values (np.inf, -np.inf) are not preserved when round-tripped through OpenVINO tensors on the CPU backend. Instead of remaining as infinity, they are clamped to the maximum finite representation of float64 (approx 1.797e+308). This differs from float32 behavior, where infinity values are correctly preserved.

Similar issue has been reported before in #30264 , but that issue was closed.

Step-by-step reproduction

import numpy as np
import openvino as ov
import openvino.opset15 as ov_opset

def test_inf_preservation():
    # Test float32 (Working)
    x_f32 = np.array([np.inf, -np.inf, 1.0], dtype=np.float32)
    const_f32 = ov_opset.constant(x_f32, dtype=ov.Type.f32)
    # Compile and run a simple identity model
    model_f32 = ov.Model([const_f32], [])
    compiled_f32 = ov.compile_model(model_f32, "CPU")
    res_f32 = compiled_f32({})[0]
    print(f"FP32 Input: {x_f32}")
    print(f"FP32 Output: {res_f32}")
    
    # Test float64 (Failing)
    x_f64 = np.array([np.inf, -np.inf, 1.0], dtype=np.float64)
    const_f64 = ov_opset.constant(x_f64, dtype=ov.Type.f64)
    # Compile and run a simple identity model
    model_f64 = ov.Model([const_f64], [])
    compiled_f64 = ov.compile_model(model_f64, "CPU")
    res_f64 = compiled_f64({})[0]
    print(f"FP64 Input: {x_f64}")
    print(f"FP64 Output: {res_f64}")

    # Check for failure 
    assert np.isinf(res_f64[0]), "FP64 +inf was lost!"
    assert np.isinf(res_f64[1]), "FP64 -inf was lost!"

if __name__ == "__main__":
    try:
        test_inf_preservation()
        print("Test PASSED (Infinities preserved)")
    except AssertionError as e:
        print(f"Test FAILED as expected: {e}")

Relevant log output

FP32 Input: [ inf -inf   1.]
FP32 Output: [ inf -inf   1.]
FP64 Input: [ inf -inf   1.]
FP64 Output: [ 3.40282347e+38 -3.40282347e+38  1.00000000e+00]
Test FAILED as expected: FP64 +inf was lost!

Issue submission checklist

  • I'm reporting an issue. It's not a question.
  • I checked the problem with the documentation, FAQ, open issues, Stack Overflow, etc., and have not found a solution.
  • There is reproducer code and related data files such as images, videos, models, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions