Skip to content

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

[PyTorch] Run transformation tests that need other transformers versions in separate CI steps (#38632)

Evgeny Kotov2520ba4d5ecd
diff --git a/.github/workflows/job_gpu_rope_tests.yml b/.github/workflows/job_gpu_rope_tests.yml
index 8fd1c075de1..6f3c3f9e95a 100644
--- a/.github/workflows/job_gpu_rope_tests.yml
+++ b/.github/workflows/job_gpu_rope_tests.yml
@@ -154,14 +154,11 @@ jobs:
- name: Install RoPE test requirements
run: |
- # rope_gpu.txt holds GPU-only deps (diffusers + transformers bump);
- # kept out of the shared rope.txt because the CPU RoPE flow installs
- # that file too and diffusers breaks optimum-intel there — see
- # rope_gpu.txt. All three resolved in one pip pass so transformers is
- # not installed then re-installed (faster, single consistent resolve).
+ # rope_gpu.txt holds GPU-only deps (diffusers for the Flux test).
+ # All three resolved in one pip pass (single consistent resolve).
python3 -m pip install \
-r ${INSTALL_TEST_DIR}/requirements_pytorch \
- -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/rope.txt \
+ -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/transformations_actual.txt \
-r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/rope_gpu.txt
- name: OpenVINO GPU RoPE Tests
@@ -181,7 +178,7 @@ jobs:
"
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/transformation_tests/test_transformations.py \
- -m precommit \
+ -m "precommit and not transformations_legacy" \
--html=${INSTALL_TEST_DIR}/TEST-gpu_rope_tests.html \
--self-contained-html -v --tb=short -n 2
diff --git a/.github/workflows/job_pytorch_models_tests.yml b/.github/workflows/job_pytorch_models_tests.yml
index 7ab99052a27..5a945aef363 100644
--- a/.github/workflows/job_pytorch_models_tests.yml
+++ b/.github/workflows/job_pytorch_models_tests.yml
@@ -190,13 +190,13 @@ jobs:
python3 -m pip uninstall -y gptqmodel triton kernels torchao 2>/dev/null || true
python3 -m pip install \
-r ${INSTALL_TEST_DIR}/requirements_pytorch \
- -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/optimum_intel.txt
+ -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/transformations_actual.txt
- name: PagedAttention Test
if: ${{ inputs.model_scope == 'precommit' }}
run: |
export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
- python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/transformation_tests/test_pa_transformation.py -m precommit --html=${INSTALL_TEST_DIR}/TEST-torch_pagedattention_tests.html --self-contained-html -vvv -s --tb=short -n 2
+ python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/transformation_tests/test_pa_transformation.py -m "precommit and not transformations_legacy" --html=${INSTALL_TEST_DIR}/TEST-torch_pagedattention_tests.html --self-contained-html -vvv -s --tb=short -n 2
env:
TEST_DEVICE: CPU
@@ -208,6 +208,20 @@ jobs:
env:
TEST_DEVICE: CPU
+ - name: PagedAttention and RoPE Tests (legacy transformers)
+ if: ${{ inputs.model_scope == 'precommit' }}
+ run: |
+ export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
+ # nncf 3.x pulled by optimum-intel 2.x breaks the import of optimum-intel 1.x; pinning nncf 2.x does not
+ # help: it takes the model_hub_tests/tensorflow directory on PYTHONPATH for TensorFlow and fails to import
+ python3 -m pip uninstall -y nncf
+ python3 -m pip install \
+ -r ${INSTALL_TEST_DIR}/requirements_pytorch \
+ -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/transformations_legacy.txt
+ python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/transformation_tests/test_pa_transformation.py ${MODEL_HUB_TESTS_INSTALL_DIR}/transformation_tests/test_transformations.py -m "precommit and transformations_legacy" --html=${INSTALL_TEST_DIR}/TEST-torch_transformations_legacy_tests.html --self-contained-html -vvv -s --tb=short -n 2
+ env:
+ TEST_DEVICE: CPU
+
- name: TorchFX GPTQ Pattern Test
if: ${{ inputs.model_scope == 'precommit' }}
run: |
@@ -243,8 +257,8 @@ jobs:
export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
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
+ -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/envs/transformations_actual.txt
+ python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/transformation_tests/test_transformations.py -m "precommit and not transformations_legacy" --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/model_hub_tests/pytest.ini b/tests/model_hub_tests/pytest.ini
index b68f005310c..9c59e179c20 100644
--- a/tests/model_hub_tests/pytest.ini
+++ b/tests/model_hub_tests/pytest.ini
@@ -2,3 +2,4 @@
markers =
nightly
precommit
+ transformations_legacy: needs pytorch/envs/transformations_legacy.txt (older transformers/optimum)
diff --git a/tests/model_hub_tests/pytorch/envs/optimum_intel.txt b/tests/model_hub_tests/pytorch/envs/optimum_intel.txt
deleted file mode 100644
index d71a32e330c..00000000000
--- a/tests/model_hub_tests/pytorch/envs/optimum_intel.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-# optimum-intel required by transformation tests (PA, StatefulToStateless, etc.)
-# Pinned to a known-working commit for compatibility.
-# optimum-intel@8ba536cd requires transformers>=4.36,<4.52
-transformers==4.51.3
-optimum==1.25.0; python_version < "3.12"
-auto-gptq==0.7.1; platform_system == "Linux" and platform_machine == "x86_64" and python_version < "3.12"
-autoawq==0.2.7; platform_system == "Linux" and platform_machine == "x86_64"
-git+https://github.com/huggingface/optimum-intel.git@8ba536cd0a2bf93e9e88408b0048a7695db5be0b; python_version < "3.12"
diff --git a/tests/model_hub_tests/pytorch/envs/rope.txt b/tests/model_hub_tests/pytorch/envs/rope.txt
deleted file mode 100644
index f8403cd583b..00000000000
--- a/tests/model_hub_tests/pytorch/envs/rope.txt
+++ /dev/null
@@ -1 +0,0 @@
-optimum-intel==1.27.0
diff --git a/tests/model_hub_tests/pytorch/envs/rope_gpu.txt b/tests/model_hub_tests/pytorch/envs/rope_gpu.txt
index 6f1f555d740..6acc5f48723 100644
--- a/tests/model_hub_tests/pytorch/envs/rope_gpu.txt
+++ b/tests/model_hub_tests/pytorch/envs/rope_gpu.txt
@@ -1,15 +1,4 @@
-# GPU-only RoPE test dependencies — installed IN ADDITION to rope.txt by the
-# iGPU RoPE flow (.github/workflows/job_gpu_rope_tests.yml). Kept out of the
-# shared rope.txt on purpose: that file is also installed by the CPU RoPE flow
-# (job_pytorch_models_tests.yml), and diffusers' mere presence breaks
-# optimum-intel's auto-pipeline import on the CPU/ARM64 transformers stack —
-# it failed all 41 CPU RoPE tests (CVS-182458, CI round 2). diffusers is only
-# needed for the Flux test, which is skipped on CPU
-# (test_transformations.py:run_flux_test).
-#
-# Explicit transformers bump: diffusers 0.34 registers the cogview4 pipeline,
-# whose module-level `from transformers import GlmModel` needs transformers>=4.49.
-# optimum-intel==1.27.0 admits >=4.45,<4.58 and the iGPU runner's setup-python
-# venv ships 4.45.1, so pip won't auto-upgrade — pin the window satisfying both.
+# GPU-only RoPE test dependencies, installed on top of transformations_actual.txt by the iGPU RoPE flow
+# (.github/workflows/job_gpu_rope_tests.yml). diffusers is only needed for the Flux test, which is skipped
+# on CPU (test_transformations.py:run_flux_test).
diffusers==0.34.0
-transformers>=4.49,<4.58
diff --git a/tests/model_hub_tests/pytorch/envs/transformations_actual.txt b/tests/model_hub_tests/pytorch/envs/transformations_actual.txt
new file mode 100644
index 00000000000..761398d8c91
--- /dev/null
+++ b/tests/model_hub_tests/pytorch/envs/transformations_actual.txt
@@ -0,0 +1,10 @@
+# Default stack for the transformation tests (PA, StatefulToStateless, RoPE): the latest optimum-intel and the
+# highest transformers it supports for most architectures (optimum-intel 2.2.0 caps llama & co. at 4.57.6).
+# Models that cannot run with it are marked `transformations_legacy` (see transformations_legacy.txt).
+optimum-intel==2.2.0
+transformers==4.57.6
+huggingface-hub>=0.34.0,<1.0
+# required by the remote code of tiny-random-baichuan2-13b
+accelerate==1.15.0
+# required by the remote code of tiny-random-internlm2
+einops==0.8.0
diff --git a/tests/model_hub_tests/pytorch/envs/transformations_legacy.txt b/tests/model_hub_tests/pytorch/envs/transformations_legacy.txt
new file mode 100644
index 00000000000..471393350f3
--- /dev/null
+++ b/tests/model_hub_tests/pytorch/envs/transformations_legacy.txt
@@ -0,0 +1,10 @@
+# Stack for the transformation tests marked `transformations_legacy`: the lowest transformers on which these
+# models still run. optimum-intel caps their architectures below transformers 4.57.6, and the auto-gptq/autoawq
+# quantized models need optimum 1.x / older transformers.
+transformers==4.51.3
+optimum-intel==1.24.0
+optimum==1.26.1
+auto-gptq==0.7.1; platform_system == "Linux" and platform_machine == "x86_64" and python_version < "3.12"
+autoawq==0.2.7; platform_system == "Linux" and platform_machine == "x86_64"
+# auto-gptq 0.7.1 imports peft.peft_model.PEFT_TYPE_TO_MODEL_MAPPING, removed in newer peft
+peft==0.18.1; platform_system == "Linux" and platform_machine == "x86_64" and python_version < "3.12"
diff --git a/tests/model_hub_tests/transformation_tests/env_marks.py b/tests/model_hub_tests/transformation_tests/env_marks.py
new file mode 100644
index 00000000000..7c36acdadcf
--- /dev/null
+++ b/tests/model_hub_tests/transformation_tests/env_marks.py
@@ -0,0 +1,44 @@
+# Copyright (C) 2018-2026 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+# Transformation-test models that cannot run with pytorch/envs/transformations_actual.txt.
+# They are marked `transformations_legacy`; job_pytorch_models_tests.yml installs
+# pytorch/envs/transformations_legacy.txt and runs them in a separate step.
+import pytest
+
+transformations_legacy = pytest.mark.transformations_legacy
+
+PA_LEGACY_MODELS = {
+ # optimum-intel caps these architectures at transformers<=4.53.3
+ "optimum-intel-internal-testing/tiny-random-deepseek-v3",
+ "optimum-intel-internal-testing/tiny-random-minicpm",
+ "optimum-intel-internal-testing/tiny-random-minicpm3",
+ "optimum-intel-internal-testing/tiny-random-snowflake",
+ "optimum-intel-internal-testing/tiny-random-nanollava",
+ "optimum-intel-internal-testing/tiny-random-phi-4-multimodal",
+ "optimum-intel-internal-testing/tiny-random-phi3-vision",
+ # optimum-intel caps chatglm and qwen at transformers<=4.55.4
+ "optimum-intel-internal-testing/tiny-random-chatglm",
+ "optimum-intel-internal-testing/tiny-random-chatglm4",
+ "optimum-intel-internal-testing/tiny-random-qwen",
+ # auto-gptq needs optimum 1.x, optimum 2.x loads GPTQ models only through gptqmodel
+ "optimum-intel-internal-testing/opt-125m-gptq-4bit",
+ # autoawq does not support transformers>=4.57
+ "optimum-intel-internal-testing/tiny-mixtral-AWQ-4bit",
+}
+
+ROPE_LEGACY_MODELS = {
+ # optimum-intel caps minicpm at transformers<=4.53.3, chatglm and qwen at <=4.55.4
+ "katuni4ka/tiny-random-minicpm",
+ "katuni4ka/tiny-random-qwen",
+ "optimum-intel-internal-testing/tiny-random-chatglm",
+ "optimum-intel-internal-testing/tiny-random-chatglm4",
+}
+
+
+def with_env_marks(cases, legacy_models, name_index, unpack):
+ missing = legacy_models - {case[name_index] for case in cases}
+ assert not missing, f"Legacy models are missing from the model list: {sorted(missing)}"
+ return [pytest.param(*(case if unpack else (case,)),
+ marks=transformations_legacy if case[name_index] in legacy_models else ())
+ for case in cases]
diff --git a/tests/model_hub_tests/transformation_tests/generate_ref_diffs.py b/tests/model_hub_tests/transformation_tests/generate_ref_diffs.py
index fb69303282f..b0619128718 100644
--- a/tests/model_hub_tests/transformation_tests/generate_ref_diffs.py
+++ b/tests/model_hub_tests/transformation_tests/generate_ref_diffs.py
@@ -103,7 +103,8 @@ def main():
if cls is OVModelForCausalLM:
ov_model = model.model
elif cls is OVModelForVisualCausalLM:
- ov_model = model.lm_model
+ # newer optimum-intel renamed lm_model to language_model
+ ov_model = model.language_model.model if hasattr(model, "language_model") else model.lm_model
elif cls is OVModelForSeq2SeqLM:
ov_model = model.decoder_with_past_model
else:
diff --git a/tests/model_hub_tests/transformation_tests/sdpa2pa_ref_diff.py b/tests/model_hub_tests/transformation_tests/sdpa2pa_ref_diff.py
index 3f5e771b114..5d826acb468 100644
--- a/tests/model_hub_tests/transformation_tests/sdpa2pa_ref_diff.py
+++ b/tests/model_hub_tests/transformation_tests/sdpa2pa_ref_diff.py
@@ -81,11 +81,12 @@ ref_diff_map = {
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
+ # transformers>=4.54 caches multi_query K and V as separate tensors per layer
"optimum-intel-internal-testing/tiny-random-GPTBigCodeModel" : {
- "Assign" : -5,
+ "Assign" : -10,
"PagedAttentionExtension" : 5,
"Parameter" : 13,
- "ReadValue" : -5,
+ "ReadValue" : -10,
"ScaledDotProductAttention" : -5,
},
"optimum-intel-internal-testing/tiny-random-GPTJModel" : {
@@ -539,11 +540,12 @@ ref_diff_map_optimizations = {
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
+ # transformers>=4.54 caches multi_query K and V as separate tensors per layer
"optimum-intel-internal-testing/tiny-random-GPTBigCodeModel" : {
- "Assign" : -5,
+ "Assign" : -10,
"PagedAttentionExtension" : 5,
"Parameter" : 50,
- "ReadValue" : -5,
+ "ReadValue" : -10,
"ScaledDotProductAttention" : -5,
},
"optimum-intel-internal-testing/tiny-random-GPTJModel" : {
diff --git a/tests/model_hub_tests/transformation_tests/test_pa_transformation.py b/tests/model_hub_tests/transformation_tests/test_pa_transformation.py
index cc5b458a37b..99d9d2e7b38 100644
--- a/tests/model_hub_tests/transformation_tests/test_pa_transformation.py
+++ b/tests/model_hub_tests/transformation_tests/test_pa_transformation.py
@@ -12,6 +12,7 @@ import openvino as ov
from models_hub_common.utils import retry
import models_hub_common.utils as utils
from sdpa2pa_ref_diff import ref_diff_map, ref_diff_map_optimizations, nodes_to_compare
+from env_marks import PA_LEGACY_MODELS, with_env_marks
import pytest
import os
import platform
@@ -165,7 +166,8 @@ def run_pa(tmp_path,
if cls is OVModelForCausalLM:
ov_model = model.model
elif cls is OVModelForVisualCausalLM:
- ov_model = model.lm_model
+ # newer optimum-intel renamed lm_model to language_model
+ ov_model = model.language_model.model if hasattr(model, "language_model") else model.lm_model
elif cls is OVModelForSeq2SeqLM:
ov_model = model.decoder_with_past_model
else:
@@ -183,6 +185,7 @@ PA_PRECOMMIT_TEST_CASES = [
(OVModelForSeq2SeqLM, *model_info_tuple)
for model_info_tuple in utils.get_models_list(os.path.join(os.path.dirname(__file__), "models", "hf-tiny-random-enc-dec-models-precommit"))
]
+PA_PRECOMMIT_TEST_CASES = with_env_marks(PA_PRECOMMIT_TEST_CASES, PA_LEGACY_MODELS, name_index=1, unpack=False)
def pa_test_idfn(entry):
retval = ""
diff --git a/tests/model_hub_tests/transformation_tests/test_transformations.py b/tests/model_hub_tests/transformation_tests/test_transformations.py
index b968ccc38eb..93cac2e7a1c 100644
--- a/tests/model_hub_tests/transformation_tests/test_transformations.py
+++ b/tests/model_hub_tests/transformation_tests/test_transformations.py
@@ -3,6 +3,7 @@
from huggingface_hub import snapshot_download
import models_hub_common.utils as utils
+from env_marks import ROPE_LEGACY_MODELS, with_env_marks
import pytest
import os
import platform
@@ -87,16 +88,10 @@ def run_test(model_id, ie_device, ts_names, expected_layer_types):
try:
from optimum.intel import OVModelForCausalLM
except (ImportError, AttributeError):
- try:
- from optimum.intel.openvino import OVModelForCausalLM
- except (ImportError, AttributeError):
- pytest.skip("OVModelForCausalLM unavailable with installed package versions")
+ from optimum.intel.openvino import OVModelForCausalLM
model_cached = snapshot_download(model_id) # required to avoid HF rate limits
- try:
- model = OVModelForCausalLM.from_pretrained(model_cached, export=True, trust_remote_code=True)
- except (ValueError, ImportError) as e:
- pytest.skip(f"model export is not possible with the installed package versions: {e}")
+ model = OVModelForCausalLM.from_pretrained(model_cached, export=True, trust_remote_code=True)
compile_and_check(model.model, ie_device, ts_names, expected_layer_types)
@@ -151,7 +146,9 @@ def run_flux_test(model_id, ie_device, ts_names, expected_layer_types):
@pytest.mark.precommit
[email protected]("model_name, model_link, mark, reason, ts_names, layer_types, model_type", utils.get_models_list(os.path.join(os.path.dirname(__file__), "models", "transformations-models-precommit")))
[email protected]("model_name, model_link, mark, reason, ts_names, layer_types, model_type",
+ with_env_marks(utils.get_models_list(os.path.join(os.path.dirname(__file__), "models", "transformations-models-precommit")),
+ ROPE_LEGACY_MODELS, name_index=0, unpack=True))
def test_transformations_precommit(tmp_path, model_name, model_link, mark, reason, ie_device, ts_names, layer_types, model_type):
assert mark is None or mark == 'skip' or mark == 'xfail', \
"Incorrect test case: {}, {}".format(model_name, model_link)