From 590d53148444efec531624c576dfdaf413ad4e24 Mon Sep 17 00:00:00 2001 From: "wenmeng.zwm" Date: Thu, 28 Jul 2022 22:04:18 +0800 Subject: [PATCH] [to #43115513] requirements refine and preparation for v0.3 release * remove tensorflow numpy from audio requirements * add audio requirements to all * auto set model to eval model for pipeline * add audio requirement check hint for easyasr and kwsbp * fix docs build error Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9561021 --- docs/source/conf.py | 4 ++-- modelscope/pipelines/base.py | 2 ++ modelscope/utils/import_utils.py | 8 +++++++- requirements/audio.txt | 7 ++----- requirements/cv.txt | 1 + requirements/docs.txt | 1 + requirements/runtime.txt | 4 ++-- setup.py | 5 +---- 8 files changed, 18 insertions(+), 14 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index d41c3cd6..39e0d881 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -13,7 +13,7 @@ import os import sys -import sphinx_rtd_theme +import sphinx_book_theme sys.path.insert(0, os.path.abspath('../../')) # -- Project information ----------------------------------------------------- @@ -77,7 +77,7 @@ exclude_patterns = ['build', 'Thumbs.db', '.DS_Store'] # a list of builtin themes. # html_theme = 'sphinx_book_theme' -html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] +html_theme_path = [sphinx_book_theme.get_html_theme_path()] html_theme_options = {} # Add any paths that contain custom static files (such as style sheets) here, diff --git a/modelscope/pipelines/base.py b/modelscope/pipelines/base.py index 6e2d6bc7..8faf8691 100644 --- a/modelscope/pipelines/base.py +++ b/modelscope/pipelines/base.py @@ -105,9 +105,11 @@ class Pipeline(ABC): def _prepare_single(model): if isinstance(model, torch.nn.Module): model.to(self.device) + model.eval() elif hasattr(model, 'model') and isinstance( model.model, torch.nn.Module): model.model.to(self.device) + model.model.eval() if not self._model_prepare: # prepare model for pytorch diff --git a/modelscope/utils/import_utils.py b/modelscope/utils/import_utils.py index 09956fdb..82f4e0ef 100644 --- a/modelscope/utils/import_utils.py +++ b/modelscope/utils/import_utils.py @@ -256,10 +256,14 @@ def is_pillow_available(): return importlib.util.find_spec('PIL.Image') is not None -def is_package_available(pkg_name): +def _is_package_available_fn(pkg_name): return importlib.util.find_spec(pkg_name) is not None +def is_package_available(pkg_name): + return functools.partial(_is_package_available_fn, pkg_name) + + def is_espnet_available(pkg_name): return importlib.util.find_spec('espnet2') is not None \ and importlib.util.find_spec('espnet') @@ -282,6 +286,8 @@ REQUIREMENTS_MAAPING = OrderedDict([ GENERAL_IMPORT_ERROR.replace('REQ', 'espnet'))), ('espnet', (is_espnet_available, GENERAL_IMPORT_ERROR.replace('REQ', 'espnet'))), + ('easyasr', (is_package_available('easyasr'), AUDIO_IMPORT_ERROR)), + ('kwsbp', (is_package_available('kwsbp'), AUDIO_IMPORT_ERROR)) ]) SYSTEM_PACKAGE = set(['os', 'sys', 'typing']) diff --git a/requirements/audio.txt b/requirements/audio.txt index f6f03adc..b1d9e2c3 100644 --- a/requirements/audio.txt +++ b/requirements/audio.txt @@ -10,7 +10,8 @@ lxml matplotlib nara_wpe nltk -numpy<=1.18 +# numpy requirements should be declared with tensorflow 1.15 but not here +# numpy<=1.18 # protobuf version beyond 3.20.0 is not compatible with TensorFlow 1.x, therefore is discouraged. protobuf>3,<3.21.0 ptflops @@ -19,11 +20,7 @@ PyWavelets>=1.0.0 scikit-learn SoundFile>0.10 sox -tensorboard -tensorflow==1.15.* -torch torchaudio -torchvision tqdm ttsfrd>=0.0.3 unidecode diff --git a/requirements/cv.txt b/requirements/cv.txt index 513dae99..521ab34f 100644 --- a/requirements/cv.txt +++ b/requirements/cv.txt @@ -1,3 +1,4 @@ decord>=0.6.0 easydict tf_slim +torchvision diff --git a/requirements/docs.txt b/requirements/docs.txt index aa5ca594..f51d1565 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -1,4 +1,5 @@ docutils>=0.16.0 +myst_parser recommonmark sphinx>=4.0.2 sphinx-book-theme diff --git a/requirements/runtime.txt b/requirements/runtime.txt index 3cfb44f2..0542dc92 100644 --- a/requirements/runtime.txt +++ b/requirements/runtime.txt @@ -3,7 +3,7 @@ datasets easydict einops filelock>=3.3.0 -gast>=0.5.3 +gast>=0.2.2 numpy opencv-python Pillow>=6.2.0 @@ -11,8 +11,8 @@ pyyaml requests scipy setuptools +tensorboard tokenizers -torch tqdm>=4.64.0 transformers>=4.10.3 yapf diff --git a/setup.py b/setup.py index 8111829f..2a551fb7 100644 --- a/setup.py +++ b/setup.py @@ -178,11 +178,8 @@ if __name__ == '__main__': continue extra_requires[field], _ = parse_requirements( f'requirements/{field}.txt') + all_requires.extend(extra_requires[field]) - # skip audio requirements due to its hard dependency which - # result in mac/windows compatibility problems - if field != Fields.audio: - all_requires.append(extra_requires[field]) extra_requires['all'] = all_requires setup(