Skip to content

Commit a251422

Browse files
authored
Fix torch version for ipex tests (#545)
* fix torch version for ipex tests * disbale tests for incompatible torch version with ipex * fix
1 parent 3b627f4 commit a251422

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

.github/workflows/test_ipex.yml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
- name: Install dependencies
3131
run: |
3232
python -m pip install --upgrade pip
33+
pip install torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 --index-url https://download.pytorch.org/whl/cpu
3334
pip install .[ipex,tests]
3435
- name: Test with Pytest
3536
run: |

tests/neural_compressor/test_optimization.py

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import os
1919
import tempfile
2020

21+
import unittest
2122
import evaluate
2223
import numpy as np
2324
import torch
@@ -43,6 +44,8 @@
4344
set_seed,
4445
)
4546
from utils_tests import SEED, INCTestMixin, _generate_dataset
47+
from optimum.intel.utils.import_utils import is_torch_version
48+
4649

4750
from optimum.intel import (
4851
INCConfig,
@@ -163,6 +166,7 @@ def test_static_quantization(self, task, model_name, expected_quantized_matmuls)
163166
)
164167

165168
@parameterized.expand(SUPPORTED_ARCHITECTURES_WITH_EXPECTED_QUANTIZED_MATMULS)
169+
@unittest.skipIf(is_torch_version(">=", "2.2.0"), "compatibility issue with torch 2.2.0 and IPEX latest version")
166170
def test_ipex_static_quantization_with_smoothquant(self, task, model_name, expected_quantized_matmuls):
167171
recipes = {"smooth_quant": True, "smooth_quant_args": {"alpha": 0.5}}
168172
num_samples = 10

tests/neural_compressor/utils_tests.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,23 @@
4040
INCStableDiffusionPipeline,
4141
)
4242

43-
from optimum.intel.ipex import (
44-
IPEXModelForCausalLM,
45-
IPEXModelForSequenceClassification,
46-
IPEXModelForMaskedLM,
47-
IPEXModelForTokenClassification,
48-
)
43+
44+
from optimum.intel.utils.import_utils import is_torch_version
4945

5046
from optimum.intel.neural_compressor.utils import _HEAD_TO_AUTOMODELS
5147
from optimum.intel.utils.constant import ONNX_WEIGHTS_NAME
5248
from optimum.onnxruntime import ORTModelForCausalLM, ORTModelForSequenceClassification
5349
from optimum.pipelines import ORT_SUPPORTED_TASKS
5450

51+
if is_torch_version("<", "2.2.0"):
52+
from optimum.intel.ipex import (
53+
IPEXModelForCausalLM,
54+
IPEXModelForSequenceClassification,
55+
IPEXModelForMaskedLM,
56+
IPEXModelForTokenClassification,
57+
)
58+
59+
5560
SEED = 1009
5661
_TASK_TO_DATASET = {
5762
"text-classification": ("glue", "sst2", "sentence"),

0 commit comments

Comments
 (0)