Skip to content

Commit 4cf2ae0

Browse files
authored
[PT FE]: fix segfault when resolving nested dict as model input (openvinotoolkit#24719)
### Details: - *item1* - *...* ### Tickets: - *ticket-id*
1 parent 000b9f7 commit 4cf2ae0

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/frontends/pytorch/src/transforms/dict_resolver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using namespace ov::op;
2121

2222
bool DictParameterResolver::run_on_model(const std::shared_ptr<Model>& model) {
2323
bool changed = false;
24-
const auto& parameters = model->get_parameters();
24+
const auto parameters = model->get_parameters();
2525
ParameterVector new_params;
2626

2727
for (const auto& p : parameters) {

tests/layer_tests/ovc_python_api_tests/test_pytorch.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,28 @@ def forward(self, x):
10161016
"compress_to_fp16": False}
10171017

10181018

1019+
def create_pytorch_module_with_nested_dict_input(tmp_dir):
1020+
class PTModel(torch.nn.Module):
1021+
def forward(self, a, b):
1022+
return a["1"] * a["2"] + b
1023+
1024+
net = PTModel()
1025+
a1 = ov.opset10.parameter(PartialShape([-1]), dtype=np.float32)
1026+
a2 = ov.opset10.parameter(PartialShape([-1]), dtype=np.float32)
1027+
b = ov.opset10.parameter(PartialShape([-1]), dtype=np.float32)
1028+
mul = ov.opset10.multiply(a1, a2)
1029+
add = ov.opset10.add(mul, b)
1030+
ref_model = Model([add], [a1, a2, b], "test")
1031+
return net, ref_model, {
1032+
"example_input": (
1033+
{
1034+
"1": torch.tensor([1, 2], dtype=torch.float32),
1035+
"2": torch.tensor([3, 4], dtype=torch.float32)
1036+
},
1037+
torch.tensor([5, 6], dtype=torch.float32)
1038+
)}
1039+
1040+
10191041
class TestMoConvertPyTorch(CommonMOConvertTest):
10201042
test_data = [
10211043
create_pytorch_nn_module_case1,
@@ -1067,7 +1089,8 @@ class TestMoConvertPyTorch(CommonMOConvertTest):
10671089
create_pytorch_module_with_nested_inputs5,
10681090
create_pytorch_module_with_nested_inputs6,
10691091
create_pytorch_module_with_nested_list_and_single_input,
1070-
create_pytorch_module_with_single_input_as_list
1092+
create_pytorch_module_with_single_input_as_list,
1093+
create_pytorch_module_with_nested_dict_input
10711094
]
10721095

10731096
@pytest.mark.parametrize("create_model", test_data)

0 commit comments

Comments
 (0)