Skip to content

Commit 7f56900

Browse files
Merge branch 'main' into enable-awq
2 parents f14f62c + 41876fb commit 7f56900

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+286
-232
lines changed

.github/workflows/test_inc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
python -m pip install --upgrade pip
3333
pip install cmake
3434
pip install py-cpuinfo
35+
pip install torch==2.2 torchaudio torchvision --extra-index-url https://download.pytorch.org/whl/cpu
3536
pip install .[neural-compressor,diffusers,tests]
3637
pip install intel-extension-for-transformers
3738
pip install peft

.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.2 torchaudio torchvision --extra-index-url https://download.pytorch.org/whl/cpu
3334
pip install .[ipex,tests]
3435
- name: Test with Pytest
3536
run: |

.github/workflows/test_offline.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Offline usage / Python - Test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build:
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
python-version: [3.9]
19+
os: [ubuntu-latest]
20+
21+
runs-on: ${{ matrix.os }}
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: Setup Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v3
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
- name: Install dependencies
29+
run: |
30+
pip install .[tests,openvino]
31+
- name: Test
32+
run: |
33+
HF_HOME=/tmp/ huggingface-cli download hf-internal-testing/tiny-random-gpt2
34+
HF_HOME=/tmp/ HF_HUB_OFFLINE=1 optimum-cli export openvino --model hf-internal-testing/tiny-random-gpt2 gpt2_openvino --task text-generation
35+
36+
huggingface-cli download hf-internal-testing/tiny-random-gpt2
37+
HF_HUB_OFFLINE=1 optimum-cli export openvino --model hf-internal-testing/tiny-random-gpt2 gpt2_openvino --task text-generation
38+
39+
pytest tests/openvino/test_modeling.py -k "test_load_from_hub" -s -vvvvv
40+
HF_HUB_OFFLINE=1 pytest tests/openvino/test_modeling.py -k "test_load_from_hub" -s -vvvvv

.github/workflows/test_openvino_examples.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ on:
77
push:
88
paths:
99
- '.github/workflows/test_openvino_examples.yml'
10-
- 'examples/openvino/*'
10+
- 'examples/openvino/**'
1111
pull_request:
1212
paths:
1313
- '.github/workflows/test_openvino_examples.yml'
14-
- 'examples/openvino/*'
14+
- 'examples/openvino/**'
1515

1616
concurrency:
1717
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -22,9 +22,9 @@ jobs:
2222
strategy:
2323
fail-fast: false
2424
matrix:
25-
python-version: ["3.8", "3.10"]
25+
python-version: ["3.8", "3.11"]
2626

27-
runs-on: ubuntu-20.04
27+
runs-on: ubuntu-22.04
2828

2929
steps:
3030
- uses: actions/checkout@v2
@@ -35,12 +35,12 @@ jobs:
3535

3636
- name: Install dependencies
3737
run: |
38-
pip install optimum[openvino] jstyleson nncf pytest
39-
pip install -r examples/openvino/audio-classification/requirements.txt
40-
pip install -r examples/openvino/image-classification/requirements.txt
41-
pip install -r examples/openvino/question-answering/requirements.txt
42-
pip install -r examples/openvino/text-classification/requirements.txt
38+
pip install .[openvino] jstyleson pytest
39+
pip install -r examples/openvino/audio-classification/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
40+
pip install -r examples/openvino/image-classification/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
41+
pip install -r examples/openvino/question-answering/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
42+
pip install -r examples/openvino/text-classification/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
4343
4444
- name: Test examples
4545
run: |
46-
python -m pytest examples/openvino/test_examples.py
46+
python -m pytest examples/openvino/test_examples.py

.github/workflows/test_openvino_notebooks.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ jobs:
2323
strategy:
2424
fail-fast: false
2525
matrix:
26-
python-version: ["3.8", "3.10"]
26+
python-version: ["3.8", "3.11"]
2727

28-
runs-on: ubuntu-20.04
28+
runs-on: ubuntu-22.04
2929

3030
steps:
3131
- uses: actions/checkout@v2

examples/neural_compressor/language-modeling/run_clm.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,10 @@
5757
from transformers.utils.versions import require_version
5858

5959
from optimum.intel.neural_compressor import INCModelForCausalLM, INCQuantizer, INCTrainer
60-
from optimum.intel.utils.import_utils import (
61-
INTEL_EXTENSION_FOR_TRANSFORMERS_IMPORT_ERROR,
62-
is_intel_extension_for_transformers_available,
63-
)
60+
from optimum.intel.utils.import_utils import ITREX_IMPORT_ERROR, is_itrex_available
6461

6562

66-
if is_intel_extension_for_transformers_available():
63+
if is_itrex_available():
6764
from intel_extension_for_transformers.transformers.utils.config import GPTQConfig, RtnConfig
6865

6966
os.environ["CUDA_VISIBLE_DEVICES"] = ""
@@ -658,8 +655,8 @@ def compute_metrics(eval_preds):
658655
else:
659656
recipes = {}
660657
if optim_args.quantization_approach == "weight_only":
661-
if not is_intel_extension_for_transformers_available():
662-
raise ImportError(INTEL_EXTENSION_FOR_TRANSFORMERS_IMPORT_ERROR.format("WeightOnly quantization"))
658+
if not is_itrex_available():
659+
raise ImportError(ITREX_IMPORT_ERROR.format("WeightOnly quantization"))
663660
if optim_args.apply_pruning or optim_args.apply_distillation:
664661
raise ValueError("Weight only quantization and pruning or distillation cannot be combined.")
665662

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
datasets>=1.14.0
22
evaluate
33
librosa
4-
torchaudio
4+
torchaudio
5+
accelerate

examples/openvino/audio-classification/run_audio_classification.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from transformers.utils import check_min_version, send_example_telemetry
3636
from transformers.utils.versions import require_version
3737

38-
from optimum.intel.openvino import OVConfig, OVTrainer, OVTrainingArguments
38+
from optimum.intel import OVConfig, OVTrainer, OVTrainingArguments
3939

4040

4141
logger = logging.getLogger(__name__)

examples/openvino/image-classification/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ datasets >= 1.8.0
22
torch >= 1.9.0
33
torchvision>=0.6.0
44
evaluate
5+
accelerate

examples/openvino/image-classification/run_image_classification.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
from transformers.utils import check_min_version, send_example_telemetry
5353
from transformers.utils.versions import require_version
5454

55-
from optimum.intel.openvino import OVConfig, OVTrainer, OVTrainingArguments
55+
from optimum.intel import OVConfig, OVTrainer, OVTrainingArguments
5656

5757

5858
logger = logging.getLogger(__name__)
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
datasets >= 1.8.0
22
torch >= 1.9.0
33
evaluate
4+
accelerate

examples/openvino/question-answering/run_qa.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from transformers.utils.versions import require_version
5050
from utils_qa import postprocess_qa_predictions
5151

52-
from optimum.intel.openvino import OVConfig, OVTrainingArguments
52+
from optimum.intel import OVConfig, OVTrainingArguments
5353

5454

5555
# Will error if the minimal version of Transformers is not installed. Remove at your own risks.

examples/openvino/question-answering/trainer_qa.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import torch.nn.functional as F
2121
from transformers.trainer_utils import PredictionOutput
2222

23-
from optimum.intel.openvino.trainer import OVTrainer
23+
from optimum.intel import OVTrainer
2424

2525

2626
class QuestionAnsweringOVTrainer(OVTrainer):

examples/openvino/text-classification/requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ scipy
44
scikit-learn
55
protobuf
66
torch >= 1.3
7-
evaluate
7+
evaluate
8+
accelerate

examples/openvino/text-classification/run_glue.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from transformers.utils import check_min_version, send_example_telemetry
4747
from transformers.utils.versions import require_version
4848

49-
from optimum.intel.openvino import OVConfig, OVTrainer, OVTrainingArguments
49+
from optimum.intel import OVConfig, OVTrainer, OVTrainingArguments
5050

5151

5252
# Will error if the minimal version of Transformers is not installed. Remove at your own risks.

notebooks/openvino/optimum_openvino_inference.ipynb

+12-12
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
}
7777
],
7878
"source": [
79-
"from optimum.intel.openvino import OVModelForQuestionAnswering\n",
79+
"from optimum.intel import OVModelForQuestionAnswering\n",
8080
"\n",
8181
"# Load PyTorch model from the Hub and export to OpenVINO in the background\n",
8282
"model = OVModelForQuestionAnswering.from_pretrained(\"distilbert-base-uncased-distilled-squad\", export=True)\n",
@@ -182,7 +182,7 @@
182182
}
183183
],
184184
"source": [
185-
"from optimum.intel.openvino import OVModelForQuestionAnswering\n",
185+
"from optimum.intel import OVModelForQuestionAnswering\n",
186186
"from transformers import AutoTokenizer, pipeline\n",
187187
"\n",
188188
"model = OVModelForQuestionAnswering.from_pretrained(\"distilbert-base-uncased-distilled-squad-ov-fp32\")\n",
@@ -240,7 +240,7 @@
240240
],
241241
"source": [
242242
"import torch\n",
243-
"from optimum.intel.openvino import OVModelForQuestionAnswering\n",
243+
"from optimum.intel import OVModelForQuestionAnswering\n",
244244
"from transformers import AutoTokenizer, pipeline\n",
245245
"\n",
246246
"model = OVModelForQuestionAnswering.from_pretrained(\"distilbert-base-uncased-distilled-squad-ov-fp32\")\n",
@@ -324,7 +324,7 @@
324324
}
325325
],
326326
"source": [
327-
"from optimum.intel.openvino import OVModelForQuestionAnswering\n",
327+
"from optimum.intel import OVModelForQuestionAnswering\n",
328328
"from transformers import AutoTokenizer, pipeline\n",
329329
"\n",
330330
"model = OVModelForQuestionAnswering.from_pretrained(\n",
@@ -529,7 +529,7 @@
529529
],
530530
"source": [
531531
"from IPython.display import Audio\n",
532-
"from optimum.intel.openvino import OVModelForAudioClassification\n",
532+
"from optimum.intel import OVModelForAudioClassification\n",
533533
"from transformers import AutoFeatureExtractor, pipeline\n",
534534
"from datasets import load_dataset\n",
535535
"\n",
@@ -638,7 +638,7 @@
638638
}
639639
],
640640
"source": [
641-
"from optimum.intel.openvino import OVModelForCausalLM\n",
641+
"from optimum.intel import OVModelForCausalLM\n",
642642
"from transformers import AutoTokenizer, pipeline\n",
643643
"\n",
644644
"model_id = \"helenai/gpt2-ov\"\n",
@@ -704,7 +704,7 @@
704704
],
705705
"source": [
706706
"from IPython.display import Image\n",
707-
"from optimum.intel.openvino import OVModelForImageClassification\n",
707+
"from optimum.intel import OVModelForImageClassification\n",
708708
"from transformers import AutoImageProcessor, pipeline\n",
709709
"\n",
710710
"model_id = \"helenai/microsoft-swin-tiny-patch4-window7-224-ov\"\n",
@@ -766,7 +766,7 @@
766766
}
767767
],
768768
"source": [
769-
"from optimum.intel.openvino import OVModelForMaskedLM\n",
769+
"from optimum.intel import OVModelForMaskedLM\n",
770770
"from transformers import AutoTokenizer, pipeline\n",
771771
"\n",
772772
"model_id = \"helenai/bert-base-uncased-ov\"\n",
@@ -835,7 +835,7 @@
835835
}
836836
],
837837
"source": [
838-
"from optimum.intel.openvino import OVModelForQuestionAnswering\n",
838+
"from optimum.intel import OVModelForQuestionAnswering\n",
839839
"from transformers import AutoTokenizer, pipeline\n",
840840
"\n",
841841
"# Load the model and tokenizer saved in Part 1 of this notebook. Or use the line below to load them from the hub\n",
@@ -890,7 +890,7 @@
890890
}
891891
],
892892
"source": [
893-
"from optimum.intel.openvino import OVModelForSeq2SeqLM\n",
893+
"from optimum.intel import OVModelForSeq2SeqLM\n",
894894
"from transformers import AutoTokenizer, pipeline\n",
895895
"\n",
896896
"model_id = \"helenai/t5-small-ov\"\n",
@@ -998,7 +998,7 @@
998998
}
999999
],
10001000
"source": [
1001-
"from optimum.intel.openvino import OVModelForSequenceClassification\n",
1001+
"from optimum.intel import OVModelForSequenceClassification\n",
10021002
"from transformers import AutoTokenizer, pipeline\n",
10031003
"\n",
10041004
"model_id = \"helenai/papluca-xlm-roberta-base-language-detection-ov\"\n",
@@ -1047,7 +1047,7 @@
10471047
}
10481048
],
10491049
"source": [
1050-
"from optimum.intel.openvino import OVModelForTokenClassification\n",
1050+
"from optimum.intel import OVModelForTokenClassification\n",
10511051
"from transformers import AutoTokenizer, pipeline\n",
10521052
"\n",
10531053
"model_id = \"helenai/dslim-bert-base-NER-ov-fp32\"\n",

notebooks/openvino/question_answering_quantization.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"import transformers\n",
5252
"from evaluate import evaluator\n",
5353
"from openvino.runtime import Core\n",
54-
"from optimum.intel.openvino import OVModelForQuestionAnswering, OVQuantizer, OVQuantizationConfig, OVConfig\n",
54+
"from optimum.intel import OVModelForQuestionAnswering, OVQuantizer, OVQuantizationConfig, OVConfig\n",
5555
"from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline\n",
5656
"\n",
5757
"transformers.logging.set_verbosity_error()\n",
@@ -286,7 +286,7 @@
286286
"**NOTE:** if you notice very low accuracy after post-training quantization, it is likely caused by an overflow issue which affects processors that do not contain VNNI (Vector Neural Network Instruction). NNCF has an `overflow_fix` option to address this. It will effectively use 7-bits for quantizing instead of 8-bits to prevent the overflow. To use this option, modify the code in the next cell to add an explicit quantization configuration, and set `overflow_fix` to `\"enable\"`:\n",
287287
"\n",
288288
"```\n",
289-
"from optimum.intel.openvino import OVConfig, OVQuantizationConfig\n",
289+
"from optimum.intel import OVConfig, OVQuantizationConfig\n",
290290
"\n",
291291
"ov_config = OVConfig(quantization_config=OVQuantizationConfig(overflow_fix=\"enable\")\n",
292292
"quantizer = OVQuantizer.from_pretrained(model)\n",

notebooks/openvino/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
optimum-intel[openvino, nncf]
1+
optimum-intel[openvino]
22
datasets
33
evaluate[evaluator]
44
ipywidgets

notebooks/openvino/stable_diffusion_optimization.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"metadata": {},
1515
"outputs": [],
1616
"source": [
17-
"from optimum.intel.openvino import OVStableDiffusionPipeline\n",
17+
"from optimum.intel import OVStableDiffusionPipeline\n",
1818
"from diffusers.training_utils import set_seed\n",
1919
"from IPython.display import display"
2020
]

optimum/commands/export/openvino.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from pathlib import Path
1919
from typing import TYPE_CHECKING, Optional
2020

21+
from huggingface_hub.constants import HUGGINGFACE_HUB_CACHE
22+
2123
from ...exporters import TasksManager
2224
from ...intel.utils.import_utils import DIFFUSERS_IMPORT_ERROR, is_diffusers_available
2325
from ..base import BaseOptimumCLICommand, CommandInfo
@@ -47,7 +49,9 @@ def parse_args_openvino(parser: "ArgumentParser"):
4749
f" {str(TasksManager.get_all_tasks())}. For decoder models, use `xxx-with-past` to export the model using past key values in the decoder."
4850
),
4951
)
50-
optional_group.add_argument("--cache_dir", type=str, default=None, help="Path indicating where to store cache.")
52+
optional_group.add_argument(
53+
"--cache_dir", type=str, default=HUGGINGFACE_HUB_CACHE, help="Path indicating where to store cache."
54+
)
5155
optional_group.add_argument(
5256
"--framework",
5357
type=str,

optimum/exporters/openvino/__main__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from pathlib import Path
1717
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Union
1818

19+
from huggingface_hub.constants import HUGGINGFACE_HUB_CACHE
1920
from requests.exceptions import ConnectionError as RequestsConnectionError
2021
from transformers import AutoConfig, AutoTokenizer, PreTrainedTokenizerBase
2122

@@ -48,7 +49,7 @@ def main_export(
4849
task: str = "auto",
4950
device: str = "cpu",
5051
framework: Optional[str] = None,
51-
cache_dir: Optional[str] = None,
52+
cache_dir: str = HUGGINGFACE_HUB_CACHE,
5253
trust_remote_code: bool = False,
5354
pad_token_id: Optional[int] = None,
5455
subfolder: str = "",

0 commit comments

Comments
 (0)