From 49949f321d9b034440b52e54937fd2df3027bf0a Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Wed, 28 Jun 2023 22:05:25 +0530 Subject: [PATCH] [Tests] add test for checking soft dependencies. (#3847) * add test for checking soft dependencies. * address patrick's comments. * dependency tests should not run twice. * debugging. * up. --- .github/workflows/pr_dependency_test.yml | 32 +++++++++++++++++++ .github/workflows/pr_tests.yml | 2 +- setup.py | 3 ++ src/diffusers/dependency_versions_table.py | 3 ++ tests/others/test_dependencies.py | 37 ++++++++++++++++++++++ 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pr_dependency_test.yml create mode 100644 tests/others/test_dependencies.py diff --git a/.github/workflows/pr_dependency_test.yml b/.github/workflows/pr_dependency_test.yml new file mode 100644 index 0000000000..baa83e20bf --- /dev/null +++ b/.github/workflows/pr_dependency_test.yml @@ -0,0 +1,32 @@ +name: Run dependency tests + +on: + pull_request: + branches: + - main + push: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + check_dependencies: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.7" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e . + pip install pytest + - name: Check for soft dependencies + run: | + pytest tests/others/test_dependencies.py + \ No newline at end of file diff --git a/.github/workflows/pr_tests.yml b/.github/workflows/pr_tests.yml index 162b1ba83d..88c424ee49 100644 --- a/.github/workflows/pr_tests.yml +++ b/.github/workflows/pr_tests.yml @@ -81,7 +81,7 @@ jobs: if: ${{ matrix.config.framework == 'pytorch_models' }} run: | python -m pytest -n 2 --max-worker-restart=0 --dist=loadfile \ - -s -v -k "not Flax and not Onnx" \ + -s -v -k "not Flax and not Onnx and not Dependency" \ --make-reports=tests_${{ matrix.config.report }} \ tests/models tests/schedulers tests/others diff --git a/setup.py b/setup.py index 9dab0b903f..d6b083c228 100644 --- a/setup.py +++ b/setup.py @@ -94,6 +94,8 @@ _deps = [ "jaxlib>=0.1.65", "Jinja2", "k-diffusion>=0.0.12", + "torchsde", + "note_seq", "librosa", "numpy", "omegaconf", @@ -106,6 +108,7 @@ _deps = [ "safetensors", "sentencepiece>=0.1.91,!=0.1.92", "scipy", + "onnx", "regex!=2019.12.17", "requests", "tensorboard", diff --git a/src/diffusers/dependency_versions_table.py b/src/diffusers/dependency_versions_table.py index 19a843470e..423d6c5347 100644 --- a/src/diffusers/dependency_versions_table.py +++ b/src/diffusers/dependency_versions_table.py @@ -18,6 +18,8 @@ deps = { "jaxlib": "jaxlib>=0.1.65", "Jinja2": "Jinja2", "k-diffusion": "k-diffusion>=0.0.12", + "torchsde": "torchsde", + "note_seq": "note_seq", "librosa": "librosa", "numpy": "numpy", "omegaconf": "omegaconf", @@ -30,6 +32,7 @@ deps = { "safetensors": "safetensors", "sentencepiece": "sentencepiece>=0.1.91,!=0.1.92", "scipy": "scipy", + "onnx": "onnx", "regex": "regex!=2019.12.17", "requests": "requests", "tensorboard": "tensorboard", diff --git a/tests/others/test_dependencies.py b/tests/others/test_dependencies.py new file mode 100644 index 0000000000..9bee7a0db3 --- /dev/null +++ b/tests/others/test_dependencies.py @@ -0,0 +1,37 @@ +# Copyright 2023 The HuggingFace Team. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import inspect +import unittest + + +class DependencyTester(unittest.TestCase): + def test_diffusers_import(self): + try: + import diffusers # noqa: F401 + except ImportError: + assert False + + def test_backend_registration(self): + import diffusers + from diffusers.dependency_versions_table import deps + + all_classes = inspect.getmembers(diffusers, inspect.isclass) + + for cls_name, cls_module in all_classes: + if "dummy_" in cls_module.__module__: + for backend in cls_module._backends: + if backend == "k_diffusion": + backend = "k-diffusion" + assert backend in deps, f"{backend} is not in the deps table!"