forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for concatenation in Loop (openvinotoolkit#15899)
* Add support for concatenation in Loop * Apply suggestions from code review * Fix win build * Fix issues with propagation shapes and types in Loop * Fix einsum * Set type and shape of count in frontend
- Loading branch information
Showing
10 changed files
with
159 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (C) 2018-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "openvino/frontend/pytorch/node_context.hpp" | ||
#include "pt_framework_node.hpp" | ||
#include "utils.hpp" | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace pytorch { | ||
namespace op { | ||
|
||
OutputVector translate_cat(NodeContext& context) { | ||
// This translator is only needed to get axis as constant from external scope | ||
num_inputs_check(context, 2, 2); | ||
auto fw_node = std::make_shared<PtFrameworkNode>(context.get_decoder(), OutputVector{context.get_input(0)}, 1); | ||
auto attrs = fw_node->get_attrs(); | ||
// If this fails it means axis is dynamic and aten::cat will be converted to fw node in regular pipeline | ||
attrs["axis"] = std::to_string(context.const_input<int64_t>(1)); | ||
fw_node->set_attrs(attrs); | ||
return {context.mark_node(std::dynamic_pointer_cast<Node>(fw_node))}; | ||
}; | ||
|
||
} // namespace op | ||
} // namespace pytorch | ||
} // namespace frontend | ||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# 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 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 | ||
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) |