Add support for concating lists in aten::add (#15587)

This commit is contained in:
Maxim Vafin 2023-02-10 17:41:27 +01:00 committed by GitHub
parent b329b005a3
commit 00f8d2b992
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -5,6 +5,7 @@
#include "openvino/op/add.hpp"
#include "openvino/frontend/pytorch/node_context.hpp"
#include "openvino/op/concat.hpp"
#include "openvino/op/convert_like.hpp"
#include "openvino/op/multiply.hpp"
#include "utils.hpp"
@ -17,6 +18,13 @@ namespace op {
OutputVector translate_add(NodeContext& context) {
auto lhs = context.get_input(0);
auto rhs = context.get_input(1);
auto dtype0 = context.get_input_type(0);
auto dtype1 = context.get_input_type(1);
if (dtype0.is<type::List>() && dtype1.is<type::List>()) {
// aten::add.t(t[] a, t[] b) -> t[]
// Case when two lists gets concatenated
return {context.mark_node(std::make_shared<ov::op::v0::Concat>(OutputVector{lhs, rhs}, 0))};
}
align_eltwise_input_types(context, lhs, rhs);
if (!context.input_is_none(2)) {
auto converted_alpha = context.mark_node(std::make_shared<ov::op::v1::ConvertLike>(context.get_input(2), rhs));

View File

@ -100,3 +100,20 @@ class TestAddTypes(PytorchLayerTest):
self.rhs_shape = rhs_shape
self._test(*self.create_model(lhs_type, lhs_shape, rhs_type, rhs_shape),
ie_device, precision, ir_version)
class TestAddLists(PytorchLayerTest):
def _prepare_input(self):
return (np.random.randn(2, 5, 3, 4).astype(np.float32),)
def create_model(self):
class aten_add(torch.nn.Module):
def forward(self, x):
return x.reshape(x.shape[:-1] + (-1,))
return aten_add(), None, "aten::add"
@pytest.mark.nightly
@pytest.mark.precommit
def test_add(self, ie_device, precision, ir_version):
self._test(*self.create_model(), ie_device, precision, ir_version)