Skip to content

Commit 8ba1b8b

Browse files
authored
Merge branch 'main' into task-to-padding-side
2 parents 96ea0a3 + 6388aeb commit 8ba1b8b

File tree

20 files changed

+506
-91
lines changed

20 files changed

+506
-91
lines changed
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Build and Test Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'docker/Dockerfile.intel'
9+
10+
pull_request:
11+
branches:
12+
- main
13+
paths:
14+
- 'docker/Dockerfile.intel'
15+
16+
jobs:
17+
build_and_run:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Build and Run Docker Image
28+
run: |
29+
IMAGE_NAME="intel_image:latest"
30+
docker build -f docker/Dockerfile.intel -t $IMAGE_NAME .
31+
if [ $? -ne 0 ]; then
32+
echo "Docker image build failed."
33+
exit 1
34+
fi
35+
CONTAINER_ID=$(docker run -d $IMAGE_NAME tail -f /dev/null)
36+
if docker inspect -f '{{.State.Running}}' $CONTAINER_ID 2>/dev/null | grep -q 'true'; then
37+
echo "Container is running."
38+
else
39+
echo "Container failed to start."
40+
docker logs $CONTAINER_ID 2>/dev/null || echo "No container ID found."
41+
exit 1
42+
fi
43+
docker stop $CONTAINER_ID
44+
docker rm $CONTAINER_ID

.github/workflows/test_openvino_notebooks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ jobs:
4040
# ffmpeg, torchaudio and pillow are required for image classification and audio classification pipelines
4141
sudo apt-get install ffmpeg
4242
pip install torch torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
43-
pip install ".[tests, openvino]" nbval
4443
pip install -r notebooks/openvino/requirements.txt
44+
pip install .[tests,openvino] nbval
4545
4646
- run: free -h
4747
- run: lscpu

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Below are examples of how to use OpenVINO and its [NNCF](https://docs.openvino.a
7272

7373
#### Export:
7474

75-
It is possible to export your model to the [OpenVINO IR](https://docs.openvino.ai/2024/documentation/openvino-ir-format.html) format with the CLI :
75+
It is also possible to export your model to the [OpenVINO IR](https://docs.openvino.ai/2024/documentation/openvino-ir-format.html) format with the CLI :
7676

7777
```plain
7878
optimum-cli export openvino --model gpt2 ov_model

docker/Dockerfile.intel

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ARG TORCHVISION_VERSION=0.18.1+cpu
3737
ARG TORCHAUDIO_VERSION=2.3.1+cpu
3838

3939
RUN python3 -m pip install --no-cache-dir \
40+
intel-openmp \
4041
torch==${PYTORCH_VERSION}+cpu \
4142
torchvision==${TORCHVISION_VERSION} \
4243
torchaudio==${TORCHAUDIO_VERSION} \

docs/source/openvino/export.mdx

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ specific language governing permissions and limitations under the License.
99

1010
# Export your model
1111

12+
To export a [model](https://huggingface.co/docs/optimum/main/en/intel/openvino/models) hosted on the [Hub](https://huggingface.co/models) you can use our [space](https://huggingface.co/spaces/echarlaix/openvino-export). After conversion, a repository will be pushed under your namespace, this repository can be either public or private.
13+
1214
## Using the CLI
1315

1416
To export your model to the [OpenVINO IR](https://docs.openvino.ai/2024/documentation/openvino-ir-format.html) format with the CLI :

docs/source/openvino/optimization.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ model = OVModelForCausalLM.from_pretrained(model_id, quantization_config=quantiz
6464
You can tune quantization parameters to achieve a better performance accuracy trade-off as follows:
6565

6666
```python
67-
quantization_config = OVWeightQuantizationConfig(bits=4, sym=False, ratio=0.8, dataset="ptb")
67+
quantization_config = OVWeightQuantizationConfig(bits=4, sym=False, ratio=0.8, dataset="wikitext2")
6868
```
6969

7070
By default the quantization scheme will be [asymmetric](https://github.com/openvinotoolkit/nncf/blob/develop/docs/usage/training_time_compression/other_algorithms/LegacyQuantization.md#asymmetric-quantization), to make it [symmetric](https://github.com/openvinotoolkit/nncf/blob/develop/docs/usage/training_time_compression/other_algorithms/LegacyQuantization.md#symmetric-quantization) you can add `sym=True`.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
datasets>=1.14.0
1+
datasets>=1.14.0,<2.20.0
22
evaluate
33
librosa
44
torchaudio
5-
accelerate
5+
accelerate

examples/openvino/image-classification/requirements.txt

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

examples/openvino/text-classification/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
datasets >= 1.8.0
1+
datasets>=1.14.0,<2.20.0
22
sentencepiece != 0.1.92
33
scipy
44
scikit-learn

optimum/commands/export/openvino.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414
"""Defines the command line for the export with OpenVINO."""
1515

16-
import json
1716
import logging
1817
import sys
1918
from pathlib import Path
@@ -213,19 +212,7 @@ def parse_args(parser: "ArgumentParser"):
213212

214213
def run(self):
215214
from ...exporters.openvino.__main__ import infer_task, main_export, maybe_convert_tokenizers
216-
from ...intel.openvino.configuration import _DEFAULT_4BIT_CONFIG, _DEFAULT_4BIT_CONFIGS, OVConfig
217-
218-
def _get_default_int4_config(model_id_or_path, library_name):
219-
if model_id_or_path in _DEFAULT_4BIT_CONFIGS:
220-
return _DEFAULT_4BIT_CONFIGS[model_id_or_path]
221-
if "transformers" in library_name and (Path(model_id_or_path) / "config.json").exists():
222-
with (Path(model_id_or_path) / "config.json").open("r") as config_f:
223-
config = json.load(config_f)
224-
original_model_name = config.get("_name_or_path", "")
225-
if original_model_name in _DEFAULT_4BIT_CONFIGS:
226-
return _DEFAULT_4BIT_CONFIGS[original_model_name]
227-
228-
return _DEFAULT_4BIT_CONFIG
215+
from ...intel.openvino.configuration import _DEFAULT_4BIT_CONFIG, OVConfig, get_default_int4_config
229216

230217
if self.args.library is None:
231218
# TODO: add revision, subfolder and token to args
@@ -260,7 +247,7 @@ def _get_default_int4_config(model_id_or_path, library_name):
260247
and self.args.awq is None
261248
and self.args.sensitivity_metric is None
262249
):
263-
quantization_config = _get_default_int4_config(self.args.model, library_name)
250+
quantization_config = get_default_int4_config(self.args.model)
264251
else:
265252
quantization_config = {
266253
"bits": 8 if is_int8 else 4,

optimum/exporters/openvino/model_configs.py

+59
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
FalconOnnxConfig,
2525
GemmaOnnxConfig,
2626
LlamaOnnxConfig,
27+
MistralOnnxConfig,
2728
MPTOnnxConfig,
2829
PhiOnnxConfig,
2930
UNetOnnxConfig,
@@ -53,11 +54,13 @@
5354
InternLMModelPatcher,
5455
JaisModelPatcher,
5556
LlamaModelPatcher,
57+
MistralModelPatcher,
5658
MixtralModelPatcher,
5759
MPTModelPatcher,
5860
PersimmonModelPatcher,
5961
Phi3ModelPatcher,
6062
QwenModelPatcher,
63+
UpdateCausalMaskModelPatcher,
6164
XverseModelPatcher,
6265
)
6366

@@ -117,6 +120,11 @@ class Qwen2OpenVINOConfig(TextDecoderWithPositionIdsOnnxConfig):
117120
DUMMY_PKV_GENERATOR_CLASS = MistralDummyPastKeyValuesGenerator
118121
NORMALIZED_CONFIG_CLASS = NormalizedTextConfig
119122

123+
def patch_model_for_export(
124+
self, model: Union["PreTrainedModel", "TFPreTrainedModel"], model_kwargs: Optional[Dict[str, Any]] = None
125+
) -> "ModelPatcher":
126+
return UpdateCausalMaskModelPatcher(self, model, model_kwargs=model_kwargs)
127+
120128

121129
@register_in_tasks_manager("qwen2-moe", *["text-generation", "text-generation-with-past"], library_name="transformers")
122130
class Qwen2MoEOpenVINOConfig(TextDecoderWithPositionIdsOnnxConfig):
@@ -126,6 +134,11 @@ class Qwen2MoEOpenVINOConfig(TextDecoderWithPositionIdsOnnxConfig):
126134
DUMMY_PKV_GENERATOR_CLASS = MistralDummyPastKeyValuesGenerator
127135
NORMALIZED_CONFIG_CLASS = NormalizedTextConfig
128136

137+
def patch_model_for_export(
138+
self, model: Union["PreTrainedModel", "TFPreTrainedModel"], model_kwargs: Optional[Dict[str, Any]] = None
139+
) -> "ModelPatcher":
140+
return UpdateCausalMaskModelPatcher(self, model, model_kwargs=model_kwargs)
141+
129142

130143
@register_in_tasks_manager("minicpm", *["text-generation", "text-generation-with-past"], library_name="transformers")
131144
class MiniCPMOpenVINOConfig(TextDecoderWithPositionIdsOnnxConfig):
@@ -144,6 +157,11 @@ class StableLMOpenVINOConfig(TextDecoderWithPositionIdsOnnxConfig):
144157
DUMMY_PKV_GENERATOR_CLASS = MistralDummyPastKeyValuesGenerator
145158
NORMALIZED_CONFIG_CLASS = NormalizedTextConfig
146159

160+
def patch_model_for_export(
161+
self, model: Union["PreTrainedModel", "TFPreTrainedModel"], model_kwargs: Optional[Dict[str, Any]] = None
162+
) -> "ModelPatcher":
163+
return UpdateCausalMaskModelPatcher(self, model, model_kwargs=model_kwargs)
164+
147165

148166
class ChatGLM2DummyPastKeyValuesGenerator(DummyPastKeyValuesGenerator):
149167
def __init__(
@@ -466,6 +484,11 @@ class Starcoder2OpenVINOConfig(TextDecoderWithPositionIdsOnnxConfig):
466484
DUMMY_PKV_GENERATOR_CLASS = MistralDummyPastKeyValuesGenerator
467485
NORMALIZED_CONFIG_CLASS = NormalizedTextConfig
468486

487+
def patch_model_for_export(
488+
self, model: Union["PreTrainedModel", "TFPreTrainedModel"], model_kwargs: Optional[Dict[str, Any]] = None
489+
) -> "ModelPatcher":
490+
return UpdateCausalMaskModelPatcher(self, model, model_kwargs=model_kwargs)
491+
469492

470493
@register_in_tasks_manager("internlm2", *["text-generation", "text-generation-with-past"], library_name="transformers")
471494
class InternLM2OpenVINOConfig(TextDecoderWithPositionIdsOnnxConfig):
@@ -530,6 +553,24 @@ def patch_model_for_export(
530553
return Phi3ModelPatcher(self, model, model_kwargs=model_kwargs)
531554

532555

556+
@register_in_tasks_manager(
557+
"phi",
558+
*[
559+
"feature-extraction",
560+
"feature-extraction-with-past",
561+
"text-generation",
562+
"text-generation-with-past",
563+
"text-classification",
564+
],
565+
library_name="transformers",
566+
)
567+
class PhiOpenVINOConfig(PhiOnnxConfig):
568+
def patch_model_for_export(
569+
self, model: Union["PreTrainedModel", "TFPreTrainedModel"], model_kwargs: Optional[Dict[str, Any]] = None
570+
) -> "ModelPatcher":
571+
return UpdateCausalMaskModelPatcher(self, model, model_kwargs=model_kwargs)
572+
573+
533574
class OVFalconDummyPastKeyValuesGenerator(FalconDummyPastKeyValuesGenerator):
534575
def __init__(
535576
self,
@@ -839,3 +880,21 @@ def patch_model_for_export(
839880
)
840881

841882
return ArcticModelPatcher(self, model, model_kwargs=model_kwargs)
883+
884+
885+
@register_in_tasks_manager(
886+
"mistral",
887+
*[
888+
"feature-extraction",
889+
"feature-extraction-with-past",
890+
"text-generation",
891+
"text-generation-with-past",
892+
"text-classification",
893+
],
894+
library_name="transformers",
895+
)
896+
class MistralOpenVINOConfig(MistralOnnxConfig):
897+
def patch_model_for_export(
898+
self, model: Union["PreTrainedModel", "TFPreTrainedModel"], model_kwargs: Optional[Dict[str, Any]] = None
899+
) -> "ModelPatcher":
900+
return MistralModelPatcher(self, model, model_kwargs=model_kwargs)

0 commit comments

Comments
 (0)