Skip to content

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

[PyTorch] Split requirements for model tests (#34076)

Maxim Vafin0eee1e7ed035
diff --git a/.github/workflows/job_pytorch_models_tests.yml b/.github/workflows/job_pytorch_models_tests.yml
index f4d1db5c568..3b3575d5e43 100644
--- a/.github/workflows/job_pytorch_models_tests.yml
+++ b/.github/workflows/job_pytorch_models_tests.yml
@@ -95,9 +95,12 @@ jobs:
wheels-dir-path: ${{ env.INSTALL_DIR }}
wheels-to-install: 'openvino openvino_tokenizers'
- - name: Install PyTorch tests requirements
+ - name: Install PyTorch tests requirements and requirements for timm/tv tests
run: |
- python3 -m pip install -r ${INSTALL_TEST_DIR}/requirements_pytorch
+ python3 -m pip install -r ${INSTALL_TEST_DIR}/requirements_pytorch \
+ -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/timm.txt \
+ -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/edsr.txt \
+ -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/torchvision.txt
env:
CPLUS_INCLUDE_PATH: ${{ env.Python_ROOT_DIR }}/include/python${{ env.PYTHON_VERSION }}
@@ -111,16 +114,72 @@ jobs:
TEST_DEVICE: CPU
OP_REPORT_FILE: ${{ env.INSTALL_TEST_DIR }}/TEST-torch_unsupported_ops.log
+ - name: Install deps for HF Transformers/LLM and other model tests
+ if: ${{ inputs.model_scope == 'precommit' || inputs.model_scope == 'nightly_scope2' }}
+ run: |
+ python3 -m pip install \
+ -r ${INSTALL_TEST_DIR}/requirements_pytorch \
+ -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/hf_transformers.txt \
+ -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/easyocr.txt \
+ -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/gfpgan.txt \
+ -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/tpsmm.txt
+
- name: PyTorch Models Tests Not Timm or Torchvision
if: ${{ inputs.model_scope == 'precommit' || inputs.model_scope == 'nightly_scope2' }}
run: |
export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
- python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-torch_model_"${TYPE}"_tests.html --self-contained-html -v -k "not (TestTimmConvertModel or TestTorchHubConvertModel or TestEdsrConvertModel)"
+ python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-torch_model_"${TYPE}"_tests.html --self-contained-html -v -k "not (TestTimmConvertModel or TestTorchHubConvertModel or TestEdsrConvertModel or TestLLMModel or TestDetectron2ConvertModel or TestTorchbenchmarkConvertModel)"
+ env:
+ TYPE: ${{ inputs.model_scope == 'precommit' && 'precommit' || 'nightly' }}
+ TEST_DEVICE: CPU
+ OP_REPORT_FILE: ${{ env.INSTALL_TEST_DIR }}/TEST-torch_unsupported_ops.log
+
+ - name: Install deps for LLM model tests
+ if: ${{ inputs.model_scope == 'precommit' || inputs.model_scope == 'nightly_scope2' }}
+ run: |
+ python3 -m pip install \
+ -r ${INSTALL_TEST_DIR}/requirements_pytorch \
+ -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/llm.txt
+
+ - name: PyTorch LLM Model Tests
+ if: ${{ inputs.model_scope == 'precommit' || inputs.model_scope == 'nightly_scope2' }}
+ run: |
+ export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
+ python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/test_llm.py -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-torch_model_llm_"${TYPE}"_tests.html --self-contained-html -v
env:
TYPE: ${{ inputs.model_scope == 'precommit' && 'precommit' || 'nightly' }}
TEST_DEVICE: CPU
OP_REPORT_FILE: ${{ env.INSTALL_TEST_DIR }}/TEST-torch_unsupported_ops.log
+ # Detectron2 and Torchbench install packages at runtime via subprocess,
+ # so they run after model tests and before transformation tests to avoid
+ # polluting the environment for other model tests.
+ - name: PyTorch Detectron2 Tests
+ if: ${{ inputs.model_scope == 'precommit' || inputs.model_scope == 'nightly_scope2' }}
+ run: |
+ export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
+ python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/test_detectron2.py -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-torch_model_detectron2_"${TYPE}"_tests.html --self-contained-html -v
+ env:
+ TYPE: ${{ inputs.model_scope == 'precommit' && 'precommit' || 'nightly' }}
+ TEST_DEVICE: CPU
+ OP_REPORT_FILE: ${{ env.INSTALL_TEST_DIR }}/TEST-torch_unsupported_ops.log
+
+ - name: PyTorch Torchbench Tests
+ if: ${{ inputs.model_scope == 'nightly_scope2' }}
+ run: |
+ export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
+ python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/test_torchbench.py -m nightly --html=${INSTALL_TEST_DIR}/TEST-torch_model_torchbench_nightly_tests.html --self-contained-html -v
+ env:
+ TEST_DEVICE: CPU
+ OP_REPORT_FILE: ${{ env.INSTALL_TEST_DIR }}/TEST-torch_unsupported_ops.log
+
+ - name: Install deps for transformation tests
+ if: ${{ inputs.model_scope == 'precommit' }}
+ run: |
+ python3 -m pip install \
+ -r ${INSTALL_TEST_DIR}/requirements_pytorch \
+ -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/optimum_intel.txt
+
- name: PagedAttention Test
if: ${{ inputs.model_scope == 'precommit' }}
run: |
@@ -139,10 +198,9 @@ jobs:
- name: TorchFX GPTQ Pattern Test
if: ${{ inputs.model_scope == 'precommit' }}
- # install torch 2.3.1 as newer is not yet supported by openvino backend
run: |
export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
- python3 -m pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --upgrade --index-url https://download.pytorch.org/whl/cpu
+ python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/compile_gptq.txt
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/transformation_tests/test_gptq_torchfx_transformations.py -m precommit --html=${INSTALL_TEST_DIR}/TEST-torch_gptqpattern_tests.html --self-contained-html -v --tb=short
env:
TEST_DEVICE: CPU
@@ -151,7 +209,7 @@ jobs:
if: ${{ inputs.model_scope == 'precommit' }}
run: |
export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
- python3 -m pip install optimum-intel==1.25.2 transformers==4.53.3 --upgrade
+ python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/moe.txt
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/transformation_tests/test_moe_transformation.py -m precommit --html=${INSTALL_TEST_DIR}/TEST-torch_moe_tests.html --self-contained-html -vvv -s --tb=short -n 2
env:
TEST_DEVICE: CPU
@@ -160,7 +218,9 @@ jobs:
if: ${{ inputs.model_scope == 'precommit' }}
run: |
export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
- python3 -m pip install -r ${INSTALL_TEST_DIR}/requirements_rope.txt
+ python3 -m pip install \
+ -r ${INSTALL_TEST_DIR}/requirements_pytorch \
+ -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/rope.txt
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/transformation_tests/test_transformations.py -m precommit --html=${INSTALL_TEST_DIR}/TEST-torch_rope_tests.html --self-contained-html -v --tb=short -n 2
env:
TEST_DEVICE: CPU
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index a6af01d0657..6eccbd6bdcb 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -8,5 +8,5 @@ add_subdirectory(samples_tests)
add_subdirectory(e2e_tests)
add_subdirectory(memory_tests)
-install(FILES requirements_pytorch requirements_tensorflow requirements_onnx requirements_jax requirements_rope.txt
+install(FILES requirements_pytorch requirements_tensorflow requirements_onnx requirements_jax
DESTINATION tests COMPONENT tests EXCLUDE_FROM_ALL)
diff --git a/tests/layer_tests/pytorch_tests/test_repeat.py b/tests/layer_tests/pytorch_tests/test_repeat.py
index 730ea1aa348..83db6c13bf3 100644
--- a/tests/layer_tests/pytorch_tests/test_repeat.py
+++ b/tests/layer_tests/pytorch_tests/test_repeat.py
@@ -59,22 +59,26 @@ class TestRepeatList(PytorchLayerTest):
kwargs_to_prepare_input={"repeats_shape": repeats}, fx_kind="aten.repeat.default")
-class TestRepeatFromFlanT5(PytorchLayerTest):
+class TestRepeatExtendedMask(PytorchLayerTest):
def _prepare_input(self):
return (self.random.randn(1, 15),)
def create_model(self):
import torch
- from transformers.modeling_utils import ModuleUtilsMixin
class aten_repeat(torch.nn.Module):
def forward(self, x):
- return ModuleUtilsMixin.create_extended_attention_mask_for_decoder(x.size(), x)
+ batch_size, seq_length = x.size()
+ seq_ids = torch.arange(seq_length, device=x.device)
+ causal_mask = seq_ids[None, None, :].repeat(batch_size, seq_length, 1) <= seq_ids[None, :, None]
+ causal_mask = causal_mask.to(x.dtype)
+ extended_attention_mask = causal_mask[:, None, :, :] * x[:, None, None, :]
+ return extended_attention_mask
return aten_repeat(), "aten::repeat"
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_fx_backend
- def test_repeat_t5(self, ie_device, precision, ir_version):
+ def test_repeat_extended_mask(self, ie_device, precision, ir_version):
self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True, use_convert_model=True)
diff --git a/tests/model_hub_tests/pytorch/envs/compile_gptq.txt b/tests/model_hub_tests/pytorch/envs/compile_gptq.txt
new file mode 100644
index 00000000000..a511518d312
--- /dev/null
+++ b/tests/model_hub_tests/pytorch/envs/compile_gptq.txt
@@ -0,0 +1,11 @@
+# Dependencies for test_gptq_torchfx_transformations.py
+# Requires older torch (2.3.x) — newer is not yet supported by openvino backend
+# Only GPTQ-related packages — no autoawq/triton/peft which conflict with torch 2.3.x
+--extra-index-url https://download.pytorch.org/whl/cpu
+torch==2.3.1
+torchvision==0.18.1
+torchaudio==2.3.1
+transformers==4.47.1
+huggingface-hub==0.25.2
+auto-gptq==0.7.1; platform_system == "Linux" and platform_machine == "x86_64" and python_version < "3.12"
+optimum==1.24.0; python_version < "3.12"
diff --git a/tests/model_hub_tests/pytorch/envs/easyocr.txt b/tests/model_hub_tests/pytorch/envs/easyocr.txt
new file mode 100644
index 00000000000..3732b3d811a
--- /dev/null
+++ b/tests/model_hub_tests/pytorch/envs/easyocr.txt
@@ -0,0 +1,2 @@
+# Extra dependencies for test_easyocr.py
+easyocr==1.7.2
diff --git a/tests/model_hub_tests/pytorch/envs/edsr.txt b/tests/model_hub_tests/pytorch/envs/edsr.txt
new file mode 100644
index 00000000000..d50412bc715
--- /dev/null
+++ b/tests/model_hub_tests/pytorch/envs/edsr.txt
@@ -0,0 +1,3 @@
+# Extra dependencies for test_edsr.py
+super-image==0.2.0
+requests==2.31.0
diff --git a/tests/model_hub_tests/pytorch/envs/gfpgan.txt b/tests/model_hub_tests/pytorch/envs/gfpgan.txt
new file mode 100644
index 00000000000..e5cb9976303
--- /dev/null
+++ b/tests/model_hub_tests/pytorch/envs/gfpgan.txt
@@ -0,0 +1,3 @@
+# Extra dependencies for test_gfpgan.py
+basicsr==1.4.2; python_version < "3.12"
+facexlib==0.3.0; python_version < "3.12"
diff --git a/tests/model_hub_tests/pytorch/envs/hf_transformers.txt b/tests/model_hub_tests/pytorch/envs/hf_transformers.txt
new file mode 100644
index 00000000000..cad7ef99785
--- /dev/null
+++ b/tests/model_hub_tests/pytorch/envs/hf_transformers.txt
@@ -0,0 +1,24 @@
+# Extra dependencies for test_hf_transformers.py and test_llm.py
+# These are common model-hub deps not needed by layer tests
+# before updating transformers version, make sure no tests (esp. sdpa2pa) are failing
+transformers==4.47.1
+datasets==3.0.1
+huggingface-hub==0.25.2
+hf_transfer==0.1.9
+sentencepiece==0.2.1
+sacremoses==0.1.1
+soundfile==0.12.1
+pandas==2.2.3
+av==13.0.0
+
+# requirements for specific HF models
+# - hf-tiny-model-private/tiny-random-RoFormerForCausalLM
+rjieba==0.1.11
+# - katuni4ka/tiny-random-qwen
+# - katuni4ka/tiny-random-internlm2
+transformers_stream_generator==0.0.5
+einops==0.8.0
+
+# librosa/pyctcdecode needed internally by some HF audio models
+librosa==0.10.2; python_version < "3.12"
+pyctcdecode==0.5.0; python_version < "3.12"
diff --git a/tests/model_hub_tests/pytorch/envs/llm.txt b/tests/model_hub_tests/pytorch/envs/llm.txt
new file mode 100644
index 00000000000..d9a81360893
--- /dev/null
+++ b/tests/model_hub_tests/pytorch/envs/llm.txt
@@ -0,0 +1,12 @@
+# Extra dependencies for test_llm.py (LLM quantized models)
+# These are NOT needed by test_hf_transformers.py
+
+# quantized model deps
+autoawq==0.2.7; platform_system == "Linux" and platform_machine == "x86_64"
+triton==3.5.1; platform_system == "Linux" and platform_machine == "x86_64"
+auto-gptq==0.7.1; platform_system == "Linux" and platform_machine == "x86_64" and python_version < "3.12"
+peft==0.17.1; platform_system == "Linux" and platform_machine == "x86_64" and python_version < "3.12"
+
+# optimum (required by transformers' GptqHfQuantizer for GPTQ model loading)
+# Pinned to 1.24.0 for compatibility with auto-gptq 0.7.1
+optimum==1.24.0; python_version < "3.12"
diff --git a/tests/model_hub_tests/pytorch/envs/moe.txt b/tests/model_hub_tests/pytorch/envs/moe.txt
new file mode 100644
index 00000000000..380d01b1fd0
--- /dev/null
+++ b/tests/model_hub_tests/pytorch/envs/moe.txt
@@ -0,0 +1,5 @@
+# MoE Fusion test environment overrides
+optimum-intel==1.25.2
+transformers==4.53.3
+# transformers 4.53 needs huggingface-hub>=0.30,<1.0; override hf_transformers pin
+huggingface-hub>=0.30.0,<1.0
diff --git a/tests/model_hub_tests/pytorch/envs/optimum_intel.txt b/tests/model_hub_tests/pytorch/envs/optimum_intel.txt
new file mode 100644
index 00000000000..bfafa8cb6e7
--- /dev/null
+++ b/tests/model_hub_tests/pytorch/envs/optimum_intel.txt
@@ -0,0 +1,3 @@
+# optimum-intel required by transformation tests (PA, StatefulToStateless, etc.)
+# Pinned to a known-working commit for compatibility.
+git+https://github.com/huggingface/optimum-intel.git@8ba536cd0a2bf93e9e88408b0048a7695db5be0b; python_version < "3.12"
diff --git a/tests/requirements_rope.txt b/tests/model_hub_tests/pytorch/envs/rope.txt
similarity index 100%
rename from tests/requirements_rope.txt
rename to tests/model_hub_tests/pytorch/envs/rope.txt
diff --git a/tests/model_hub_tests/pytorch/envs/timm.txt b/tests/model_hub_tests/pytorch/envs/timm.txt
new file mode 100644
index 00000000000..eb1601f1e6e
--- /dev/null
+++ b/tests/model_hub_tests/pytorch/envs/timm.txt
@@ -0,0 +1,2 @@
+# Extra dependencies for test_timm.py
+timm==1.0.24
diff --git a/tests/model_hub_tests/pytorch/envs/torchvision.txt b/tests/model_hub_tests/pytorch/envs/torchvision.txt
new file mode 100644
index 00000000000..9dcbfecf1ba
--- /dev/null
+++ b/tests/model_hub_tests/pytorch/envs/torchvision.txt
@@ -0,0 +1,3 @@
+# Extra dependencies for test_torchvision_models.py
+# PyAV is needed by torchvision for video operations (e.g. raft_small)
+av==13.0.0
diff --git a/tests/model_hub_tests/pytorch/envs/tpsmm.txt b/tests/model_hub_tests/pytorch/envs/tpsmm.txt
new file mode 100644
index 00000000000..913f07819dc
--- /dev/null
+++ b/tests/model_hub_tests/pytorch/envs/tpsmm.txt
@@ -0,0 +1,2 @@
+# Extra dependencies for test_tpsmm.py
+PyYAML==6.0.2
diff --git a/tests/model_hub_tests/pytorch/test_detectron2.py b/tests/model_hub_tests/pytorch/test_detectron2.py
index 4a5503c4027..6cdc4b26490 100644
--- a/tests/model_hub_tests/pytorch/test_detectron2.py
+++ b/tests/model_hub_tests/pytorch/test_detectron2.py
@@ -23,8 +23,9 @@ class TestDetectron2ConvertModel(TestTorchConvertModel):
self.image = Image.open(response.raw)
self.image = self.image.resize([640, 480])
- subprocess.run([sys.executable, "-m", "pip", "install",
- "git+https://github.com/facebookresearch/detectron2.git@017abbfa5f2c2a2afa045200c2af9ccf2fc6227f"])
+ subprocess.check_call([sys.executable, "-m", "pip", "install",
+ "setuptools<78", # detectron2 needs pkg_resources, removed in setuptools>=78
+ "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):
diff --git a/tests/model_hub_tests/pytorch/test_edsr.py b/tests/model_hub_tests/pytorch/test_edsr.py
index ecd2848b09b..d6d01c210c6 100644
--- a/tests/model_hub_tests/pytorch/test_edsr.py
+++ b/tests/model_hub_tests/pytorch/test_edsr.py
@@ -2,37 +2,16 @@
# SPDX-License-Identifier: Apache-2.0
import os
+import platform
import pytest
import random
import torch
-from huggingface_hub import snapshot_download
from models_hub_common.constants import hf_cache_dir, clean_hf_cache_dir
from models_hub_common.utils import cleanup_dir
from torch_utils import TestTorchConvertModel
-from super_image import ImageLoader, EdsrModel, MsrnModel, A2nModel, PanModel, CarnModel, DrlnModel, MdsrModel, HanModel, AwsrnModel, RnanModel, MasaModel, JiifModel, LiifModel, SmsrModel, RcanModel, DrnModel, PhysicssrModel, DdbpnModel
from PIL import Image
-import requests
-
-name_to_class = {
- "a2n": A2nModel,
- "awsrn-bam": AwsrnModel,
- "carn": CarnModel,
- "carn-bam": CarnModel,
- "drln": DrlnModel,
- "drln-bam": DrlnModel,
- "edsr": EdsrModel,
- "edsr-base": EdsrModel,
- "msrn": MsrnModel,
- "mdsr": MdsrModel,
- "msrn-bam": MsrnModel,
- "mdsr-bam": MdsrModel,
- "pan": PanModel,
- "pan-bam": PanModel,
- "rcan-bam": RcanModel,
- "han": HanModel,
-}
# To make tests reproducible we seed the random generator
torch.manual_seed(0)
@@ -40,14 +19,38 @@ torch.manual_seed(0)
class TestEdsrConvertModel(TestTorchConvertModel):
def load_model(self, model_name, model_link):
- # image link from https://github.com/eugenesiow/super-image
- url = 'https://paperswithcode.com/media/datasets/Set5-0000002728-07a9793f_zA3bDjj.jpg'
- image = Image.open(requests.get(url, stream=True).raw)
+ import requests
+ from super_image import (ImageLoader, EdsrModel, MsrnModel, A2nModel,
+ PanModel, CarnModel, DrlnModel, MdsrModel,
+ HanModel, AwsrnModel, RcanModel)
+
+ name_to_class = {
+ "a2n": A2nModel,
+ "awsrn-bam": AwsrnModel,
+ "carn": CarnModel,
+ "carn-bam": CarnModel,
+ "drln": DrlnModel,
+ "drln-bam": DrlnModel,
+ "edsr": EdsrModel,
+ "edsr-base": EdsrModel,
+ "msrn": MsrnModel,
+ "mdsr": MdsrModel,
+ "msrn-bam": MsrnModel,
+ "mdsr-bam": MdsrModel,
+ "pan": PanModel,
+ "pan-bam": PanModel,
+ "rcan-bam": RcanModel,
+ "han": HanModel,
+ }
+
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg"
+ response = requests.get(url, stream=True)
+ response.raise_for_status()
+ image = Image.open(response.raw)
assert model_name in name_to_class, "Unexpected model name"
print(f"scale: {self.scale}")
- model_cached = snapshot_download(f'eugenesiow/{model_name}') # required to avoid HF rate limits
model = name_to_class[model_name].from_pretrained(
- model_cached, scale=self.scale)
+ f'eugenesiow/{model_name}', scale=self.scale)
inputs = ImageLoader.load_image(image)
self.example = (torch.randn_like(inputs),)
self.inputs = (inputs,)
@@ -59,7 +62,10 @@ class TestEdsrConvertModel(TestTorchConvertModel):
cleanup_dir(hf_cache_dir)
super().teardown_method()
- @pytest.mark.skip(reason="CVS-171175")
+ @pytest.mark.skipif(
+ condition=platform.machine() in ("arm", "armv7l", "aarch64", "arm64", "ARM64"),
+ reason="Not supported on ARM",
+ )
@pytest.mark.parametrize("name", ["edsr"])
@pytest.mark.precommit
def test_convert_model_precommit(self, name, ie_device):
diff --git a/tests/model_hub_tests/pytorch/test_hf_transformers.py b/tests/model_hub_tests/pytorch/test_hf_transformers.py
index 4c559833af5..06f584ee4bc 100644
--- a/tests/model_hub_tests/pytorch/test_hf_transformers.py
+++ b/tests/model_hub_tests/pytorch/test_hf_transformers.py
@@ -4,21 +4,9 @@
import os
import platform
-from datasets import Audio, load_dataset
-from huggingface_hub import hf_hub_download, model_info, snapshot_download
from PIL import Image
import pytest
import torch
-import transformers
-from transformers import (
- AutoConfig, AutoFeatureExtractor, AutoImageProcessor, AutoModel,
- AutoModelForTextToWaveform, AutoProcessor, AutoTokenizer,
- BlipForConditionalGeneration, BlipProcessor, CLIPFeatureExtractor,
- FlavaImageModel, LayoutLMv2Processor, Pix2StructForConditionalGeneration,
- RetriBertTokenizer, SpeechT5ForTextToSpeech, SpeechT5Processor,
- T5Tokenizer, ViTImageProcessor, VisionEncoderDecoderModel,
- VivitImageProcessor, XCLIPVisionModel
-)
from models_hub_common.constants import hf_cache_dir, clean_hf_cache_dir
from models_hub_common.utils import cleanup_dir, get_models_list, retry
@@ -60,6 +48,19 @@ class TestTransformersModel(TestTorchConvertModel):
@retry(10, exceptions=(OSError,), delay=5, exponential_backoff=True, backoff_multiplier=2, max_delay=300)
def load_model(self, name, type):
+ from datasets import Audio, load_dataset
+ from huggingface_hub import hf_hub_download, model_info, snapshot_download
+ import transformers
+ from transformers import (
+ AutoConfig, AutoFeatureExtractor, AutoImageProcessor, AutoModel,
+ AutoModelForTextToWaveform, AutoProcessor, AutoTokenizer,
+ BlipForConditionalGeneration, BlipProcessor, CLIPFeatureExtractor,
+ FlavaImageModel, LayoutLMv2Processor, Pix2StructForConditionalGeneration,
+ RetriBertTokenizer, SpeechT5ForTextToSpeech, SpeechT5Processor,
+ T5Tokenizer, ViTImageProcessor, VisionEncoderDecoderModel,
+ VivitImageProcessor, XCLIPVisionModel
+ )
+
name, _, name_suffix = name.partition(':')
model_cached = snapshot_download(name) # required to avoid HF rate limits
@@ -521,6 +522,10 @@ class TestTransformersModel(TestTorchConvertModel):
@staticmethod
def load_model_with_default_class(name, **kwargs):
+ import transformers
+ from huggingface_hub import model_info, snapshot_download
+ from transformers import AutoModel
+
model_cached = snapshot_download(name) # required to avoid HF rate limits
try:
mi = model_info(name)
diff --git a/tests/model_hub_tests/pytorch/test_llm.py b/tests/model_hub_tests/pytorch/test_llm.py
index eeca66b98b5..3621cfc6f0a 100644
--- a/tests/model_hub_tests/pytorch/test_llm.py
+++ b/tests/model_hub_tests/pytorch/test_llm.py
@@ -8,8 +8,6 @@ import numpy as np
import platform
import pytest
import torch
-from huggingface_hub import snapshot_download
-from transformers import AutoConfig, AutoTokenizer, AutoModelForCausalLM
from models_hub_common.utils import retry
from openvino.frontend.pytorch.patch_model import __make_16bit_traceable as patch
@@ -35,23 +33,30 @@ def patch_gptq():
torch.cuda.get_device_capability = lambda n: (9, 1)
try:
- from optimum.gptq import GPTQQuantizer
-
- orig_post_init_model = GPTQQuantizer.post_init_model
-
- def post_init_model(self, model):
- from auto_gptq import exllama_set_max_input_length
-
- class StoreAttr(object):
- pass
-
- model.quantize_config = StoreAttr()
- model.quantize_config.desc_act = self.desc_act
- if self.desc_act and not self.disable_exllama and self.max_input_length is not None:
- model = exllama_set_max_input_length(model, self.max_input_length)
+ # Patch at the transformers level to avoid GPU-only post_init_model
+ # from optimum.gptq. transformers' GptqHfQuantizer delegates to
+ # optimum_quantizer.post_init_model() which calls gptq_post_init
+ # (requires GPU). Replace with a CPU-safe stub.
+ from transformers.quantizers.quantizer_gptq import GptqHfQuantizer
+
+ orig_post_init_model = GptqHfQuantizer._process_model_after_weight_loading
+
+ def _process_model_after_weight_loading_cpu(self, model, **kwargs):
+ if self.pre_quantized:
+ class StoreAttr(object):
+ pass
+ model.quantize_config = StoreAttr()
+ oq = self.optimum_quantizer
+ model.quantize_config.desc_act = oq.desc_act
+ if oq.desc_act and not oq.disable_exllama and oq.max_input_length is not None:
+ try:
+ from auto_gptq import exllama_set_max_input_length
+ model = exllama_set_max_input_length(model, oq.max_input_length)
+ except ImportError:
+ pass
return model
- GPTQQuantizer.post_init_model = post_init_model
+ GptqHfQuantizer._process_model_after_weight_loading = _process_model_after_weight_loading_cpu
except ImportError:
pass
@@ -96,8 +101,8 @@ def patch_gptq():
def unpatch_gptq(orig_cuda_check, orig_post_init_model, orig_gemm_forward):
torch.cuda.is_available, torch.cuda.is_bf16_supported, torch.cuda.get_device_capability = orig_cuda_check
try:
- from optimum.gptq import GPTQQuantizer
- GPTQQuantizer.post_init_model = orig_post_init_model
+ from transformers.quantizers.quantizer_gptq import GptqHfQuantizer
+ GptqHfQuantizer._process_model_after_weight_loading = orig_post_init_model
except ImportError:
pass
try:
@@ -142,6 +147,9 @@ class TestLLMModel(TestTorchConvertModel):
@retry(3, exceptions=(OSError,), delay=1)
def load_model(self, name, type):
+ from huggingface_hub import snapshot_download
+ from transformers import AutoConfig, AutoTokenizer, AutoModelForCausalLM
+
model = None
example = None
model_cached = snapshot_download(name) # required to avoid HF rate limits
diff --git a/tests/requirements_pytorch b/tests/requirements_pytorch
index 060c46759f6..d9616859159 100644
--- a/tests/requirements_pytorch
+++ b/tests/requirements_pytorch
@@ -1,6 +1,9 @@
+# Base requirements shared by layer tests and model hub tests.
+# Model-hub-specific deps live in tests/model_hub_tests/pytorch/envs/*.txt
+# and are installed on top of this file via `pip install -r envs/<group>.txt`.
+
# test ovc with NumPy 2.x on Ubuntu 24 with default Python 3.12
# test against NumPy 1.x with older Python versions
-# optimum still requires numpy<2.0.0
numpy==1.26.4; python_version < "3.12"
numpy==2.1.1; python_version >= "3.12"
torch==2.9.0
@@ -8,53 +11,11 @@ torch==2.9.0
torchvision==0.24.0
torchaudio==2.9.0
-# before updating transformers version, make sure no tests (esp. sdpa2pa) are failing
-transformers==4.47.1
pytest==7.0.1; python_version < '3.10'
pytest==7.2.0; python_version >= '3.10'
pytest-html==4.2.0
pytest-xdist[psutil]==3.6.1
defusedxml==0.7.1
-
-autoawq==0.2.7; platform_system == "Linux" and platform_machine == "x86_64"
-# triton is a dependency of autoawq, newer versions lead to TorchFX test failures
-triton==3.5.1; platform_system == "Linux" and platform_machine == "x86_64"
-auto-gptq==0.7.1; platform_system == "Linux" and platform_machine == "x86_64" and python_version < "3.12"
-# peft is a dependency of auto-gptq, newer versions lead to gptq model loading failures
-peft==0.17.1; platform_system == "Linux" and platform_machine == "x86_64" and python_version < "3.12"
-av==13.0.0
-basicsr==1.4.2; python_version < "3.12"
-datasets==3.0.1
-easyocr==1.7.2
-facexlib==0.3.0; python_version < "3.12"
-librosa==0.10.2; python_version < "3.12"
packaging==24.1
-pandas==2.2.3
protobuf==5.28.3
-pyctcdecode==0.5.0; python_version < "3.12"
-sacremoses==0.1.1
-sentencepiece==0.2.1
-soundfile==0.12.1
-super-image==0.1.7; python_version < "3.12"
-timm==1.0.24
wheel==0.44.0
-PyYAML==6.0.2
-kornia==0.7.3
-super-image==0.1.7
-# huggingface-hub required for super-image
-huggingface-hub==0.25.2
-
-# For now, we decided to pin a specific working version of optimum-intel.
-# It will be discussed in the future how to manage versioning of the components properly.
-git+https://github.com/huggingface/optimum-intel.git@8ba536cd0a2bf93e9e88408b0048a7695db5be0b; python_version < "3.12"
-# set 'export HF_HUB_ENABLE_HF_TRANSFER=1' to benefits from hf_transfer
-hf_transfer==0.1.9
-
-# requirements for specific models
-# - hf-tiny-model-private/tiny-random-RoFormerForCausalLM
-rjieba==0.1.11
-
-# - katuni4ka/tiny-random-qwen
-# - katuni4ka/tiny-random-internlm2
-transformers_stream_generator==0.0.5
-einops==0.8.0