diff --git a/tests/layer_tests/py_frontend_tests/test_torchvision_preprocessor.py b/tests/layer_tests/py_frontend_tests/test_torchvision_preprocessor.py index 4500e76e587cda..bfaa782ab59d7d 100644 --- a/tests/layer_tests/py_frontend_tests/test_torchvision_preprocessor.py +++ b/tests/layer_tests/py_frontend_tests/test_torchvision_preprocessor.py @@ -30,6 +30,23 @@ def forward(self, data): def _infer_pipelines(test_input, preprocess_pipeline, input_channels=3): + retries = 0 + max_retries = 3 + while retries < max_retries: + try: + return _infer_pipelines_impl(test_input, preprocess_pipeline, input_channels) + except RuntimeError as e: + if "builtin cannot be used as a value" in e: + # This is a potentially sporadic issue + print(f"An error occurred: {e}. Retrying...") + retries += 1 + else: + raise + else: + print("Max retries reached. Function execution failed.") + + +def _infer_pipelines_impl(test_input, preprocess_pipeline, input_channels=3): torch_model = Convnet(input_channels) ov_model = convert_model(torch_model) core = Core() diff --git a/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py b/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py index 031bd419e46c7a..2481f1d65ef8fb 100644 --- a/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py +++ b/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py @@ -67,8 +67,27 @@ def use_torch_export(): return torch_compile_env == "EXPORT" return False + def _test(self, model, ref_net, kind, ie_device, precision, ir_version, infer_timeout=60, dynamic_shapes=True, **kwargs): + retries = 0 + max_retries = 3 + while retries < max_retries: + try: + return self._test_impl(model, ref_net, kind, ie_device, precision, ir_version, infer_timeout, dynamic_shapes, **kwargs) + except RuntimeError as e: + if "builtin cannot be used as a value" in e: + # This is a potentially sporadic issue + print(f"An error occurred: {e}. Retrying...") + retries += 1 + else: + raise + else: + print("Max retries reached. Function execution failed.") + + + def _test_impl(self, model, ref_net, kind, ie_device, precision, ir_version, infer_timeout=60, dynamic_shapes=True, + **kwargs): """ :param enabled_transforms/disabled_transforms: string with idxs of transforms that should be enabled/disabled. Example: "transform_1,transform_2"