OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[PT][FE] Fix FX Stack Translate to Process ListConstruct Args (#30209)
Aamir Nazir40a0a74c7ec9
diff --git a/src/frontends/pytorch/src/op/cat.cpp b/src/frontends/pytorch/src/op/cat.cppindex 5dcc52cf662..0298aaa80af 100644--- a/src/frontends/pytorch/src/op/cat.cpp+++ b/src/frontends/pytorch/src/op/cat.cpp@@ -127,27 +127,26 @@ OutputVector translate_quantized_cat(const NodeContext& context) {OutputVector translate_stack_fx(const NodeContext& context) {num_inputs_check(context, 1, context.get_input_size());- auto dim = context.mark_node(v0::Constant::create(element::i32, Shape{}, {0}));int64_t axis = 0;-std::deque<Output<Node>> list_elems;auto num_elements = context.get_input_size();if (!context.get_input_type(num_elements - 1).is<type::List>()) {axis = context.const_input<int64_t>(num_elements - 1);- dim = context.mark_node(v0::Constant::create(element::i32, Shape{}, {axis}));- num_elements -= 1;}- OutputVector stack_inputs;- for (size_t i = 0; i < num_elements; i++) {- stack_inputs.push_back(context.get_input(static_cast<int>(i)));- }+ auto dim = context.mark_node(v0::Constant::create(element::i32, Shape{}, {axis}));++ list_elems = get_list_as_outputs(context.get_input(0));++ OutputVector stack_inputs(list_elems.begin(), list_elems.end());// returns the u4 constant if the stack operation is a part of the decompression patternif (const auto& u4_const = u4_compression_stack(stack_inputs, axis))return {u4_const};+ num_elements = list_elems.size();+ list_elems.clear();for (size_t i = 0; i < num_elements; i++) {auto stack_input = context.mark_node(std::make_shared<v0::Unsqueeze>(stack_inputs[i], dim));list_elems.push_back(stack_input);diff --git a/tests/layer_tests/pytorch_tests/test_stack.py b/tests/layer_tests/pytorch_tests/test_stack.pyindex 04d1808063c..293da4ebc22 100644--- a/tests/layer_tests/pytorch_tests/test_stack.py+++ b/tests/layer_tests/pytorch_tests/test_stack.py@@ -11,7 +11,7 @@ class TestStack2D(PytorchLayerTest):def _prepare_input(self):return self.input_tensors- def create_model(self, dim):+ def create_model(self, dim=None):import torchclass aten_stack(torch.nn.Module):@@ -21,6 +21,8 @@ class TestStack2D(PytorchLayerTest):def forward(self, x, y):inputs = [x, y]+ if self.dim is None:+ return torch.stack(inputs)return torch.stack(inputs, self.dim)ref_net = None@@ -34,11 +36,12 @@ class TestStack2D(PytorchLayerTest):[8, 1, 1, 9]])@pytest.mark.parametrize("dim", ([- 0, 1, 2,+ 0, 1, 2, None]))@pytest.mark.nightly@pytest.mark.precommit@pytest.mark.precommit_torch_export+ @pytest.mark.precommit_fx_backenddef test_stack2D(self, input_shape, dim, ie_device, precision, ir_version):self.input_tensors = [np.random.randn(*input_shape).astype(np.float32),@@ -61,6 +64,8 @@ class TestStack3D(PytorchLayerTest):def forward(self, x, y, z):inputs = [x, y, z]+ if self.dim is None:+ return torch.stack(inputs)return torch.stack(inputs, self.dim)ref_net = None@@ -79,6 +84,7 @@ class TestStack3D(PytorchLayerTest):@pytest.mark.nightly@pytest.mark.precommit@pytest.mark.precommit_torch_export+ @pytest.mark.precommit_fx_backenddef test_stack3D(self, input_shape, dim, ie_device, precision, ir_version):self.input_tensors = [np.random.randn(*input_shape).astype(np.float32),