Files
openvino/tests/layer_tests/pytorch_tests/test_squeeze.py
Ekaterina Aidova 016eb43741 [PT FE]: fix issues with squeeze producing dynamic rank (#18748)
* [PT FE]: fix issues with squeeze producing dynamic rank

* Update test_squeeze.py

* Update test_squeeze.py

* Update test_slice.py

* Apply suggestions from code review
2023-07-24 20:10:20 +04:00

45 lines
1.6 KiB
Python

# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import pytest
from pytorch_layer_test_class import PytorchLayerTest
class TestSqueeze(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
return (np.random.randn(1, 1, 32).astype(np.float32),)
def create_model(self, dim):
import torch
class aten_squeeze(torch.nn.Module):
def __init__(self, dim):
super(aten_squeeze, self).__init__()
self.dim = dim
def forward(self, x):
if self.dim is not None:
return torch.squeeze(x, self.dim)
return torch.squeeze(x)
ref_net = None
return aten_squeeze(dim), ref_net, "aten::squeeze"
@pytest.mark.parametrize("dim,dynamic_shapes", [(-2, True), (0, True), (None, False)])
@pytest.mark.nightly
@pytest.mark.precommit
def test_squeeze(self, dim, dynamic_shapes, ie_device, precision, ir_version):
self._test(*self.create_model(dim), ie_device, precision, ir_version, dynamic_shapes=dynamic_shapes)
@pytest.mark.xfail(reason='OpenVINO squeeze does not support dimension is not equal to 1.')
@pytest.mark.parametrize("dim", [-1, 2])
@pytest.mark.nightly
@pytest.mark.precommit
def test_squeeze_non_1(self, dim, ie_device, precision, ir_version):
# Dynamic shapes are introducing dynamic rank, with is not suppoerted by Squeeze operation.
self._test(*self.create_model(dim), ie_device, precision, ir_version, dynamic_shapes=False)