From cfb53876979b51ac12ae755d2487355569db6ff8 Mon Sep 17 00:00:00 2001 From: uakarsh <55104596+uakarsh@users.noreply.github.com> Date: Sat, 17 Sep 2022 13:09:31 +0530 Subject: [PATCH 01/17] Removed the functions that are integrated in lightning_utilities --- flash/core/utilities/imports.py | 51 ++------------------------------- 1 file changed, 3 insertions(+), 48 deletions(-) diff --git a/flash/core/utilities/imports.py b/flash/core/utilities/imports.py index adbc9e6264..aef7ff1962 100644 --- a/flash/core/utilities/imports.py +++ b/flash/core/utilities/imports.py @@ -21,59 +21,14 @@ import pkg_resources from pkg_resources import DistributionNotFound +from lightning_utilities.core.imports import module_available as _module_available +from lightning_utilities.core.imports import compare_version as _compare_version try: from packaging.version import Version except (ModuleNotFoundError, DistributionNotFound): Version = None - - -def _module_available(module_path: str) -> bool: - """Check if a path is available in your environment. - - >>> _module_available('os') - True - >>> _module_available('bla.bla') - False - """ - try: - return find_spec(module_path) is not None - except AttributeError: - # Python 3.6 - return False - except ModuleNotFoundError: - # Python 3.7+ - return False - except ValueError: - # Sometimes __spec__ can be None and gives a ValueError - return True - - -def _compare_version(package: str, op: Callable, version: str, use_base_version: bool = False) -> bool: - """Compare package version with some requirements. - - >>> _compare_version("torch", operator.ge, "0.1") - True - >>> _compare_version("does_not_exist", operator.ge, "0.0") - False - """ - try: - pkg = importlib.import_module(package) - except (ImportError, DistributionNotFound): - return False - try: - if hasattr(pkg, "__version__"): - pkg_version = Version(pkg.__version__) - else: - # try pkg_resources to infer version - pkg_version = Version(pkg_resources.get_distribution(package).version) - except TypeError: - # this is mocked by Sphinx, so it should return True to generate all summaries - return True - if use_base_version: - pkg_version = Version(pkg_version.base_version) - return op(pkg_version, Version(version)) - + _TORCH_AVAILABLE = _module_available("torch") _PL_AVAILABLE = _module_available("pytorch_lightning") From eade3fdd742d9891e4a1a6d866aa7a7016ddb21a Mon Sep 17 00:00:00 2001 From: uakarsh <55104596+uakarsh@users.noreply.github.com> Date: Sat, 17 Sep 2022 13:26:01 +0530 Subject: [PATCH 02/17] imort of `is_overriden` method from `lightning_utilities` --- flash/core/utilities/apply_func.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flash/core/utilities/apply_func.py b/flash/core/utilities/apply_func.py index 759d3c3e95..d742938361 100644 --- a/flash/core/utilities/apply_func.py +++ b/flash/core/utilities/apply_func.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. from typing import Callable, Dict, Mapping, Sequence, Type, Union - +from lightning_utilities.core.overrides import is_overridden from torch import nn @@ -37,5 +37,5 @@ def _is_overridden(method_name: str, instance: object, parent: Type[object]) -> if not hasattr(instance, method_name): return False - - return getattr(instance, method_name).__code__ != getattr(parent, method_name).__code__ + + return is_overridden(method_name, instance, parent) \ No newline at end of file From 8eb4c870b4746e4cab4cea35163f058748f8a3d5 Mon Sep 17 00:00:00 2001 From: uakarsh <55104596+uakarsh@users.noreply.github.com> Date: Sat, 17 Sep 2022 13:26:01 +0530 Subject: [PATCH 03/17] import of `is_overriden` method from `lightning_utilities` --- flash/core/utilities/apply_func.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flash/core/utilities/apply_func.py b/flash/core/utilities/apply_func.py index 759d3c3e95..d742938361 100644 --- a/flash/core/utilities/apply_func.py +++ b/flash/core/utilities/apply_func.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. from typing import Callable, Dict, Mapping, Sequence, Type, Union - +from lightning_utilities.core.overrides import is_overridden from torch import nn @@ -37,5 +37,5 @@ def _is_overridden(method_name: str, instance: object, parent: Type[object]) -> if not hasattr(instance, method_name): return False - - return getattr(instance, method_name).__code__ != getattr(parent, method_name).__code__ + + return is_overridden(method_name, instance, parent) \ No newline at end of file From 3f8976654603a22409fbadf810b062789fb05731 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 17 Sep 2022 08:00:43 +0000 Subject: [PATCH 04/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- flash/core/utilities/apply_func.py | 5 +++-- flash/core/utilities/imports.py | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/flash/core/utilities/apply_func.py b/flash/core/utilities/apply_func.py index d742938361..4356bb0ad5 100644 --- a/flash/core/utilities/apply_func.py +++ b/flash/core/utilities/apply_func.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. from typing import Callable, Dict, Mapping, Sequence, Type, Union + from lightning_utilities.core.overrides import is_overridden from torch import nn @@ -37,5 +38,5 @@ def _is_overridden(method_name: str, instance: object, parent: Type[object]) -> if not hasattr(instance, method_name): return False - - return is_overridden(method_name, instance, parent) \ No newline at end of file + + return is_overridden(method_name, instance, parent) diff --git a/flash/core/utilities/imports.py b/flash/core/utilities/imports.py index aef7ff1962..5f81bf1c82 100644 --- a/flash/core/utilities/imports.py +++ b/flash/core/utilities/imports.py @@ -20,15 +20,15 @@ from typing import Callable, List, Tuple, Union import pkg_resources -from pkg_resources import DistributionNotFound -from lightning_utilities.core.imports import module_available as _module_available from lightning_utilities.core.imports import compare_version as _compare_version +from lightning_utilities.core.imports import module_available as _module_available +from pkg_resources import DistributionNotFound try: from packaging.version import Version except (ModuleNotFoundError, DistributionNotFound): Version = None - + _TORCH_AVAILABLE = _module_available("torch") _PL_AVAILABLE = _module_available("pytorch_lightning") From a19beac232ba671af5dea78dd54fd2e537daa277 Mon Sep 17 00:00:00 2001 From: uakarsh <55104596+uakarsh@users.noreply.github.com> Date: Sat, 17 Sep 2022 13:35:11 +0530 Subject: [PATCH 05/17] Added `lightning_utilties` --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 6230dcff95..94cb2ab62d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,3 +10,4 @@ jsonargparse[signatures]>=3.17.0, <=4.9.0 click>=7.1.2 protobuf<=3.20.1 fsspec +lightning_utilities From 6b0d99621f9917453995d9c607ba9054d28f881e Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Sat, 24 Sep 2022 00:17:19 +0200 Subject: [PATCH 06/17] Apply suggestions from code review Co-authored-by: Kushashwa Ravi Shrimali --- flash/core/utilities/imports.py | 12 ++++++------ requirements.txt | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/flash/core/utilities/imports.py b/flash/core/utilities/imports.py index 5f81bf1c82..fb4bb3f03c 100644 --- a/flash/core/utilities/imports.py +++ b/flash/core/utilities/imports.py @@ -17,11 +17,11 @@ import os import types from importlib.util import find_spec -from typing import Callable, List, Tuple, Union +from typing import List, Tuple, Union import pkg_resources -from lightning_utilities.core.imports import compare_version as _compare_version -from lightning_utilities.core.imports import module_available as _module_available +from lightning_utilities.core.imports import compare_version +from lightning_utilities.core.imports import module_available from pkg_resources import DistributionNotFound try: @@ -30,9 +30,9 @@ Version = None -_TORCH_AVAILABLE = _module_available("torch") -_PL_AVAILABLE = _module_available("pytorch_lightning") -_BOLTS_AVAILABLE = _module_available("pl_bolts") and _compare_version("torch", operator.lt, "1.9.0") +_TORCH_AVAILABLE = module_available("torch") +_PL_AVAILABLE = module_available("pytorch_lightning") +_BOLTS_AVAILABLE = module_available("pl_bolts") and compare_version("torch", operator.lt, "1.9.0") _PANDAS_AVAILABLE = _module_available("pandas") _SKLEARN_AVAILABLE = _module_available("sklearn") _PYTORCHTABULAR_AVAILABLE = _module_available("pytorch_tabular") diff --git a/requirements.txt b/requirements.txt index 94cb2ab62d..6393bec225 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,4 @@ jsonargparse[signatures]>=3.17.0, <=4.9.0 click>=7.1.2 protobuf<=3.20.1 fsspec -lightning_utilities +lightning_utilities>=0.3.0 From 532fd2f0b4311d6be09736625d74c86f33738b41 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 23 Sep 2022 22:17:58 +0000 Subject: [PATCH 07/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- flash/core/utilities/imports.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flash/core/utilities/imports.py b/flash/core/utilities/imports.py index fb4bb3f03c..1ceea00e2d 100644 --- a/flash/core/utilities/imports.py +++ b/flash/core/utilities/imports.py @@ -20,8 +20,7 @@ from typing import List, Tuple, Union import pkg_resources -from lightning_utilities.core.imports import compare_version -from lightning_utilities.core.imports import module_available +from lightning_utilities.core.imports import compare_version, module_available from pkg_resources import DistributionNotFound try: From 980c1e08ce52237c533aca21848d9ff912b5e8fa Mon Sep 17 00:00:00 2001 From: uakarsh <55104596+uakarsh@users.noreply.github.com> Date: Sat, 24 Sep 2022 17:56:50 +0530 Subject: [PATCH 08/17] Some updates from suggestion 1. Kept the import name of "module_available" and "compare_version" as it is 2. Removed the unused imports in the apply_func 3. "is_overridden" is used for "_is_overridden" in apply_func.py file --- flash/core/utilities/apply_func.py | 8 +- flash/core/utilities/imports.py | 116 +++++++++--------- flash/image/detection/backbones.py | 8 +- .../image/instance_segmentation/backbones.py | 4 +- 4 files changed, 64 insertions(+), 72 deletions(-) diff --git a/flash/core/utilities/apply_func.py b/flash/core/utilities/apply_func.py index 4356bb0ad5..2412770503 100644 --- a/flash/core/utilities/apply_func.py +++ b/flash/core/utilities/apply_func.py @@ -33,10 +33,4 @@ def get_callable_dict(fn: Union[nn.Module, Callable, Mapping, Sequence]) -> Unio def _is_overridden(method_name: str, instance: object, parent: Type[object]) -> bool: - """Cropped Version of https://github.com/Lightning- - AI/lightning/blob/master/src/pytorch_lightning/utilities/model_helpers.py.""" - - if not hasattr(instance, method_name): - return False - - return is_overridden(method_name, instance, parent) + return is_overridden(method_name, instance, parent) \ No newline at end of file diff --git a/flash/core/utilities/imports.py b/flash/core/utilities/imports.py index 5f81bf1c82..4a3153c222 100644 --- a/flash/core/utilities/imports.py +++ b/flash/core/utilities/imports.py @@ -16,12 +16,10 @@ import operator import os import types -from importlib.util import find_spec -from typing import Callable, List, Tuple, Union +from typing import List, Tuple, Union -import pkg_resources -from lightning_utilities.core.imports import compare_version as _compare_version -from lightning_utilities.core.imports import module_available as _module_available +from lightning_utilities.core.imports import compare_version +from lightning_utilities.core.imports import module_available from pkg_resources import DistributionNotFound try: @@ -30,50 +28,50 @@ Version = None -_TORCH_AVAILABLE = _module_available("torch") -_PL_AVAILABLE = _module_available("pytorch_lightning") -_BOLTS_AVAILABLE = _module_available("pl_bolts") and _compare_version("torch", operator.lt, "1.9.0") -_PANDAS_AVAILABLE = _module_available("pandas") -_SKLEARN_AVAILABLE = _module_available("sklearn") -_PYTORCHTABULAR_AVAILABLE = _module_available("pytorch_tabular") -_FORECASTING_AVAILABLE = _module_available("pytorch_forecasting") -_KORNIA_AVAILABLE = _module_available("kornia") -_COCO_AVAILABLE = _module_available("pycocotools") -_TIMM_AVAILABLE = _module_available("timm") -_TORCHVISION_AVAILABLE = _module_available("torchvision") -_PYTORCHVIDEO_AVAILABLE = _module_available("pytorchvideo") -_MATPLOTLIB_AVAILABLE = _module_available("matplotlib") -_TRANSFORMERS_AVAILABLE = _module_available("transformers") -_PYSTICHE_AVAILABLE = _module_available("pystiche") -_FIFTYONE_AVAILABLE = _module_available("fiftyone") -_FASTAPI_AVAILABLE = _module_available("fastapi") -_PYDANTIC_AVAILABLE = _module_available("pydantic") -_GRAPHVIZ_AVAILABLE = _module_available("graphviz") -_CYTOOLZ_AVAILABLE = _module_available("cytoolz") -_UVICORN_AVAILABLE = _module_available("uvicorn") -_PIL_AVAILABLE = _module_available("PIL") -_OPEN3D_AVAILABLE = _module_available("open3d") -_SEGMENTATION_MODELS_AVAILABLE = _module_available("segmentation_models_pytorch") -_FASTFACE_AVAILABLE = _module_available("fastface") and _compare_version("pytorch_lightning", operator.lt, "1.5.0") -_LIBROSA_AVAILABLE = _module_available("librosa") -_TORCH_SCATTER_AVAILABLE = _module_available("torch_scatter") -_TORCH_SPARSE_AVAILABLE = _module_available("torch_sparse") -_TORCH_GEOMETRIC_AVAILABLE = _module_available("torch_geometric") -_NETWORKX_AVAILABLE = _module_available("networkx") -_TORCHAUDIO_AVAILABLE = _module_available("torchaudio") -_SENTENCEPIECE_AVAILABLE = _module_available("sentencepiece") -_DATASETS_AVAILABLE = _module_available("datasets") -_TM_TEXT_AVAILABLE: bool = _module_available("torchmetrics.text") -_ICEVISION_AVAILABLE = _module_available("icevision") -_ICEDATA_AVAILABLE = _module_available("icedata") -_LEARN2LEARN_AVAILABLE = _module_available("learn2learn") and _compare_version("learn2learn", operator.ge, "0.1.6") -_TORCH_ORT_AVAILABLE = _module_available("torch_ort") -_VISSL_AVAILABLE = _module_available("vissl") and _module_available("classy_vision") -_ALBUMENTATIONS_AVAILABLE = _module_available("albumentations") -_BAAL_AVAILABLE = _module_available("baal") -_TORCH_OPTIMIZER_AVAILABLE = _module_available("torch_optimizer") -_SENTENCE_TRANSFORMERS_AVAILABLE = _module_available("sentence_transformers") -_DEEPSPEED_AVAILABLE = _module_available("deepspeed") +_TORCH_AVAILABLE = module_available("torch") +_PL_AVAILABLE = module_available("pytorch_lightning") +_BOLTS_AVAILABLE = module_available("pl_bolts") and compare_version("torch", operator.lt, "1.9.0") +_PANDAS_AVAILABLE = module_available("pandas") +_SKLEARN_AVAILABLE = module_available("sklearn") +_PYTORCHTABULAR_AVAILABLE = module_available("pytorch_tabular") +_FORECASTING_AVAILABLE = module_available("pytorch_forecasting") +_KORNIA_AVAILABLE = module_available("kornia") +_COCO_AVAILABLE = module_available("pycocotools") +_TIMM_AVAILABLE = module_available("timm") +_TORCHVISION_AVAILABLE = module_available("torchvision") +_PYTORCHVIDEO_AVAILABLE = module_available("pytorchvideo") +_MATPLOTLIB_AVAILABLE = module_available("matplotlib") +_TRANSFORMERS_AVAILABLE = module_available("transformers") +_PYSTICHE_AVAILABLE = module_available("pystiche") +_FIFTYONE_AVAILABLE = module_available("fiftyone") +_FASTAPI_AVAILABLE = module_available("fastapi") +_PYDANTIC_AVAILABLE = module_available("pydantic") +_GRAPHVIZ_AVAILABLE = module_available("graphviz") +_CYTOOLZ_AVAILABLE = module_available("cytoolz") +_UVICORN_AVAILABLE = module_available("uvicorn") +_PIL_AVAILABLE = module_available("PIL") +_OPEN3D_AVAILABLE = module_available("open3d") +_SEGMENTATION_MODELS_AVAILABLE = module_available("segmentation_models_pytorch") +_FASTFACE_AVAILABLE = module_available("fastface") and compare_version("pytorch_lightning", operator.lt, "1.5.0") +_LIBROSA_AVAILABLE = module_available("librosa") +_TORCH_SCATTER_AVAILABLE = module_available("torch_scatter") +_TORCH_SPARSE_AVAILABLE = module_available("torch_sparse") +_TORCH_GEOMETRIC_AVAILABLE = module_available("torch_geometric") +_NETWORKX_AVAILABLE = module_available("networkx") +_TORCHAUDIO_AVAILABLE = module_available("torchaudio") +_SENTENCEPIECE_AVAILABLE = module_available("sentencepiece") +_DATASETS_AVAILABLE = module_available("datasets") +_TM_TEXT_AVAILABLE: bool = module_available("torchmetrics.text") +_ICEVISION_AVAILABLE = module_available("icevision") +_ICEDATA_AVAILABLE = module_available("icedata") +_LEARN2LEARN_AVAILABLE = module_available("learn2learn") and compare_version("learn2learn", operator.ge, "0.1.6") +_TORCH_ORT_AVAILABLE = module_available("torch_ort") +_VISSL_AVAILABLE = module_available("vissl") and module_available("classy_vision") +_ALBUMENTATIONS_AVAILABLE = module_available("albumentations") +_BAAL_AVAILABLE = module_available("baal") +_TORCH_OPTIMIZER_AVAILABLE = module_available("torch_optimizer") +_SENTENCE_TRANSFORMERS_AVAILABLE = module_available("sentence_transformers") +_DEEPSPEED_AVAILABLE = module_available("deepspeed") if _PIL_AVAILABLE: @@ -85,15 +83,15 @@ class Image: if Version: - _TORCHVISION_GREATER_EQUAL_0_9 = _compare_version("torchvision", operator.ge, "0.9.0") - _PL_GREATER_EQUAL_1_4_3 = _compare_version("pytorch_lightning", operator.ge, "1.4.3") - _PL_GREATER_EQUAL_1_4_0 = _compare_version("pytorch_lightning", operator.ge, "1.4.0") - _PL_GREATER_EQUAL_1_5_0 = _compare_version("pytorch_lightning", operator.ge, "1.5.0") - _PL_GREATER_EQUAL_1_6_0 = _compare_version("pytorch_lightning", operator.ge, "1.6.0rc0") - _PANDAS_GREATER_EQUAL_1_3_0 = _compare_version("pandas", operator.ge, "1.3.0") - _ICEVISION_GREATER_EQUAL_0_11_0 = _compare_version("icevision", operator.ge, "0.11.0") - _TM_GREATER_EQUAL_0_7_0 = _compare_version("torchmetrics", operator.ge, "0.7.0") - _BAAL_GREATER_EQUAL_1_5_2 = _compare_version("baal", operator.ge, "1.5.2") + _TORCHVISION_GREATER_EQUAL_0_9 = compare_version("torchvision", operator.ge, "0.9.0") + _PL_GREATER_EQUAL_1_4_3 = compare_version("pytorch_lightning", operator.ge, "1.4.3") + _PL_GREATER_EQUAL_1_4_0 = compare_version("pytorch_lightning", operator.ge, "1.4.0") + _PL_GREATER_EQUAL_1_5_0 = compare_version("pytorch_lightning", operator.ge, "1.5.0") + _PL_GREATER_EQUAL_1_6_0 = compare_version("pytorch_lightning", operator.ge, "1.6.0rc0") + _PANDAS_GREATER_EQUAL_1_3_0 = compare_version("pandas", operator.ge, "1.3.0") + _ICEVISION_GREATER_EQUAL_0_11_0 = compare_version("icevision", operator.ge, "0.11.0") + _TM_GREATER_EQUAL_0_7_0 = compare_version("torchmetrics", operator.ge, "0.7.0") + _BAAL_GREATER_EQUAL_1_5_2 = compare_version("baal", operator.ge, "1.5.2") _TEXT_AVAILABLE = all( [ @@ -148,7 +146,7 @@ def decorator(func): available = False else: modules.append(module_path) - if not _module_available(module_path): + if not module_available(module_path): available = False else: available, module_path = module_path diff --git a/flash/image/detection/backbones.py b/flash/image/detection/backbones.py index 7b5d37dfc3..73aad6146c 100644 --- a/flash/image/detection/backbones.py +++ b/flash/image/detection/backbones.py @@ -23,7 +23,7 @@ ) from flash.core.model import Task from flash.core.registry import FlashRegistry -from flash.core.utilities.imports import _ICEVISION_AVAILABLE, _module_available, _TORCHVISION_AVAILABLE +from flash.core.utilities.imports import _ICEVISION_AVAILABLE, module_available, _TORCHVISION_AVAILABLE from flash.core.utilities.providers import _EFFDET, _ICEVISION, _MMDET, _TORCHVISION, _ULTRALYTICS if _ICEVISION_AVAILABLE: @@ -75,7 +75,7 @@ def from_task( providers=[_ICEVISION, _TORCHVISION], ) - if _module_available("yolov5"): + if module_available("yolov5"): model_type = icevision_models.ultralytics.yolov5 OBJECT_DETECTION_HEADS( partial(load_icevision_with_image_size, model_type), @@ -85,7 +85,7 @@ def from_task( providers=[_ICEVISION, _ULTRALYTICS], ) - if _module_available("mmdet"): + if module_available("mmdet"): for model_type in [ icevision_models.mmdet.faster_rcnn, icevision_models.mmdet.retinanet, @@ -100,7 +100,7 @@ def from_task( providers=[_ICEVISION, _MMDET], ) - if _module_available("effdet"): + if module_available("effdet"): model_type = icevision_models.ross.efficientdet OBJECT_DETECTION_HEADS( diff --git a/flash/image/instance_segmentation/backbones.py b/flash/image/instance_segmentation/backbones.py index 0478bce1d5..2add071685 100644 --- a/flash/image/instance_segmentation/backbones.py +++ b/flash/image/instance_segmentation/backbones.py @@ -19,7 +19,7 @@ from flash.core.integrations.icevision.backbones import get_backbones, load_icevision_ignore_image_size from flash.core.model import Task from flash.core.registry import FlashRegistry -from flash.core.utilities.imports import _ICEVISION_AVAILABLE, _module_available, _TORCHVISION_AVAILABLE +from flash.core.utilities.imports import _ICEVISION_AVAILABLE, module_available, _TORCHVISION_AVAILABLE from flash.core.utilities.providers import _ICEVISION, _MMDET, _TORCHVISION if _ICEVISION_AVAILABLE: @@ -71,7 +71,7 @@ def from_task( providers=[_ICEVISION, _TORCHVISION], ) - if _module_available("mmdet"): + if module_available("mmdet"): model_type = icevision_models.mmdet.mask_rcnn INSTANCE_SEGMENTATION_HEADS( partial(load_icevision_ignore_image_size, model_type), From d345d96aa7a1cb2b58cdb5d9186f1e1a32d6b156 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 24 Sep 2022 12:31:32 +0000 Subject: [PATCH 09/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- flash/core/utilities/apply_func.py | 2 +- flash/core/utilities/imports.py | 3 +-- flash/image/detection/backbones.py | 2 +- flash/image/instance_segmentation/backbones.py | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/flash/core/utilities/apply_func.py b/flash/core/utilities/apply_func.py index 2412770503..af5435fdd5 100644 --- a/flash/core/utilities/apply_func.py +++ b/flash/core/utilities/apply_func.py @@ -33,4 +33,4 @@ def get_callable_dict(fn: Union[nn.Module, Callable, Mapping, Sequence]) -> Unio def _is_overridden(method_name: str, instance: object, parent: Type[object]) -> bool: - return is_overridden(method_name, instance, parent) \ No newline at end of file + return is_overridden(method_name, instance, parent) diff --git a/flash/core/utilities/imports.py b/flash/core/utilities/imports.py index 525f19c91c..7813171aef 100644 --- a/flash/core/utilities/imports.py +++ b/flash/core/utilities/imports.py @@ -19,8 +19,7 @@ from typing import List, Tuple, Union import pkg_resources -from lightning_utilities.core.imports import compare_version -from lightning_utilities.core.imports import module_available +from lightning_utilities.core.imports import compare_version, module_available from pkg_resources import DistributionNotFound try: diff --git a/flash/image/detection/backbones.py b/flash/image/detection/backbones.py index 73aad6146c..753f03018f 100644 --- a/flash/image/detection/backbones.py +++ b/flash/image/detection/backbones.py @@ -23,7 +23,7 @@ ) from flash.core.model import Task from flash.core.registry import FlashRegistry -from flash.core.utilities.imports import _ICEVISION_AVAILABLE, module_available, _TORCHVISION_AVAILABLE +from flash.core.utilities.imports import _ICEVISION_AVAILABLE, _TORCHVISION_AVAILABLE, module_available from flash.core.utilities.providers import _EFFDET, _ICEVISION, _MMDET, _TORCHVISION, _ULTRALYTICS if _ICEVISION_AVAILABLE: diff --git a/flash/image/instance_segmentation/backbones.py b/flash/image/instance_segmentation/backbones.py index 2add071685..c0e08cef0d 100644 --- a/flash/image/instance_segmentation/backbones.py +++ b/flash/image/instance_segmentation/backbones.py @@ -19,7 +19,7 @@ from flash.core.integrations.icevision.backbones import get_backbones, load_icevision_ignore_image_size from flash.core.model import Task from flash.core.registry import FlashRegistry -from flash.core.utilities.imports import _ICEVISION_AVAILABLE, module_available, _TORCHVISION_AVAILABLE +from flash.core.utilities.imports import _ICEVISION_AVAILABLE, _TORCHVISION_AVAILABLE, module_available from flash.core.utilities.providers import _ICEVISION, _MMDET, _TORCHVISION if _ICEVISION_AVAILABLE: From 0e6a6921b5e9bcdf20d5f437cafb7550380237c9 Mon Sep 17 00:00:00 2001 From: Kushashwa Ravi Shrimali Date: Sat, 24 Sep 2022 19:08:46 +0530 Subject: [PATCH 10/17] Apply suggestions from code review --- flash/core/utilities/imports.py | 1 - flash/image/detection/backbones.py | 3 ++- flash/image/instance_segmentation/backbones.py | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/flash/core/utilities/imports.py b/flash/core/utilities/imports.py index 7813171aef..a7d45ad566 100644 --- a/flash/core/utilities/imports.py +++ b/flash/core/utilities/imports.py @@ -18,7 +18,6 @@ import types from typing import List, Tuple, Union -import pkg_resources from lightning_utilities.core.imports import compare_version, module_available from pkg_resources import DistributionNotFound diff --git a/flash/image/detection/backbones.py b/flash/image/detection/backbones.py index 753f03018f..4dccf3ab61 100644 --- a/flash/image/detection/backbones.py +++ b/flash/image/detection/backbones.py @@ -23,8 +23,9 @@ ) from flash.core.model import Task from flash.core.registry import FlashRegistry -from flash.core.utilities.imports import _ICEVISION_AVAILABLE, _TORCHVISION_AVAILABLE, module_available +from flash.core.utilities.imports import _ICEVISION_AVAILABLE, _TORCHVISION_AVAILABLE from flash.core.utilities.providers import _EFFDET, _ICEVISION, _MMDET, _TORCHVISION, _ULTRALYTICS +from lightning_utilities.core.imports import module_available if _ICEVISION_AVAILABLE: from icevision import models as icevision_models diff --git a/flash/image/instance_segmentation/backbones.py b/flash/image/instance_segmentation/backbones.py index c0e08cef0d..8f90bdf92c 100644 --- a/flash/image/instance_segmentation/backbones.py +++ b/flash/image/instance_segmentation/backbones.py @@ -19,7 +19,8 @@ from flash.core.integrations.icevision.backbones import get_backbones, load_icevision_ignore_image_size from flash.core.model import Task from flash.core.registry import FlashRegistry -from flash.core.utilities.imports import _ICEVISION_AVAILABLE, _TORCHVISION_AVAILABLE, module_available +from flash.core.utilities.imports import _ICEVISION_AVAILABLE, _TORCHVISION_AVAILABLE +from lightning_utilities.core.imports import module_available from flash.core.utilities.providers import _ICEVISION, _MMDET, _TORCHVISION if _ICEVISION_AVAILABLE: From c25d3df0a5fd2895b73bfdd5fd7835e0ae5e6f8f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 24 Sep 2022 13:39:26 +0000 Subject: [PATCH 11/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- flash/image/detection/backbones.py | 3 ++- flash/image/instance_segmentation/backbones.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/flash/image/detection/backbones.py b/flash/image/detection/backbones.py index 4dccf3ab61..6bcfd5dd44 100644 --- a/flash/image/detection/backbones.py +++ b/flash/image/detection/backbones.py @@ -14,6 +14,8 @@ from functools import partial from typing import Optional +from lightning_utilities.core.imports import module_available + from flash.core.adapter import Adapter from flash.core.integrations.icevision.adapter import IceVisionAdapter, SimpleCOCOMetric from flash.core.integrations.icevision.backbones import ( @@ -25,7 +27,6 @@ from flash.core.registry import FlashRegistry from flash.core.utilities.imports import _ICEVISION_AVAILABLE, _TORCHVISION_AVAILABLE from flash.core.utilities.providers import _EFFDET, _ICEVISION, _MMDET, _TORCHVISION, _ULTRALYTICS -from lightning_utilities.core.imports import module_available if _ICEVISION_AVAILABLE: from icevision import models as icevision_models diff --git a/flash/image/instance_segmentation/backbones.py b/flash/image/instance_segmentation/backbones.py index 8f90bdf92c..40fe3d7c85 100644 --- a/flash/image/instance_segmentation/backbones.py +++ b/flash/image/instance_segmentation/backbones.py @@ -14,13 +14,14 @@ from functools import partial from typing import Optional +from lightning_utilities.core.imports import module_available + from flash.core.adapter import Adapter from flash.core.integrations.icevision.adapter import IceVisionAdapter, SimpleCOCOMetric from flash.core.integrations.icevision.backbones import get_backbones, load_icevision_ignore_image_size from flash.core.model import Task from flash.core.registry import FlashRegistry from flash.core.utilities.imports import _ICEVISION_AVAILABLE, _TORCHVISION_AVAILABLE -from lightning_utilities.core.imports import module_available from flash.core.utilities.providers import _ICEVISION, _MMDET, _TORCHVISION if _ICEVISION_AVAILABLE: From 7d5a5335846deca9ab5e99adfb8048d46e925728 Mon Sep 17 00:00:00 2001 From: uakarsh <55104596+uakarsh@users.noreply.github.com> Date: Sat, 24 Sep 2022 19:39:07 +0530 Subject: [PATCH 12/17] Modified the `is_overriden` method --- flash/core/data/base_viz.py | 4 ++-- flash/core/utilities/apply_func.py | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/flash/core/data/base_viz.py b/flash/core/data/base_viz.py index 0b12bff644..3d4a863416 100644 --- a/flash/core/data/base_viz.py +++ b/flash/core/data/base_viz.py @@ -17,7 +17,7 @@ from flash.core.data.callback import BaseDataFetcher from flash.core.data.utils import _CALLBACK_FUNCS -from flash.core.utilities.apply_func import _is_overridden +from lightning_utilities.core.overrides import is_overridden from flash.core.utilities.stages import RunningStage @@ -124,7 +124,7 @@ def show( for func_name in func_names_set: hook_name = f"show_{func_name}" - if _is_overridden(hook_name, self, BaseVisualization): + if is_overriden(hook_name, self, BaseVisualization): getattr(self, hook_name)(batch[func_name], running_stage, limit_nb_samples, figsize) def show_load_sample( diff --git a/flash/core/utilities/apply_func.py b/flash/core/utilities/apply_func.py index 2412770503..19e3f80153 100644 --- a/flash/core/utilities/apply_func.py +++ b/flash/core/utilities/apply_func.py @@ -29,8 +29,4 @@ def get_callable_dict(fn: Union[nn.Module, Callable, Mapping, Sequence]) -> Unio if isinstance(fn, Sequence): return {get_callable_name(f): f for f in fn} if callable(fn): - return {get_callable_name(fn): fn} - - -def _is_overridden(method_name: str, instance: object, parent: Type[object]) -> bool: - return is_overridden(method_name, instance, parent) \ No newline at end of file + return {get_callable_name(fn): fn} \ No newline at end of file From 8f1f3f411013f05f73d765bed73f9150c0abbecd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 24 Sep 2022 14:10:38 +0000 Subject: [PATCH 13/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- flash/core/data/base_viz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flash/core/data/base_viz.py b/flash/core/data/base_viz.py index 3d4a863416..ea85e6102e 100644 --- a/flash/core/data/base_viz.py +++ b/flash/core/data/base_viz.py @@ -13,11 +13,11 @@ # limitations under the License. from typing import Any, Dict, List, Set, Tuple +from lightning_utilities.core.overrides import is_overridden from pytorch_lightning.utilities.exceptions import MisconfigurationException from flash.core.data.callback import BaseDataFetcher from flash.core.data.utils import _CALLBACK_FUNCS -from lightning_utilities.core.overrides import is_overridden from flash.core.utilities.stages import RunningStage From 24812189f53d5b9432e9d842f8028ee0282d37d4 Mon Sep 17 00:00:00 2001 From: uakarsh <55104596+uakarsh@users.noreply.github.com> Date: Sat, 24 Sep 2022 19:46:08 +0530 Subject: [PATCH 14/17] Syntax Error solve --- flash/core/utilities/apply_func.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/flash/core/utilities/apply_func.py b/flash/core/utilities/apply_func.py index ef1da6e28e..578019916e 100644 --- a/flash/core/utilities/apply_func.py +++ b/flash/core/utilities/apply_func.py @@ -29,12 +29,4 @@ def get_callable_dict(fn: Union[nn.Module, Callable, Mapping, Sequence]) -> Unio if isinstance(fn, Sequence): return {get_callable_name(f): f for f in fn} if callable(fn): -<<<<<<< HEAD return {get_callable_name(fn): fn} -======= - return {get_callable_name(fn): fn} - - -def _is_overridden(method_name: str, instance: object, parent: Type[object]) -> bool: - return is_overridden(method_name, instance, parent) ->>>>>>> c25d3df0a5fd2895b73bfdd5fd7835e0ae5e6f8f From 85404195a858782148e6c4723526681b8e10cd1c Mon Sep 17 00:00:00 2001 From: uakarsh <55104596+uakarsh@users.noreply.github.com> Date: Sat, 24 Sep 2022 20:09:37 +0530 Subject: [PATCH 15/17] Renamed `is_overriden` to `is_overridden` --- flash/core/data/base_viz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flash/core/data/base_viz.py b/flash/core/data/base_viz.py index ea85e6102e..46ea679c2b 100644 --- a/flash/core/data/base_viz.py +++ b/flash/core/data/base_viz.py @@ -124,7 +124,7 @@ def show( for func_name in func_names_set: hook_name = f"show_{func_name}" - if is_overriden(hook_name, self, BaseVisualization): + if is_overridden(hook_name, self, BaseVisualization): getattr(self, hook_name)(batch[func_name], running_stage, limit_nb_samples, figsize) def show_load_sample( From 9ef1553546d5827e8360db0c627d2ee997d6b74d Mon Sep 17 00:00:00 2001 From: Kushashwa Ravi Shrimali Date: Sat, 24 Sep 2022 23:14:15 +0530 Subject: [PATCH 16/17] Apply suggestions from code review --- flash/core/utilities/apply_func.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flash/core/utilities/apply_func.py b/flash/core/utilities/apply_func.py index 578019916e..b7e5ff7c21 100644 --- a/flash/core/utilities/apply_func.py +++ b/flash/core/utilities/apply_func.py @@ -11,9 +11,8 @@ # 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. -from typing import Callable, Dict, Mapping, Sequence, Type, Union +from typing import Callable, Dict, Mapping, Sequence, Union -from lightning_utilities.core.overrides import is_overridden from torch import nn From f0544a60aec2299d9fac4ca4850c90f1fef4c190 Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Sat, 1 Oct 2022 10:32:53 +0100 Subject: [PATCH 17/17] Install libsndfile for doctests --- .github/workflows/docs-check.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docs-check.yml b/.github/workflows/docs-check.yml index 44f41f800b..70858ef33a 100644 --- a/.github/workflows/docs-check.yml +++ b/.github/workflows/docs-check.yml @@ -81,6 +81,7 @@ jobs: run: | sudo apt-get update sudo apt-get install -y cmake pandoc + sudo apt-get install -y libsndfile1 pip install '.[all]' --find-links https://download.pytorch.org/whl/cpu/torch_stable.html pip install '.[test]' --find-links https://download.pytorch.org/whl/cpu/torch_stable.html pip install --requirement requirements/docs.txt