Files
openvino/tests/layer_tests/pytorch_tests/test_cat.py
T
Maxim Vafin 48dec1000e [PT FE] Support inplace operations on aliases of tensors (#17856)
* Support operations on aliases of tensors

* Add tests

* Fix issue with convnd

* Fix code style

* Fix issue with tensor index of mutated tensor

* Fix if types alignment

* Fix issues in keypoint detectron2

* Fix issue with masks in detectron2

* Fix acuracy issue in mobilevitv2 models

* Remove unused includes

* Return upsample case in lictconstruct replacer

* Fix types, apply review feedback

* Apply feedback

* Revert change of not using shared_from_this for getitem

* Fix issue in prim::device transformation

* Fix layer tests

* Apply review feedback

* Fix issue with not existing alias to tensor
2023-06-13 13:30:48 +02:00

67 lines
2.1 KiB
Python

# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import pytest
import torch
from pytorch_layer_test_class import PytorchLayerTest
class aten_cat(torch.nn.Module):
def forward(self, x):
return torch.cat([x, x], 1)
class aten_append_cat(torch.nn.Module):
def forward(self, x):
list = []
list.append(x)
list.append(x)
return torch.cat(list, 1)
class aten_loop_append_cat(torch.nn.Module):
def forward(self, x):
list = []
for i in range(3):
list.append(x)
return torch.cat(list, 1)
class aten_add_cat(torch.nn.Module):
def forward(self, x):
list = [x, x]
list2 = list + [x, x]
return torch.cat(list2, 1)
class TestCat(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
return (np.random.randn(2, 1, 3),)
@pytest.mark.nightly
@pytest.mark.precommit
def test_cat(self, ie_device, precision, ir_version):
self._test(aten_cat(), None, ["aten::cat", "prim::ListConstruct"],
ie_device, precision, ir_version)
@pytest.mark.nightly
@pytest.mark.precommit
def test_append_cat(self, ie_device, precision, ir_version):
self._test(aten_append_cat(), None, ["aten::cat", "aten::append", "prim::ListConstruct"],
ie_device, precision, ir_version)
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.xfail(reason="Transformation RemoveMultiSubGraphOpDanglingParamsResults doesn't support removing unused merged inputs, ticket 112833.")
def test_loop_append_cat(self, ie_device, precision, ir_version):
self._test(aten_loop_append_cat(), None, ["aten::cat", "aten::append", "prim::ListConstruct", "prim::Loop"],
ie_device, precision, ir_version, freeze_model=False)
@pytest.mark.nightly
@pytest.mark.precommit
def test_add_cat(self, ie_device, precision, ir_version):
self._test(aten_add_cat(), None, ["aten::cat", "aten::add", "prim::ListConstruct"],
ie_device, precision, ir_version, freeze_model=False)