From 894334d93e6535d52488021db2ed12c11f98d6d4 Mon Sep 17 00:00:00 2001 From: Ella Charlaix <80481427+echarlaix@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:52:32 +0100 Subject: [PATCH] Fix format (#615) --- Makefile | 4 +- examples/openvino/test_examples.py | 131 +++++++++--------- .../stable_diffusion_optimization.ipynb | 8 +- 3 files changed, 70 insertions(+), 73 deletions(-) diff --git a/Makefile b/Makefile index 90a2827bed..83035cf467 100644 --- a/Makefile +++ b/Makefile @@ -22,11 +22,11 @@ REAL_CLONE_URL = $(if $(CLONE_URL),$(CLONE_URL),$(DEFAULT_CLONE_URL)) # Run code quality checks style_check: black --check . - ruff . + ruff check . style: black . - ruff . --fix + ruff check . --fix # Run tests for the library test: diff --git a/examples/openvino/test_examples.py b/examples/openvino/test_examples.py index ac6f5afe9b..a59b8b5690 100644 --- a/examples/openvino/test_examples.py +++ b/examples/openvino/test_examples.py @@ -17,6 +17,7 @@ import unittest from unittest.mock import patch + SRC_DIRS = [ os.path.join(os.path.dirname(__file__), dirname) for dirname in [ @@ -29,9 +30,9 @@ sys.path.extend(SRC_DIRS) if SRC_DIRS is not None: - import run_image_classification import run_audio_classification import run_glue + import run_image_classification import run_qa @@ -39,29 +40,29 @@ class TestExamples(unittest.TestCase): def test_audio_classification(self): with tempfile.TemporaryDirectory() as tmp_dir: test_args = f""" - run_audio_classification.py - --model_name_or_path hf-internal-testing/tiny-random-Wav2Vec2Model - --nncf_compression_config examples/openvino/audio-classification/configs/wav2vec2-base-qat.json - --dataset_name superb - --dataset_config_name ks - --max_train_samples 10 - --max_eval_samples 2 - --remove_unused_columns False - --do_train - --learning_rate 3e-5 - --max_length_seconds 1 - --attention_mask False - --warmup_ratio 0.1 - --num_train_epochs 1 - --gradient_accumulation_steps 1 - --dataloader_num_workers 1 - --logging_strategy steps - --logging_steps 1 - --evaluation_strategy epoch - --save_strategy epoch - --load_best_model_at_end False + run_audio_classification.py + --model_name_or_path hf-internal-testing/tiny-random-Wav2Vec2Model + --nncf_compression_config examples/openvino/audio-classification/configs/wav2vec2-base-qat.json + --dataset_name superb + --dataset_config_name ks + --max_train_samples 10 + --max_eval_samples 2 + --remove_unused_columns False + --do_train + --learning_rate 3e-5 + --max_length_seconds 1 + --attention_mask False + --warmup_ratio 0.1 + --num_train_epochs 1 + --gradient_accumulation_steps 1 + --dataloader_num_workers 1 + --logging_strategy steps + --logging_steps 1 + --evaluation_strategy epoch + --save_strategy epoch + --load_best_model_at_end False --seed 42 - --output_dir {tmp_dir} + --output_dir {tmp_dir} --overwrite_output_dir """.split() @@ -71,21 +72,21 @@ def test_audio_classification(self): def test_image_classification(self): with tempfile.TemporaryDirectory() as tmp_dir: test_args = f""" - run_image_classification.py - --model_name_or_path nateraw/vit-base-beans - --dataset_name beans - --max_train_samples 10 - --max_eval_samples 2 - --remove_unused_columns False + run_image_classification.py + --model_name_or_path nateraw/vit-base-beans + --dataset_name beans + --max_train_samples 10 + --max_eval_samples 2 + --remove_unused_columns False --do_train - --do_eval - --learning_rate 2e-5 - --num_train_epochs 1 - --logging_strategy steps - --logging_steps 1 - --evaluation_strategy epoch - --save_strategy epoch - --save_total_limit 1 + --do_eval + --learning_rate 2e-5 + --num_train_epochs 1 + --logging_strategy steps + --logging_steps 1 + --evaluation_strategy epoch + --save_strategy epoch + --save_total_limit 1 --seed 1337 --output_dir {tmp_dir} """.split() @@ -95,23 +96,23 @@ def test_image_classification(self): def test_text_classification(self): with tempfile.TemporaryDirectory() as tmp_dir: - test_args = f""" - run_glue.py - --model_name_or_path hf-internal-testing/tiny-random-DistilBertForSequenceClassification - --task_name sst2 - --max_train_samples 10 - --max_eval_samples 2 - --overwrite_output_dir + test_args = f""" + run_glue.py + --model_name_or_path hf-internal-testing/tiny-random-DistilBertForSequenceClassification + --task_name sst2 + --max_train_samples 10 + --max_eval_samples 2 + --overwrite_output_dir --do_train - --do_eval - --max_seq_length 128 - --learning_rate 1e-5 - --optim adamw_torch - --num_train_epochs 1 - --logging_steps 1 - --evaluation_strategy steps - --eval_steps 1 - --save_strategy epoch + --do_eval + --max_seq_length 128 + --learning_rate 1e-5 + --optim adamw_torch + --num_train_epochs 1 + --logging_steps 1 + --evaluation_strategy steps + --eval_steps 1 + --save_strategy epoch --seed 42 --output_dir {tmp_dir} """.split() @@ -122,17 +123,17 @@ def test_text_classification(self): def test_question_answering(self): with tempfile.TemporaryDirectory() as tmp_dir: test_args = f""" - run_qa.py - --model_name_or_path hf-internal-testing/tiny-random-DistilBertForQuestionAnswering - --dataset_name squad - --do_train - --do_eval - --max_train_samples 10 - --max_eval_samples 2 - --learning_rate 3e-5 - --num_train_epochs 1 - --max_seq_length 384 - --doc_stride 128 + run_qa.py + --model_name_or_path hf-internal-testing/tiny-random-DistilBertForQuestionAnswering + --dataset_name squad + --do_train + --do_eval + --max_train_samples 10 + --max_eval_samples 2 + --learning_rate 3e-5 + --num_train_epochs 1 + --max_seq_length 384 + --doc_stride 128 --overwrite_output_dir --output_dir {tmp_dir} """.split() @@ -142,4 +143,4 @@ def test_question_answering(self): if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main() diff --git a/notebooks/openvino/stable_diffusion_optimization.ipynb b/notebooks/openvino/stable_diffusion_optimization.ipynb index b44c00f78c..6c79bc5df0 100644 --- a/notebooks/openvino/stable_diffusion_optimization.ipynb +++ b/notebooks/openvino/stable_diffusion_optimization.ipynb @@ -69,9 +69,7 @@ "metadata": {}, "outputs": [], "source": [ - "quantized_pipe = OVStableDiffusionPipeline.from_pretrained(\n", - " \"OpenVINO/Stable-Diffusion-Pokemon-en-quantized\", compile=False\n", - ")\n", + "quantized_pipe = OVStableDiffusionPipeline.from_pretrained(\"OpenVINO/Stable-Diffusion-Pokemon-en-quantized\", compile=False)\n", "quantized_pipe.reshape(batch_size=1, height=512, width=512, num_images_per_prompt=1)\n", "quantized_pipe.compile()" ] @@ -104,9 +102,7 @@ "metadata": {}, "outputs": [], "source": [ - "optimized_pipe = OVStableDiffusionPipeline.from_pretrained(\n", - " \"OpenVINO/stable-diffusion-pokemons-tome-quantized\", compile=False\n", - ")\n", + "optimized_pipe = OVStableDiffusionPipeline.from_pretrained(\"OpenVINO/stable-diffusion-pokemons-tome-quantized\", compile=False)\n", "optimized_pipe.reshape(batch_size=1, height=512, width=512, num_images_per_prompt=1)\n", "optimized_pipe.compile()" ]