Skip to content

Commit

Permalink
[PT FE]: fix segfault when resolving nested dict as model input (#24728)
Browse files Browse the repository at this point in the history
### Details:
 - *item1*
 - *...*

### Tickets:
 - *CVS-142477*
  • Loading branch information
eaidova committed May 28, 2024
1 parent 185783b commit 9c59aeb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/frontends/pytorch/src/transforms/dict_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using namespace ov::op;

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

for (const auto& p : parameters) {
Expand Down
24 changes: 23 additions & 1 deletion tests/layer_tests/ovc_python_api_tests/test_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,27 @@ def forward(self, x):
"compress_to_fp16": False}


def create_pytorch_module_with_nested_dict_input(tmp_dir):
class PTModel(torch.nn.Module):
def forward(self, a, b):
return a["1"] * a["2"] + b

net = PTModel()
a1 = ov.opset10.parameter(PartialShape([-1]), dtype=np.float32)
a2 = ov.opset10.parameter(PartialShape([-1]), dtype=np.float32)
b = ov.opset10.parameter(PartialShape([-1]), dtype=np.float32)
mul = ov.opset10.multiply(a1, a2)
add = ov.opset10.add(mul, b)
ref_model = Model([add], [a1, a2, b], "test")
return net, ref_model, {
"example_input": (
{
"1": torch.tensor([1, 2], dtype=torch.float32),
"2": torch.tensor([3, 4], dtype=torch.float32)
},
torch.tensor([5, 6], dtype=torch.float32)
)}

class TestMoConvertPyTorch(CommonMOConvertTest):
test_data = [
create_pytorch_nn_module_case1,
Expand Down Expand Up @@ -1067,7 +1088,8 @@ class TestMoConvertPyTorch(CommonMOConvertTest):
create_pytorch_module_with_nested_inputs5,
create_pytorch_module_with_nested_inputs6,
create_pytorch_module_with_nested_list_and_single_input,
create_pytorch_module_with_single_input_as_list
create_pytorch_module_with_single_input_as_list,
create_pytorch_module_with_nested_dict_input
]

@pytest.mark.parametrize("create_model", test_data)
Expand Down

0 comments on commit 9c59aeb

Please sign in to comment.