From 1a041d137d4d58cc9cdce563519c3f376357beee Mon Sep 17 00:00:00 2001 From: Ashwin Vaidya Date: Mon, 5 Aug 2024 18:24:52 +0200 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=94=A8Remove=20device=20postfix=20(#2?= =?UTF-8?q?233)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * remove device postfix Signed-off-by: Ashwin Vaidya * delete test Signed-off-by: Ashwin Vaidya * update tests Signed-off-by: Ashwin Vaidya --------- Signed-off-by: Ashwin Vaidya --- src/anomalib/cli/utils/installation.py | 85 +------------------------- tests/unit/cli/test_installation.py | 28 +-------- 2 files changed, 4 insertions(+), 109 deletions(-) diff --git a/src/anomalib/cli/utils/installation.py b/src/anomalib/cli/utils/installation.py index df5cd974a6..de31ef7d61 100644 --- a/src/anomalib/cli/utils/installation.py +++ b/src/anomalib/cli/utils/installation.py @@ -276,81 +276,6 @@ def get_hardware_suffix(with_available_torch_build: bool = False, torch_version: return hardware_suffix -def add_hardware_suffix_to_torch( - requirement: Requirement, - hardware_suffix: str | None = None, - with_available_torch_build: bool = False, -) -> str: - """Add hardware suffix to the torch requirement. - - Args: - requirement (Requirement): Requirement object comprising requirement - details. - hardware_suffix (str | None): Hardware suffix. If None, it will be set - to the correct hardware suffix. Defaults to None. - with_available_torch_build (bool): To check whether the installed - CUDA version is supported by the latest available PyTorch build. - Defaults to False. - - Examples: - >>> from pkg_resources import Requirement - >>> req = "torch>=1.13.0, <=2.0.1" - >>> requirement = Requirement.parse(req) - >>> requirement.name, requirement.specs - ('torch', [('>=', '1.13.0'), ('<=', '2.0.1')]) - - >>> add_hardware_suffix_to_torch(requirement) - 'torch>=1.13.0+cu121, <=2.0.1+cu121' - - ``with_available_torch_build=True`` will use the latest available PyTorch build. - >>> req = "torch==2.0.1" - >>> requirement = Requirement.parse(req) - >>> add_hardware_suffix_to_torch(requirement, with_available_torch_build=True) - 'torch==2.0.1+cu118' - - It is possible to pass the ``hardware_suffix`` manually. - >>> req = "torch==2.0.1" - >>> requirement = Requirement.parse(req) - >>> add_hardware_suffix_to_torch(requirement, hardware_suffix="cu121") - 'torch==2.0.1+cu111' - - Raises: - ValueError: When the requirement has more than two version criterion. - - Returns: - str: Updated torch package with the right cuda suffix. - """ - name = requirement.unsafe_name - updated_specs: list[str] = [] - - for operator, version in requirement.specs: - hardware_suffix = hardware_suffix or get_hardware_suffix(with_available_torch_build, version) - updated_version = version + f"+{hardware_suffix}" if not version.startswith(("2.1", "2.2")) else version - - # ``specs`` contains operators and versions as follows: - # These are to be concatenated again for the updated version. - updated_specs.append(operator + updated_version) - - updated_requirement: str = "" - - if updated_specs: - # This is the case when specs are e.g. ['<=1.9.1+cu111'] - if len(updated_specs) == 1: - updated_requirement = name + updated_specs[0] - # This is the case when specs are e.g., ['<=1.9.1+cu111', '>=1.8.1+cu111'] - elif len(updated_specs) == 2: - updated_requirement = name + updated_specs[0] + ", " + updated_specs[1] - else: - msg = ( - "Requirement version can be a single value or a range. \n" - "For example it could be torch>=1.8.1 " - "or torch>=1.8.1, <=1.9.1\n" - f"Got {updated_specs} instead." - ) - raise ValueError(msg) - return updated_requirement - - def get_torch_install_args(requirement: str | Requirement) -> list[str]: """Get the install arguments for Torch requirement. @@ -368,7 +293,7 @@ def get_torch_install_args(requirement: str | Requirement) -> list[str]: >>> requriment = "torch>=1.13.0" >>> get_torch_install_args(requirement) ['--extra-index-url', 'https://download.pytorch.org/whl/cpu', - 'torch==1.13.0+cpu', 'torchvision==0.14.0+cpu'] + 'torch>=1.13.0', 'torchvision==0.14.0'] Returns: list[str]: The install arguments. @@ -401,21 +326,15 @@ def get_torch_install_args(requirement: str | Requirement) -> list[str]: # Create the PyTorch Index URL to download the correct wheel. index_url = f"https://download.pytorch.org/whl/{hardware_suffix}" - # Create the PyTorch version depending on the CUDA version. For example, - # If CUDA version is 11.2, then the PyTorch version is 1.8.0+cu112. - # If CUDA version is None, then the PyTorch version is 1.8.0+cpu. - torch_version = add_hardware_suffix_to_torch(requirement, hardware_suffix, with_available_torch_build=True) + torch_version = f"{requirement.name}{operator}{version}" # eg: torch==1.13.0 # Get the torchvision version depending on the torch version. torchvision_version = AVAILABLE_TORCH_VERSIONS[version]["torchvision"] torchvision_requirement = f"torchvision{operator}{torchvision_version}" - if isinstance(torchvision_version, str) and not torchvision_version.startswith("0.16"): - torchvision_requirement += f"+{hardware_suffix}" # Return the install arguments. install_args += [ "--extra-index-url", - # "--index-url", index_url, torch_version, torchvision_requirement, diff --git a/tests/unit/cli/test_installation.py b/tests/unit/cli/test_installation.py index a0678c658b..ff2f0b5184 100644 --- a/tests/unit/cli/test_installation.py +++ b/tests/unit/cli/test_installation.py @@ -12,7 +12,6 @@ from pytest_mock import MockerFixture from anomalib.cli.utils.installation import ( - add_hardware_suffix_to_torch, get_cuda_suffix, get_cuda_version, get_hardware_suffix, @@ -122,29 +121,6 @@ def test_get_hardware_suffix(mocker: MockerFixture) -> None: assert get_hardware_suffix() == "cpu" -def test_add_hardware_suffix_to_torch(mocker: MockerFixture) -> None: - """Test that add_hardware_suffix_to_torch returns the expected updated requirement.""" - mocker.patch("anomalib.cli.utils.installation.get_hardware_suffix", return_value="cu121") - requirement = Requirement.parse("torch>=1.13.0, <=2.0.1") - updated_requirement = add_hardware_suffix_to_torch(requirement) - assert "torch" in updated_requirement - assert ">=1.13.0+cu121" in updated_requirement - assert "<=2.0.1+cu121" in updated_requirement - - requirement = Requirement.parse("torch==2.0.1") - mocker.patch("anomalib.cli.utils.installation.get_hardware_suffix", return_value="cu118") - updated_requirement = add_hardware_suffix_to_torch(requirement, with_available_torch_build=True) - assert updated_requirement == "torch==2.0.1+cu118" - - requirement = Requirement.parse("torch==2.0.1") - updated_requirement = add_hardware_suffix_to_torch(requirement, hardware_suffix="cu111") - assert updated_requirement == "torch==2.0.1+cu111" - - requirement = Requirement.parse("torch>=1.13.0, <=2.0.1, !=1.14.0") - with pytest.raises(ValueError, match="Requirement version can be a single value or a range."): - add_hardware_suffix_to_torch(requirement) - - def test_get_torch_install_args(mocker: MockerFixture) -> None: """Test that get_torch_install_args returns the expected install arguments.""" requirement = Requirement.parse("torch>=2.1.1") @@ -174,8 +150,8 @@ def test_get_torch_install_args(mocker: MockerFixture) -> None: expected_args = [ "--extra-index-url", "https://download.pytorch.org/whl/cu111", - "torch==2.0.1+cu111", - "torchvision==0.15.2+cu111", + "torch==2.0.1", + "torchvision==0.15.2", ] install_args = get_torch_install_args(requirement) for arg in expected_args: From 904d2110074c81f2aebd491e9cdb3eedf1458887 Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Mon, 12 Aug 2024 13:53:48 +0100 Subject: [PATCH 2/5] Release v1.1.1 (#2237) Update `CHANGELOG.md` (#2236) Update changelog --- CHANGELOG.md | 35 ++++++++++++++++++++++++++++++++--- src/anomalib/__init__.py | 2 +- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 362856e3ec..fc80fa3e7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,17 +10,46 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed -- 🔨 Replace "./dtasets/BTech" to "./dtasets/BTech" +### Deprecated + +### Fixed + +### New Contributors + +**Full Changelog**: + +## [v1.1.1] + +### Added + +- 📚Ppipelines how-to guide by @ashwinvaidya17 in https://github.com/openvinotoolkit/anomalib/pull/2109 + +### Changed + +- Set permissions for github workflows by @djdameln in https://github.com/openvinotoolkit/anomalib/pull/2127 +- Update timm requirement from <=1.0.3,>=0.5.4 to >=0.5.4,<=1.0.7 by @dependabot in https://github.com/openvinotoolkit/anomalib/pull/2151 +- 🚀 Use gh actions runners for pre-commit checks by @ashwinvaidya17 in https://github.com/openvinotoolkit/anomalib/pull/2160 +- Bump AlexanderDokuchaev/md-dead-link-check from 0.8 to 0.9 by @dependabot in https://github.com/openvinotoolkit/anomalib/pull/2162 +- Added accuracy control quantization by @adrianboguszewski in https://github.com/openvinotoolkit/anomalib/pull/2070 ### Deprecated +- 🔨Remove device postfix by @ashwinvaidya17 in https://github.com/openvinotoolkit/anomalib/pull/2233 + ### Fixed -- 🔨 Fix uncorrect download path of btech dataset +- Fix: get MLFLOW_TRACKING_UTI from env variables as default by @CarlosNacher in https://github.com/openvinotoolkit/anomalib/pull/2107 +- Fix normalization by @alexriedel1 in https://github.com/openvinotoolkit/anomalib/pull/2130 +- Fix image-level heatmap normalization by @djdameln in https://github.com/openvinotoolkit/anomalib/pull/2131 +- Fix: efficient ad model_size str fixes by @Gornoka in https://github.com/openvinotoolkit/anomalib/pull/2159 +- Fix the CI by @samet-akcay in https://github.com/openvinotoolkit/anomalib/pull/2178 +- Fix BTech Dataset by @samet-akcay in https://github.com/openvinotoolkit/anomalib/pull/2180 ### New Contributors -**Full Changelog**: +- @CarlosNacher made their first contribution in https://github.com/openvinotoolkit/anomalib/pull/2107 + +**Full Changelog**: https://github.com/openvinotoolkit/anomalib/compare/v1.1.0...v1.1.1 ## [v1.1.0] diff --git a/src/anomalib/__init__.py b/src/anomalib/__init__.py index 1b7a30497c..72495d13ce 100644 --- a/src/anomalib/__init__.py +++ b/src/anomalib/__init__.py @@ -5,7 +5,7 @@ from enum import Enum -__version__ = "1.2.0dev" +__version__ = "1.1.1" class LearningType(str, Enum): From 32fd3a8de7074e0ca4af796f3573bc0a84defa25 Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Mon, 12 Aug 2024 13:54:34 +0100 Subject: [PATCH 3/5] Bump Anomalib version to 1.2.0dev --- src/anomalib/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/anomalib/__init__.py b/src/anomalib/__init__.py index 72495d13ce..1b7a30497c 100644 --- a/src/anomalib/__init__.py +++ b/src/anomalib/__init__.py @@ -5,7 +5,7 @@ from enum import Enum -__version__ = "1.1.1" +__version__ = "1.2.0dev" class LearningType(str, Enum): From 1473a679af4fff15384494d731bce583cce0ab37 Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Mon, 12 Aug 2024 13:55:28 +0100 Subject: [PATCH 4/5] Update __init__.py --- src/anomalib/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/anomalib/__init__.py b/src/anomalib/__init__.py index 1b7a30497c..72495d13ce 100644 --- a/src/anomalib/__init__.py +++ b/src/anomalib/__init__.py @@ -5,7 +5,7 @@ from enum import Enum -__version__ = "1.2.0dev" +__version__ = "1.1.1" class LearningType(str, Enum): From 2bd2842ec33c6eedb351d53cf1a1082069ff69dc Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Mon, 12 Aug 2024 13:59:14 +0100 Subject: [PATCH 5/5] Bump Anomalib version to 1.2.0dev --- src/anomalib/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/anomalib/__init__.py b/src/anomalib/__init__.py index 72495d13ce..1b7a30497c 100644 --- a/src/anomalib/__init__.py +++ b/src/anomalib/__init__.py @@ -5,7 +5,7 @@ from enum import Enum -__version__ = "1.1.1" +__version__ = "1.2.0dev" class LearningType(str, Enum):