From 9b411418bb26f2a47ecae474e75886f6ea88cb4c Mon Sep 17 00:00:00 2001 From: Harish Subramony Date: Wed, 22 Jan 2025 11:42:19 -0800 Subject: [PATCH 1/2] disable timm models image_classification, add req installation for test_image_to_text_example --- examples/image-classification/requirements.txt | 3 --- tests/test_image_to_text_example.py | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/image-classification/requirements.txt b/examples/image-classification/requirements.txt index 4cbf42532d..1bae89f7ee 100644 --- a/examples/image-classification/requirements.txt +++ b/examples/image-classification/requirements.txt @@ -1,6 +1,3 @@ -torch>=1.5.0 -torchvision>=0.6.0 datasets>=2.14.0 evaluate scikit-learn == 1.5.2 -timm>=0.9.16 diff --git a/tests/test_image_to_text_example.py b/tests/test_image_to_text_example.py index 36143e8f91..e2ae05f3be 100644 --- a/tests/test_image_to_text_example.py +++ b/tests/test_image_to_text_example.py @@ -4,6 +4,7 @@ import subprocess from pathlib import Path from tempfile import TemporaryDirectory +from typing import Callable, Union import pytest @@ -44,6 +45,18 @@ "fp8": [], } +def install_requirements(requirements_filename: Union[str, os.PathLike]): + """ + Installs the necessary requirements to run the example if the provided file exists, otherwise does nothing. + """ + + if not Path(requirements_filename).exists(): + return + + cmd_line = f"pip install -r {requirements_filename}".split() + p = subprocess.Popen(cmd_line) + return_code = p.wait() + assert return_code == 0 def _test_image_to_text( model_name: str, @@ -55,6 +68,7 @@ def _test_image_to_text( command = ["python3"] path_to_example_dir = Path(__file__).resolve().parent.parent / "examples" env_variables = os.environ.copy() + install_requirements(path_to_example_dir / 'image-to-text/requirements.txt') command += [ f"{path_to_example_dir / 'image-to-text' / 'run_pipeline.py'}", From b2f58c65a72efd92ba850d992e4edf1f96a4e829 Mon Sep 17 00:00:00 2001 From: Harish Subramony Date: Wed, 22 Jan 2025 12:57:10 -0800 Subject: [PATCH 2/2] add requirements.txt for no-deps for timm and open-clip packages --- examples/image-classification/README.md | 4 ++++ examples/image-classification/requirements_no_deps.txt | 1 + examples/visual-question-answering/README.md | 8 ++++++-- .../openclip_requirements.txt | 3 +-- examples/visual-question-answering/requirements.txt | 2 ++ tests/test_openclip_vqa.py | 10 +++++++++- 6 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 examples/image-classification/requirements_no_deps.txt create mode 100644 examples/visual-question-answering/requirements.txt diff --git a/examples/image-classification/README.md b/examples/image-classification/README.md index 01b19b25ba..009de15e10 100644 --- a/examples/image-classification/README.md +++ b/examples/image-classification/README.md @@ -309,6 +309,10 @@ python run_image_classification.py \ This directory contains an example script that demonstrates using FastViT with graph mode. +```bash +pip install --no-deps -r requirements_no_deps.txt +``` + ### Single-HPU inference ```bash diff --git a/examples/image-classification/requirements_no_deps.txt b/examples/image-classification/requirements_no_deps.txt new file mode 100644 index 0000000000..281c8ae93a --- /dev/null +++ b/examples/image-classification/requirements_no_deps.txt @@ -0,0 +1 @@ +timm diff --git a/examples/visual-question-answering/README.md b/examples/visual-question-answering/README.md index 36f81e481b..c03439b4a3 100644 --- a/examples/visual-question-answering/README.md +++ b/examples/visual-question-answering/README.md @@ -16,6 +16,10 @@ limitations under the License. # Visual Question Answering Examples +```bash +pip install -r requirements.txt +``` + ## Single-HPU inference The `run_pipeline.py` script showcases how to use the Transformers pipeline API to run visual question answering task on HPUs. @@ -34,7 +38,7 @@ The `run_openclip_vqa.py` can be used to run zero shot image classification with The requirements for `run_openclip_vqa.py` can be installed with `openclip_requirements.txt` as follows: ```bash -pip install -r openclip_requirements.txt +pip install --no-deps -r openclip_requirements.txt ``` By default, the script runs the sample outlined in [BiomedCLIP-PubMedBERT_256-vit_base_patch16_224 notebook](https://huggingface.co/microsoft/BiomedCLIP-PubMedBERT_256-vit_base_patch16_224/blob/main/biomed_clip_example.ipynb). One can also can also run other OpenCLIP models by specifying model, classifier labels and image URL(s) like so: @@ -46,4 +50,4 @@ python run_openclip_vqa.py \ --image_path "http://images.cocodataset.org/val2017/000000039769.jpg" \ --use_hpu_graphs \ --bf16 -``` \ No newline at end of file +``` diff --git a/examples/visual-question-answering/openclip_requirements.txt b/examples/visual-question-answering/openclip_requirements.txt index c132e5eb90..266ff40ac3 100644 --- a/examples/visual-question-answering/openclip_requirements.txt +++ b/examples/visual-question-answering/openclip_requirements.txt @@ -1,3 +1,2 @@ open_clip_torch==2.23.0 -matplotlib - +timm diff --git a/examples/visual-question-answering/requirements.txt b/examples/visual-question-answering/requirements.txt new file mode 100644 index 0000000000..23cc98f2ae --- /dev/null +++ b/examples/visual-question-answering/requirements.txt @@ -0,0 +1,2 @@ +matplotlib +ftfy diff --git a/tests/test_openclip_vqa.py b/tests/test_openclip_vqa.py index c0c3d38521..04be46cefc 100644 --- a/tests/test_openclip_vqa.py +++ b/tests/test_openclip_vqa.py @@ -30,8 +30,16 @@ def _install_requirements(): PATH_TO_EXAMPLE_DIR = Path(__file__).resolve().parent.parent / "examples" + + cmd_line = ( + f"pip install -r {PATH_TO_EXAMPLE_DIR / 'visual-question-answering' / 'requirements.txt'}".split() + ) + p = subprocess.Popen(cmd_line) + return_code = p.wait() + assert return_code == 0 + cmd_line = ( - f"pip install -r {PATH_TO_EXAMPLE_DIR / 'visual-question-answering' / 'openclip_requirements.txt'}".split() + f"pip install --no-deps -r {PATH_TO_EXAMPLE_DIR / 'visual-question-answering' / 'openclip_requirements.txt'}".split() ) p = subprocess.Popen(cmd_line) return_code = p.wait()