Skip to content

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

[Transformations] Improve RoPE fusion regression testing (#34288)

Evgeny Kotov4f51ccbe7197
diff --git a/.github/workflows/job_pytorch_models_tests.yml b/.github/workflows/job_pytorch_models_tests.yml
index 4a01cdc0d3d..f4d1db5c568 100644
--- a/.github/workflows/job_pytorch_models_tests.yml
+++ b/.github/workflows/job_pytorch_models_tests.yml
@@ -129,14 +129,6 @@ jobs:
env:
TEST_DEVICE: CPU
- - name: RoPE 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_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
-
- name: StatefulToStateless Test
if: ${{ inputs.model_scope == 'precommit' }}
run: |
@@ -164,6 +156,15 @@ jobs:
env:
TEST_DEVICE: CPU
+ - name: RoPE Test
+ 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 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
+
- name: Reformat unsupported ops file
if: ${{ inputs.model_scope != 'precommit' && !cancelled()}}
run: |
diff --git a/.github/workflows/ubuntu_22.yml b/.github/workflows/ubuntu_22.yml
index 29a500da9c1..9d1054da5d8 100644
--- a/.github/workflows/ubuntu_22.yml
+++ b/.github/workflows/ubuntu_22.yml
@@ -631,6 +631,20 @@ jobs:
# if: ${{ github.event_name == 'schedule' }}
if: ${{ 'false' }} # Ticket: 143677
+ # Ticket: CVS-182443 — iGPU runners cannot install pip packages from PyPI, need to whitelist pypi.org and download.pytorch.org
+ # iGPU_RoPE_Tests:
+ # name: iGPU RoPE Tests
+ # needs: [ Build, Smart_CI, Openvino_tokenizers ]
+ # uses: ./.github/workflows/job_gpu_tests.yml
+ # with:
+ # device: 'igpu'
+ # test_type: 'rope'
+ # runner: "[ 'self-hosted', 'igpu' ]"
+ # runner-group: 'Intel-GPU'
+ # image: ubuntu:22.04
+ # options: "--group-add 44 --group-add 993 --device /dev/dri/card1:/dev/dri/card1 --device /dev/dri/renderD128:/dev/dri/renderD128 -e HF_TOKEN"
+ # if: fromJSON(needs.smart_ci.outputs.affected_components).GPU
+
Overall_Status:
name: ci/gha_overall_status
needs: [Smart_CI, Build, Debian_Packages, Samples, Conformance, CXX_Unit_Tests, Python_Unit_Tests, TensorFlow_Layer_Tests, Pytorch_Layer_Tests,
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 6eccbd6bdcb..a6af01d0657 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
+install(FILES requirements_pytorch requirements_tensorflow requirements_onnx requirements_jax requirements_rope.txt
DESTINATION tests COMPONENT tests EXCLUDE_FROM_ALL)
diff --git a/tests/model_hub_tests/models_hub_common/utils.py b/tests/model_hub_tests/models_hub_common/utils.py
index 3bb1c99d9ad..552825f92cb 100644
--- a/tests/model_hub_tests/models_hub_common/utils.py
+++ b/tests/model_hub_tests/models_hub_common/utils.py
@@ -41,7 +41,12 @@ def get_models_list(file_name: str):
other = line_items[4:]
transformations = [item[8:] for item in other if item.startswith('ts_name:')]
layers = [item[6:] for item in other if item.startswith('layer:')]
- models.append((model_name, model_link, mark, reason, transformations, layers))
+ model_type = None
+ for item in other:
+ if item.startswith('type:'):
+ model_type = item[5:]
+ break
+ models.append((model_name, model_link, mark, reason, transformations, layers, model_type))
else:
items = ','.join(line_items)
assert False, \
diff --git a/tests/model_hub_tests/transformation_tests/models/transformations-models-precommit b/tests/model_hub_tests/transformation_tests/models/transformations-models-precommit
index b3068ffbb52..4fc4a3417a5 100644
--- a/tests/model_hub_tests/transformation_tests/models/transformations-models-precommit
+++ b/tests/model_hub_tests/transformation_tests/models/transformations-models-precommit
@@ -25,3 +25,18 @@ fxmarty/tiny-random-GemmaForCausalLM,https://huggingface.co/fxmarty/tiny-random-
fxmarty/tiny-dummy-qwen2,https://huggingface.co/fxmarty/tiny-dummy-qwen2,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
fxmarty/really-tiny-falcon-testing,https://huggingface.co/fxmarty/really-tiny-falcon-testing,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
Xenova/tiny-random-Phi3ForCausalLM,https://huggingface.co/Xenova/tiny-random-Phi3ForCausalLM,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+optimum-intel-internal-testing/tiny-random-chatglm4,https://huggingface.co/optimum-intel-internal-testing/tiny-random-chatglm4,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+optimum-intel-internal-testing/tiny-random-chatglm,https://huggingface.co/optimum-intel-internal-testing/tiny-random-chatglm,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+optimum-intel-internal-testing/tiny-random-gemma2,https://huggingface.co/optimum-intel-internal-testing/tiny-random-gemma2,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+optimum-intel-internal-testing/tiny-random-mistral-nemo,https://huggingface.co/optimum-intel-internal-testing/tiny-random-mistral-nemo,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+optimum-intel-internal-testing/tiny-random-exaone,https://huggingface.co/optimum-intel-internal-testing/tiny-random-exaone,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+optimum-intel-internal-testing/tiny-random-granite,https://huggingface.co/optimum-intel-internal-testing/tiny-random-granite,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+optimum-intel-internal-testing/tiny-random-qwen3,https://huggingface.co/optimum-intel-internal-testing/tiny-random-qwen3,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+optimum-intel-internal-testing/tiny-random-qwen3moe,https://huggingface.co/optimum-intel-internal-testing/tiny-random-qwen3moe,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+optimum-intel-internal-testing/tiny-random-gemma3-text,https://huggingface.co/optimum-intel-internal-testing/tiny-random-gemma3-text,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+optimum-intel-internal-testing/tiny-random-olmo2,https://huggingface.co/optimum-intel-internal-testing/tiny-random-olmo2,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+optimum-intel-internal-testing/tiny-random-ArceeForCausalLM,https://huggingface.co/optimum-intel-internal-testing/tiny-random-ArceeForCausalLM,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+optimum-intel-internal-testing/tiny-random-exaone4,https://huggingface.co/optimum-intel-internal-testing/tiny-random-exaone4,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+optimum-intel-internal-testing/tiny-GptOssForCausalLM,https://huggingface.co/optimum-intel-internal-testing/tiny-GptOssForCausalLM,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+optimum-intel-internal-testing/tiny-random-granite-moe,https://huggingface.co/optimum-intel-internal-testing/tiny-random-granite-moe,,,ts_name:ov::pass::RoPEFusion,layer:RoPE
+hf-internal-testing/tiny-flux-pipe,https://huggingface.co/hf-internal-testing/tiny-flux-pipe,,,ts_name:ov::pass::RoPEFusion,layer:RoPE,type:flux
diff --git a/tests/model_hub_tests/transformation_tests/test_transformations.py b/tests/model_hub_tests/transformation_tests/test_transformations.py
index 92289f2838e..b968ccc38eb 100644
--- a/tests/model_hub_tests/transformation_tests/test_transformations.py
+++ b/tests/model_hub_tests/transformation_tests/test_transformations.py
@@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0
from huggingface_hub import snapshot_download
-from optimum.intel import OVModelForCausalLM
import models_hub_common.utils as utils
import pytest
import os
@@ -11,6 +10,7 @@ import openvino as ov
import tempfile
from collections import deque
import csv
+import torch
def parse_transformations_log(file_name):
@@ -72,23 +72,87 @@ class EnvVar:
del os.environ[name]
-def run_test(model_id, ie_device, ts_names, expected_layer_types):
- model_cached = snapshot_download(model_id) # required to avoid HF rate limits
- model = OVModelForCausalLM.from_pretrained(model_cached, export=True, trust_remote_code=True)
-
+def compile_and_check(ov_model, ie_device, ts_names, expected_layer_types):
with tempfile.NamedTemporaryFile(delete=True) as temp_file, \
EnvVar({'OV_ENABLE_PROFILE_PASS': temp_file.name}):
core = ov.Core()
- compiled = core.compile_model(model.model, ie_device)
+ compiled = core.compile_model(ov_model, ie_device)
check_transformations(temp_file.name, ts_names)
- ov_model = compiled.get_runtime_model()
- type_names = {op.get_rt_info()["layerType"] for op in ov_model.get_ordered_ops()}
+ runtime_model = compiled.get_runtime_model()
+ type_names = {op.get_rt_info()["layerType"] for op in runtime_model.get_ordered_ops()}
check_operations(type_names, expected_layer_types)
+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")
+
+ 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}")
+
+ compile_and_check(model.model, ie_device, ts_names, expected_layer_types)
+
+
+def run_flux_test(model_id, ie_device, ts_names, expected_layer_types):
+ from diffusers import FluxTransformer2DModel
+
+ model_cached = snapshot_download(model_id)
+ try:
+ transformer = FluxTransformer2DModel.from_pretrained(
+ model_cached, subfolder="transformer")
+ except Exception as e:
+ pytest.skip(f"flux model loading failed: {e}")
+
+ transformer.eval()
+ config = transformer.config
+
+ batch_size = 1
+ height, width = 8, 8
+ image_seq_len = height * width
+ text_seq_len = 4
+ in_channels = config.in_channels
+ joint_attention_dim = config.joint_attention_dim
+ pooled_projection_dim = config.pooled_projection_dim
+
+ hidden_states = torch.randn(batch_size, image_seq_len, in_channels)
+ encoder_hidden_states = torch.randn(batch_size, text_seq_len, joint_attention_dim)
+ pooled_projections = torch.randn(batch_size, pooled_projection_dim)
+ timestep = torch.tensor([500.0])
+ img_ids = torch.zeros(image_seq_len, 3)
+ for h in range(height):
+ for w in range(width):
+ img_ids[h * width + w, 1] = h
+ img_ids[h * width + w, 2] = w
+ txt_ids = torch.zeros(text_seq_len, 3)
+
+ example_input = {
+ "hidden_states": hidden_states,
+ "encoder_hidden_states": encoder_hidden_states,
+ "pooled_projections": pooled_projections,
+ "timestep": timestep,
+ "img_ids": img_ids,
+ "txt_ids": txt_ids,
+ }
+
+ try:
+ ov_model = ov.convert_model(transformer, example_input=example_input)
+ except Exception as e:
+ pytest.skip(f"flux model conversion to OpenVINO failed: {e}")
+
+ compile_and_check(ov_model, ie_device, ts_names, expected_layer_types)
+
+
@pytest.mark.precommit
[email protected]("model_name, model_link, mark, reason, ts_names, layer_types", utils.get_models_list(os.path.join(os.path.dirname(__file__), "models", "transformations-models-precommit")))
-def test_transformations_precommit(tmp_path, model_name, model_link, mark, reason, ie_device, ts_names, layer_types):
[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")))
+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)
arm_machine_names = {'arm', 'armv7l', 'aarch64', 'arm64', 'ARM64'}
@@ -96,12 +160,28 @@ def test_transformations_precommit(tmp_path, model_name, model_link, mark, reaso
"hf-internal-testing/tiny-random-GPTJForCausalLM",
"hf-internal-testing/tiny-random-CodeGenForCausalLM",
}
+ # RoPEFusionFlux and RoPEFusionLtxVideo are disabled on CPU
+ gpu_only_rope_models = {
+ "hf-internal-testing/tiny-flux-pipe",
+ }
+ # RoPEFusionGPTJ and RoPEFusionIOSlicing are disabled on GPU
+ gpu_disabled_rope_models = {
+ "hf-internal-testing/tiny-random-GPTJForCausalLM",
+ "hf-internal-testing/tiny-random-CodeGenForCausalLM",
+ }
if platform.machine() in arm_machine_names and model_name in arm_unsupported_rope_models:
pytest.skip("RoPE fusion is not available for this model on ARM")
+ if model_name in gpu_only_rope_models and ie_device == "CPU":
+ pytest.skip("RoPE fusion for this model is disabled on CPU")
+ if model_name in gpu_disabled_rope_models and ie_device == "GPU":
+ pytest.skip("RoPE fusion for this model is disabled on GPU")
if mark == 'skip':
pytest.skip(reason)
elif mark == 'xfail':
pytest.xfail(reason)
if not ts_names and not layer_types:
return
- run_test(model_name, ie_device, ts_names, layer_types)
+ if model_type == 'flux':
+ run_flux_test(model_name, ie_device, ts_names, layer_types)
+ else:
+ run_test(model_name, ie_device, ts_names, layer_types)
diff --git a/tests/requirements_rope.txt b/tests/requirements_rope.txt
new file mode 100644
index 00000000000..f8403cd583b
--- /dev/null
+++ b/tests/requirements_rope.txt
@@ -0,0 +1 @@
+optimum-intel==1.27.0