openvinotoolkit / openvino

OpenVINO™ is an open-source toolkit for optimizing and deploying AI inference
https://docs.openvino.ai
Apache License 2.0
7.22k stars 2.25k forks source link

[Bug]: Expected a 3D, 4D or 5D tensor for the input. Got: [?,?] #21052

Open jikechao opened 11 months ago

jikechao commented 11 months ago

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

A similar bug with https://github.com/openvinotoolkit/openvino/issues/20907

According to the PyTorch doc, a 2D input (C, L_in) is valid, but it will crash when converted to OVIR. In my personal view, OpenVINO should keep aligned with PyTorch.

image

Step-by-step reproduction

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

input_data = torch.randn([2, 5], dtype=torch.float32)
class max_pool1d(Module):
    def forward(self, *args):
        torch.nn.MaxPool1d
        return torch.nn.functional.max_pool1d(args[0], kernel_size=3,)

torch_model = max_pool1d().float().eval()
torch_outputs = torch_model(input_data).cpu().numpy()
print(torch_outputs)

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

input_shapes = input_data.shape
ov_model = ov.convert_model(trace, example_input=input_data)

Relevant log output

Traceback (most recent call last):
  File "test.py", line 20, in <module>
    ov_model = ov.convert_model(trace, example_input=input_data)
  File "C:\software\conda\envs\torch\lib\site-packages\openvino\tools\ovc\convert.py", line 101, in convert_model
    ov_model, _ = _convert(cli_parser, params, True)
  File "C:\software\conda\envs\torch\lib\site-packages\openvino\tools\ovc\convert_impl.py", line 524, in _convert
    raise e
  File "C:\software\conda\envs\torch\lib\site-packages\openvino\tools\ovc\convert_impl.py", line 476, in _convert
    ov_model = driver(argv, {"conversion_parameters": non_default_params})
  File "C:\software\conda\envs\torch\lib\site-packages\openvino\tools\ovc\convert_impl.py", line 226, in driver
    ov_model = moc_emit_ir(prepare_ir(argv), argv)
  File "C:\software\conda\envs\torch\lib\site-packages\openvino\tools\ovc\convert_impl.py", line 172, in prepare_ir
    ov_model = moc_pipeline(argv, moc_front_end)
  File "C:\software\conda\envs\torch\lib\site-packages\openvino\tools\ovc\moc_frontend\pipeline.py", line 247, in moc_pipeline
    ov_model = moc_front_end.convert(input_model)
  File "C:\software\conda\envs\torch\lib\site-packages\openvino\frontend\frontend.py", line 18, in convert
    converted_model = super().convert(model)
openvino._pyopenvino.OpConversionFailure: Check 'is_conversion_successful' failed at src\frontends\pytorch\src\frontend.cpp:138:
FrontEnd API failed with OpConversionFailure:
Model wasn't fully converted. Failed operations detailed log:
-- aten::max_pool1d with a message:
Exception happened during conversion of operation aten::max_pool1d with schema aten::max_pool1d(Tensor self, int[1] kernel_size, int[1] stride=[], int[1] padding=[0], int[1] dilation=[1], bool ceil_mode=False) -> Tensor
Check 'is_rank_compatible_any_of(data_rank, {3, 4, 5})' failed at src\core\shape_inference\include\pooling_shape_inference_util.hpp:37:
While validating node 'opset8::MaxPool MaxPool_8 (input[0]:f32[?,?]) -> (dynamic[...])' with friendly_name 'MaxPool_8':
Expected a 3D, 4D or 5D tensor for the input. Got: [?,?]

Summary:
-- Conversion is failed for: aten::max_pool1d

Issue submission checklist

mvafin commented 11 months ago

Yes, I agree. We plan to fix that. We have a publicly available issue for that task: #20927

jikechao commented 11 months ago

@mvafin Thanks for your confirmation.

jikechao commented 7 months ago

BTW, the operator AvgPool2d can cause the same bug as the MaxPool2d.

mlukasze commented 7 months ago

@p-wysocki for you attention