Skip to content

Commit 877cf9d

Browse files
authored
Add test for OpenVINO Examples (#602)
* added tests for ov examples * modified tests for ov examples * modified tests for ov examples * modified tests for ov examples * added tests for ov examples * added a new file for testing examples * added dependencies for ov examples * added config path * removed audio test * removed SD test * removed audio test * changed installation packages * added stable diffusion * removed stable diffusion * changed installation packages * added nncf package * only audio classification * audio image classification * audio image q-answering * image text q-answering * combined notebooks and examples * including only openvino examples * including only openvino examples * added combined test for notebooks and examples * added combined test for notebooks and examples * added SD for examples * added SD for OV examples * Running only SD * Running only SD * added test for ov examples * test for ov examples * torch cpu * test for ov examples * added a test script for OV examples v1 * added a test script for OV examples v2 * added test for ov examples * added test for ov examples v3 * added test for ov examples v4 * added test for ov examples v5 * added test for ov examples v6 * added test for ov examples v7 * replaced suggested models
1 parent 9f70fe9 commit 877cf9d

File tree

2 files changed

+192
-0
lines changed

2 files changed

+192
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: OpenVINO - Examples Test
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '14 3 * * 1' # run weekly: every Monday at 3:14
7+
push:
8+
paths:
9+
- '.github/workflows/test_openvino_examples.yml'
10+
- 'examples/openvino/*'
11+
pull_request:
12+
paths:
13+
- '.github/workflows/test_openvino_examples.yml'
14+
- 'examples/openvino/*'
15+
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
19+
cancel-in-progress: true
20+
21+
jobs:
22+
build:
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
python-version: ["3.8", "3.10"]
27+
28+
runs-on: ubuntu-20.04
29+
30+
steps:
31+
- uses: actions/checkout@v2
32+
- name: Setup Python ${{ matrix.python-version }}
33+
uses: actions/setup-python@v2
34+
with:
35+
python-version: ${{ matrix.python-version }}
36+
37+
- name: Install dependencies
38+
run: |
39+
pip install optimum[openvino] jstyleson nncf
40+
pip install -r examples/openvino/audio-classification/requirements.txt
41+
pip install -r examples/openvino/image-classification/requirements.txt
42+
pip install -r examples/openvino/question-answering/requirements.txt
43+
pip install -r examples/openvino/text-classification/requirements.txt
44+
45+
- name: Test examples
46+
run: |
47+
python examples/openvino/test_examples.py

examples/openvino/test_examples.py

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Copyright 2021 The HuggingFace Team. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import os
15+
import sys
16+
import tempfile
17+
import unittest
18+
from unittest.mock import patch
19+
20+
SRC_DIRS = [
21+
os.path.join(os.path.dirname(__file__), dirname)
22+
for dirname in [
23+
"text-classification",
24+
"question-answering",
25+
"audio-classification",
26+
"image-classification",
27+
]
28+
]
29+
sys.path.extend(SRC_DIRS)
30+
31+
if SRC_DIRS is not None:
32+
import run_image_classification
33+
import run_audio_classification
34+
import run_glue
35+
import run_qa
36+
37+
38+
class TestExamples(unittest.TestCase):
39+
def test_audio_classification(self):
40+
with tempfile.TemporaryDirectory() as tmp_dir:
41+
test_args = f"""
42+
run_audio_classification.py
43+
--model_name_or_path hf-internal-testing/tiny-random-Wav2Vec2Model
44+
--nncf_compression_config examples/openvino/audio-classification/configs/wav2vec2-base-qat.json
45+
--dataset_name superb
46+
--dataset_config_name ks
47+
--max_train_samples 10
48+
--max_eval_samples 2
49+
--remove_unused_columns False
50+
--do_train
51+
--learning_rate 3e-5
52+
--max_length_seconds 1
53+
--attention_mask False
54+
--warmup_ratio 0.1
55+
--num_train_epochs 1
56+
--gradient_accumulation_steps 1
57+
--dataloader_num_workers 1
58+
--logging_strategy steps
59+
--logging_steps 1
60+
--evaluation_strategy epoch
61+
--save_strategy epoch
62+
--load_best_model_at_end False
63+
--seed 42
64+
--output_dir {tmp_dir}
65+
--overwrite_output_dir
66+
""".split()
67+
68+
with patch.object(sys, "argv", test_args):
69+
run_audio_classification.main()
70+
71+
def test_image_classification(self):
72+
with tempfile.TemporaryDirectory() as tmp_dir:
73+
test_args = f"""
74+
run_image_classification.py
75+
--model_name_or_path nateraw/vit-base-beans
76+
--dataset_name beans
77+
--max_train_samples 10
78+
--max_eval_samples 2
79+
--remove_unused_columns False
80+
--do_train
81+
--do_eval
82+
--learning_rate 2e-5
83+
--num_train_epochs 1
84+
--logging_strategy steps
85+
--logging_steps 1
86+
--evaluation_strategy epoch
87+
--save_strategy epoch
88+
--save_total_limit 1
89+
--seed 1337
90+
--output_dir {tmp_dir}
91+
""".split()
92+
93+
with patch.object(sys, "argv", test_args):
94+
run_image_classification.main()
95+
96+
def test_text_classification(self):
97+
with tempfile.TemporaryDirectory() as tmp_dir:
98+
test_args = f"""
99+
run_glue.py
100+
--model_name_or_path hf-internal-testing/tiny-random-DistilBertForSequenceClassification
101+
--task_name sst2
102+
--max_train_samples 10
103+
--max_eval_samples 2
104+
--overwrite_output_dir
105+
--do_train
106+
--do_eval
107+
--max_seq_length 128
108+
--learning_rate 1e-5
109+
--optim adamw_torch
110+
--num_train_epochs 1
111+
--logging_steps 1
112+
--evaluation_strategy steps
113+
--eval_steps 1
114+
--save_strategy epoch
115+
--seed 42
116+
--output_dir {tmp_dir}
117+
""".split()
118+
119+
with patch.object(sys, "argv", test_args):
120+
run_glue.main()
121+
122+
def test_question_answering(self):
123+
with tempfile.TemporaryDirectory() as tmp_dir:
124+
test_args = f"""
125+
run_qa.py
126+
--model_name_or_path hf-internal-testing/tiny-random-DistilBertForQuestionAnswering
127+
--dataset_name squad
128+
--do_train
129+
--do_eval
130+
--max_train_samples 10
131+
--max_eval_samples 2
132+
--learning_rate 3e-5
133+
--num_train_epochs 1
134+
--max_seq_length 384
135+
--doc_stride 128
136+
--overwrite_output_dir
137+
--output_dir {tmp_dir}
138+
""".split()
139+
140+
with patch.object(sys, "argv", test_args):
141+
run_qa.main()
142+
143+
144+
if __name__ == "__main__":
145+
unittest.main()

0 commit comments

Comments
 (0)