Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[TESTS] Fix failing nightly pytorch model tests (#34684)

Maxim Vafinedde158ee4f4
diff --git a/src/frontends/pytorch/src/utils.cpp b/src/frontends/pytorch/src/utils.cpp
index f081c045eaf..c11f3912f25 100644
--- a/src/frontends/pytorch/src/utils.cpp
+++ b/src/frontends/pytorch/src/utils.cpp
@@ -680,7 +680,7 @@ std::deque<Output<Node>> get_list_as_outputs(const Output<Node>& start, bool uns
} else if (op_type == "aten::add") {
// Insert at beginning because we're walking backward through the chain.
// Elements from RHS list come before any elements appended after this add operation.
- auto&& rhs_list = get_list_as_outputs(fw_node->get_input_source_output(1));
+ auto&& rhs_list = get_list_as_outputs(fw_node->get_input_source_output(1), unsqueeze_for_concat);
res.insert(res.begin(), rhs_list.begin(), rhs_list.end());
} else {
break;
diff --git a/tests/model_hub_tests/pytorch/hf_transformers_models b/tests/model_hub_tests/pytorch/hf_transformers_models
index cc67f8d1929..602093344d6 100644
--- a/tests/model_hub_tests/pytorch/hf_transformers_models
+++ b/tests/model_hub_tests/pytorch/hf_transformers_models
@@ -87,7 +87,7 @@ hiera,namangarg110/hiera_base_224
hifigan,microsoft/speecht5_hifigan,xfail,Load error: The size of tensor a (100) must match the size of tensor b (80) at non-singleton dimension 1
hubert,facebook/hubert-large-ls960-ft
hybridbert,gokuls/bert_12_layer_model_v1
-ibert,DunnBC22/ibert-roberta-base-Abusive_Or_Threatening_Speech
+ibert,kssteven/ibert-roberta-base
idefics,HuggingFaceM4/tiny-random-idefics
imagegpt,openai/imagegpt-small
informer,huggingface/informer-tourism-monthly,xfail,Load error: mat1 and mat2 shapes cannot be multiplied
diff --git a/tests/model_hub_tests/pytorch/test_detectron2.py b/tests/model_hub_tests/pytorch/test_detectron2.py
index 6ac10caa870..4a5503c4027 100644
--- a/tests/model_hub_tests/pytorch/test_detectron2.py
+++ b/tests/model_hub_tests/pytorch/test_detectron2.py
@@ -7,7 +7,7 @@ import subprocess
import platform
import pytest
import torch
-from models_hub_common.utils import get_models_list, compare_two_tensors
+from models_hub_common.utils import get_models_list, compare_two_tensors, retry
from torch_utils import TestTorchConvertModel, process_pytest_marks
@@ -26,6 +26,7 @@ class TestDetectron2ConvertModel(TestTorchConvertModel):
subprocess.run([sys.executable, "-m", "pip", "install",
"git+https://github.com/facebookresearch/detectron2.git@017abbfa5f2c2a2afa045200c2af9ccf2fc6227f"])
+ @retry(3, exceptions=(OSError,), delay=10, exponential_backoff=True, backoff_multiplier=2, max_delay=120)
def load_model(self, model_name, model_link):
from detectron2 import model_zoo, export
from detectron2.modeling import build_model, PanopticFPN
diff --git a/tests/model_hub_tests/pytorch/test_hf_transformers.py b/tests/model_hub_tests/pytorch/test_hf_transformers.py
index 1fdad7905ec..4c559833af5 100644
--- a/tests/model_hub_tests/pytorch/test_hf_transformers.py
+++ b/tests/model_hub_tests/pytorch/test_hf_transformers.py
@@ -155,13 +155,13 @@ class TestTransformersModel(TestTorchConvertModel):
prompts = [[
"User: What is in this image?",
- "https://upload.wikimedia.org/wikipedia/commons/8/86/Id%C3%A9fix.JPG",
+ self.image,
"<end_of_utterance>",
"\nAssistant: This picture depicts Idefix, the dog of Obelix in Asterix and Obelix. Idefix is running on the ground.<end_of_utterance>",
"\nUser:",
- "https://static.wikia.nocookie.net/asterix/images/2/25/R22b.gif/revision/latest?cb=20110815073052",
+ self.image,
"And who is that?<end_of_utterance>",
"\nAssistant:",
@@ -297,6 +297,8 @@ class TestTransformersModel(TestTorchConvertModel):
inputs = processor(
text=prompt, images=self.image, return_tensors="pt")
example = dict(inputs)
+ if 'pixel_values' in example and example['pixel_values'].ndim == 5:
+ example['pixel_values'] = example['pixel_values'].squeeze(1)
elif 'vitmatte' in mi.tags:
processor = AutoImageProcessor.from_pretrained(model_cached)
filepath = hf_hub_download(repo_id="hf-internal-testing/image-matting-fixtures",
@@ -446,6 +448,12 @@ class TestTransformersModel(TestTorchConvertModel):
example = dict(encoded_input)
except:
pass
+ if model is None and "blip_2_qformer" in mi.tags:
+ from transformers import Blip2QFormerConfig, Blip2QFormerModel
+ qformer_config = Blip2QFormerConfig.from_pretrained(model_cached)
+ qformer_config.torchscript = True
+ model = Blip2QFormerModel.from_pretrained(
+ model_cached, config=qformer_config)
if model is None:
model = self.load_model_with_default_class(name, **model_kwargs)
if hasattr(model, "set_default_language"):
@@ -488,6 +496,10 @@ class TestTransformersModel(TestTorchConvertModel):
if "hybridbert" in mi.tags and "token_type_ids" in example:
del example["token_type_ids"]
+ if "instructblip" in mi.tags:
+ # The processor does not insert image_token_index into input_ids,
+ # so force the concatenation path in the model's forward method.
+ model.config.image_token_index = None
self.example = example
if "vit_mae" in mi.tags:
# vit-mae by default will generate random noise
diff --git a/tests/model_hub_tests/pytorch/test_torchbench.py b/tests/model_hub_tests/pytorch/test_torchbench.py
index 016b0c86cbe..86700d817e1 100644
--- a/tests/model_hub_tests/pytorch/test_torchbench.py
+++ b/tests/model_hub_tests/pytorch/test_torchbench.py
@@ -30,7 +30,7 @@ class TestTorchbenchmarkConvertModel(TestTorchConvertModel):
os.system(
f"git clone https://github.com/pytorch/benchmark.git {self.repo_dir.name}")
subprocess.check_call(
- ["git", "checkout", "dbc109791dbb0dfb58775a5dc284fc2c3996cb30"], cwd=self.repo_dir.name)
+ ["git", "checkout", "364420aeca07d9519840a5b6e771035e4dff9d72"], cwd=self.repo_dir.name)
def load_model(self, model_name, model_link):
subprocess.check_call([sys.executable, "install.py"] + [model_name], cwd=self.repo_dir.name)
@@ -39,7 +39,7 @@ class TestTorchbenchmarkConvertModel(TestTorchConvertModel):
try:
model_cls = load_model_by_name(
model_name)("eval", "cpu", jit=False)
- except:
+ except TypeError:
model_cls = load_model_by_name(model_name)("eval", "cpu")
model, self.example = model_cls.get_module()
self.inputs = self.example
diff --git a/tests/model_hub_tests/pytorch/torchbench_models b/tests/model_hub_tests/pytorch/torchbench_models
index 060faa6d99b..ece3a8205f7 100644
--- a/tests/model_hub_tests/pytorch/torchbench_models
+++ b/tests/model_hub_tests/pytorch/torchbench_models
@@ -80,8 +80,8 @@ sam,None,xfail,Unexpected type of example_input
soft_actor_critic,None,skip,Tracer cannot infer type of SquashedNormal
speech_transformer,None
#squeezenet1_1,None - Already tested by torchvision tests
-stable_diffusion_text_encoder,None
-stable_diffusion_unet,None
+stable_diffusion_text_encoder,None,skip,Failed to install in torchbench
+stable_diffusion_unet,None,skip,Failed to install in torchbench
tacotron2,None,skip,Can't be loaded without CUDA
#timm_efficientdet,None - Already tested by timm tests
#timm_efficientnet,None - Already tested by timm tests