From aefabf0b443ef485c6cb8e1e8a51b8c62625739d Mon Sep 17 00:00:00 2001 From: Ella Charlaix <80481427+echarlaix@users.noreply.github.com> Date: Wed, 29 May 2024 10:23:48 +0200 Subject: [PATCH] Enable ITREX v1.4.2 for torch 2.3.0+cpu (#733) * Enable ITREX v1.4.2 for specific torch version * fix * fix style * update itrex version * fix * fix warning --- .github/workflows/test_inc.yml | 5 ++--- optimum/intel/neural_compressor/quantization.py | 11 ++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test_inc.yml b/.github/workflows/test_inc.yml index e3a7518a6f..81d102bc01 100644 --- a/.github/workflows/test_inc.yml +++ b/.github/workflows/test_inc.yml @@ -32,9 +32,9 @@ jobs: python -m pip install --upgrade pip pip install cmake pip install py-cpuinfo - pip install torch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 --index-url https://download.pytorch.org/whl/cpu + pip install torch==2.3.0 torchaudio==2.3.0 torchvision==0.18 --index-url https://download.pytorch.org/whl/cpu pip install .[neural-compressor,diffusers,tests] - pip install intel-extension-for-transformers==1.4.1 + pip install intel-extension-for-transformers pip install peft - name: Test with Pytest @@ -43,7 +43,6 @@ jobs: - name: Test IPEX run: | pip uninstall -y intel-extension-for-transformers - pip install torch==2.3.0 torchaudio==2.3.0 torchvision==0.18 --extra-index-url https://download.pytorch.org/whl/cpu pip install intel-extension-for-pytorch==2.3.0 pytest tests/neural_compressor/test_ipex.py diff --git a/optimum/intel/neural_compressor/quantization.py b/optimum/intel/neural_compressor/quantization.py index 57bc3ae7a1..5004787120 100644 --- a/optimum/intel/neural_compressor/quantization.py +++ b/optimum/intel/neural_compressor/quantization.py @@ -29,6 +29,7 @@ from neural_compressor.model.onnx_model import ONNXModel from neural_compressor.model.torch_model import IPEXModel, PyTorchModel from neural_compressor.quantization import fit +from packaging.version import parse from torch.utils.data import DataLoader, RandomSampler from transformers import ( DataCollator, @@ -79,8 +80,6 @@ ) -_ITREX_EXCLUDED_VERSION = "1.4.2" - if is_itrex_available(): if is_itrex_version("<", ITREX_MINIMUM_VERSION): raise ImportError( @@ -229,10 +228,12 @@ def quantize( # ITREX Weight Only Quantization if not isinstance(quantization_config, PostTrainingQuantConfig): - if is_itrex_version("==", _ITREX_EXCLUDED_VERSION): + if is_itrex_version("==", "1.4.2") and ( + is_torch_version("!=", "2.3.0") or parse(_torch_version).local != "cpu" + ): raise ImportError( - f"Found an incompatible version of `intel-extension-for-transformers`. Found version {_itrex_version}, " - f"but {_ITREX_EXCLUDED_VERSION} is not compatible." + f"Found an incompatible version of `intel-extension-for-transformers` and `torch`. Found version itrex {_itrex_version} and torch {_torch_version}, " + f"but only torch 2.3.0+cpu is compatible with ITREX v1.4.2." ) # check neural-compressor version