Skip to content

Commit

Permalink
Enable ITREX v1.4.2 for torch 2.3.0+cpu (#733)
Browse files Browse the repository at this point in the history
* Enable ITREX v1.4.2 for specific torch version

* fix

* fix style

* update itrex version

* fix

* fix warning
  • Loading branch information
echarlaix authored May 29, 2024
1 parent bfd0767 commit aefabf0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/test_inc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
11 changes: 6 additions & 5 deletions optimum/intel/neural_compressor/quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -79,8 +80,6 @@
)


_ITREX_EXCLUDED_VERSION = "1.4.2"

if is_itrex_available():
if is_itrex_version("<", ITREX_MINIMUM_VERSION):
raise ImportError(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit aefabf0

Please sign in to comment.