Skip to content

[Bug]: inconsistent results from PyTorch and OpenVINO about the lp_pool2d operator #21044

Description

@jikechao

OpenVINO Version

openvino-nightly 2023.2.0.dev20231101

Operating System

Ubuntu 18.04 (LTS)

Device used for inference

CPU

Framework

PyTorch

Model used

Given in the following script

Issue description

For the given PyTorch model in the following script, PyTorch and OpenVINO gave inconsistent inference results ("nan" for PyTorch and "0" for OpenVINO). They have different meanings. Thus, I think, OpenVINO should keep the same behavior as the PyTorch.

Step-by-step reproduction

import torch
from torch.nn import Module
import openvino as ov
import numpy as np


def compile_torch(model, input_data):
    ov_model = ov.convert_model(model, example_input=input_data)
    ir_path = f"temp_OVIR.xml"
    ov.save_model(ov_model, ir_path, compress_to_fp16=False)
    core = ov.Core()
    model = core.read_model(ir_path)

    compiled_model = core.compile_model(model=model, device_name="CPU")
    output_key = compiled_model.output(0)
    result = compiled_model(input_data)[output_key]
    return result

input_data = torch.randn([1, 3, 7, 7], dtype=torch.float32)


class lp_pool2d(Module):
    def forward(self, *args):
        return torch.nn.functional.lp_pool2d(args[0], norm_type=1.5, kernel_size=2)


torch_model = lp_pool2d().float().eval()
torch_outputs = torch_model(input_data).cpu().numpy()

trace = torch.jit.trace(torch_model, input_data)
trace = torch.jit.freeze(trace)

input_shapes = input_data.shape
res_ov = compile_torch(trace, input_data)
np.testing.assert_allclose(torch_outputs, res_ov, rtol=1e-3, atol=1e-3)

Relevant log output

AssertionError: 
Not equal to tolerance rtol=0.001, atol=0.001

x and y nan location mismatch:
 x: array([[[[     nan,      nan,      nan],
         [     nan,      nan,      nan],
         [     nan,      nan,      nan]],...
 y: array([[[[0.      , 0.      , 0.      ],
         [0.      , 0.      , 0.      ],
         [0.      , 0.      , 0.      ]],...

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

Labels

bugSomething isn't workingcategory: CPUOpenVINO CPU plugin

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions