From 09bd06470ff5448d630b1859beb02e1eeed25f62 Mon Sep 17 00:00:00 2001 From: Nicki Skafte Detlefsen Date: Wed, 11 Oct 2023 11:30:31 +0200 Subject: [PATCH] Update min Pytorch to 1.10 (#2145) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com> --- .azure/gpu-unittests.yml | 4 +-- .github/workflows/ci-tests.yml | 6 +--- .github/workflows/docker-build.yml | 1 - CHANGELOG.md | 2 ++ requirements/base.txt | 3 +- src/torchmetrics/functional/image/helper.py | 14 +------- .../image/perceptual_path_length.py | 5 ++- src/torchmetrics/image/fid.py | 13 ++----- src/torchmetrics/image/mifid.py | 13 +------ src/torchmetrics/utilities/checks.py | 2 +- src/torchmetrics/utilities/compute.py | 4 +-- src/torchmetrics/utilities/imports.py | 2 -- .../classification/test_calibration_error.py | 4 +-- .../unittests/classification/test_ranking.py | 6 ---- tests/unittests/image/test_fid.py | 34 ++++++------------- tests/unittests/image/test_lpips.py | 4 +-- tests/unittests/image/test_mifid.py | 7 +--- .../pairwise/test_pairwise_distance.py | 3 -- .../regression/test_minkowski_distance.py | 4 --- .../regression/test_tweedie_deviance.py | 7 ++-- tests/unittests/utilities/test_plot.py | 4 --- 21 files changed, 32 insertions(+), 110 deletions(-) diff --git a/.azure/gpu-unittests.yml b/.azure/gpu-unittests.yml index 17f7b24cc7b..d1c589aeba6 100644 --- a/.azure/gpu-unittests.yml +++ b/.azure/gpu-unittests.yml @@ -19,9 +19,9 @@ jobs: matrix: "PyTorch | old": # Torch does not have build wheels with old Torch versions for newer CUDA - docker-image: "pytorchlightning/torchmetrics:ubuntu20.04-cuda11.1.1-py3.8-torch1.8.1" + docker-image: "pytorchlightning/torchmetrics:ubuntu22.04-cuda11.8.0-py3.9-torch1.10" agent-pool: "lit-rtx-3090" - torch-ver: "1.8.1" + torch-ver: "1.10.2" "PyTorch | 1.X": docker-image: "pytorchlightning/torchmetrics:ubuntu22.04-cuda11.8.0-py3.9-torch1.13" agent-pool: "lit-rtx-3090" diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 633d483d8b0..b73982287b9 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -32,7 +32,7 @@ jobs: matrix: os: ["ubuntu-20.04"] python-version: ["3.9"] - pytorch-version: ["1.9.1", "1.10.2", "1.11.0", "1.12.1", "1.13.1", "2.0.1", "2.1.0"] + pytorch-version: ["1.10.2", "1.11.0", "1.12.1", "1.13.1", "2.0.1", "2.1.0"] include: - { os: "ubuntu-22.04", python-version: "3.8", pytorch-version: "1.13.1" } - { os: "ubuntu-22.04", python-version: "3.10", pytorch-version: "1.13.1" } @@ -47,10 +47,6 @@ jobs: - { os: "windows-2022", python-version: "3.9", pytorch-version: "1.13.1" } - { os: "windows-2022", python-version: "3.10", pytorch-version: "2.0.1" } - { os: "windows-2022", python-version: "3.11", pytorch-version: "2.1.0" } - # the oldest configurations - - { os: "ubuntu-20.04", python-version: "3.8", pytorch-version: "1.8.1", requires: "oldest" } - - { os: "macOS-11", python-version: "3.8", pytorch-version: "1.8.1", requires: "oldest" } - - { os: "windows-2019", python-version: "3.8", pytorch-version: "1.8.1", requires: "oldest" } env: PYTORCH_URL: "https://download.pytorch.org/whl/cpu/torch_stable.html" FREEZE_REQUIREMENTS: ${{ ! (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')) }} diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 5915a6a66df..3e6610521dc 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -66,7 +66,6 @@ jobs: include: # These are the base images for PL release docker images, # so include at least all of the combinations in release-dockers.yml. - - { python: "3.8", pytorch: "1.8.1", cuda: "11.1.1", ubuntu: "20.04" } - { python: "3.9", pytorch: "1.10", cuda: "11.8.0", ubuntu: "22.04" } - { python: "3.9", pytorch: "1.11", cuda: "11.8.0", ubuntu: "22.04" } - { python: "3.9", pytorch: "1.13", cuda: "11.8.0", ubuntu: "22.04" } diff --git a/CHANGELOG.md b/CHANGELOG.md index d7ec9477de8..8ce9979c417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Change default state of `SpectralAngleMapper` and `UniversalImageQualityIndex` to be tensors ([#2089](https://github.com/Lightning-AI/torchmetrics/pull/2089)) +- Changed minimum supported Pytorch version from 1.8 to 1.10 ([#2145](https://github.com/Lightning-AI/torchmetrics/pull/2145)) + ### Removed diff --git a/requirements/base.txt b/requirements/base.txt index 482edef1f82..eedb6a7a546 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -3,6 +3,7 @@ numpy >1.20.0 packaging >17.1 -torch >=1.8.1, <=2.1.0 +torch >=1.10.0, <=2.0.1 +torch >=1.10.0, <=2.1.0 typing-extensions; python_version < '3.9' lightning-utilities >=0.8.0, <0.10.0 diff --git a/src/torchmetrics/functional/image/helper.py b/src/torchmetrics/functional/image/helper.py index b4321e76e3b..bf09ff79249 100644 --- a/src/torchmetrics/functional/image/helper.py +++ b/src/torchmetrics/functional/image/helper.py @@ -4,9 +4,6 @@ from torch import Tensor from torch.nn import functional as F # noqa: N812 -from torchmetrics.utilities import rank_zero_warn -from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_10 - def _gaussian(kernel_size: int, sigma: float, dtype: torch.dtype, device: Union[torch.device, str]) -> Tensor: """Compute 1D gaussian kernel. @@ -172,13 +169,4 @@ def _reflection_pad_3d(inputs: Tensor, pad_h: int, pad_w: int, pad_d: int) -> Te padded input tensor """ - if _TORCH_GREATER_EQUAL_1_10: - inputs = F.pad(inputs, (pad_h, pad_h, pad_w, pad_w, pad_d, pad_d), mode="reflect") - else: - rank_zero_warn( - "An older version of pyTorch is used." - " For optimal speed, please upgrade to at least PyTorch v1.10 or higher." - ) - for dim, pad in enumerate([pad_h, pad_w, pad_d]): - inputs = _single_dimension_pad(inputs, dim + 2, pad, outer_pad=1) - return inputs + return F.pad(inputs, (pad_h, pad_h, pad_w, pad_w, pad_d, pad_d), mode="reflect") diff --git a/src/torchmetrics/functional/image/perceptual_path_length.py b/src/torchmetrics/functional/image/perceptual_path_length.py index 74a23b621d7..4b675ae9c54 100644 --- a/src/torchmetrics/functional/image/perceptual_path_length.py +++ b/src/torchmetrics/functional/image/perceptual_path_length.py @@ -18,7 +18,7 @@ from torch import Tensor, nn from torchmetrics.functional.image.lpips import _LPIPS -from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_10, _TORCHVISION_AVAILABLE +from torchmetrics.utilities.imports import _TORCHVISION_AVAILABLE if not _TORCHVISION_AVAILABLE: __doctest_skip__ = ["perceptual_path_length"] @@ -246,8 +246,7 @@ def perceptual_path_length( else: raise ValueError(f"sim_net must be a nn.Module or one of 'alex', 'vgg', 'squeeze', got {sim_net}") - decorator = torch.inference_mode if _TORCH_GREATER_EQUAL_1_10 else torch.no_grad - with decorator(): + with torch.inference_mode(): distances = [] num_batches = math.ceil(num_samples / batch_size) for batch_idx in range(num_batches): diff --git a/src/torchmetrics/image/fid.py b/src/torchmetrics/image/fid.py index 2ba787cf017..bc830fdd0b7 100644 --- a/src/torchmetrics/image/fid.py +++ b/src/torchmetrics/image/fid.py @@ -20,13 +20,11 @@ from torch.nn.functional import adaptive_avg_pool2d from torchmetrics.metric import Metric -from torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE, _TORCH_FIDELITY_AVAILABLE, _TORCH_GREATER_EQUAL_1_9 +from torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE, _TORCH_FIDELITY_AVAILABLE from torchmetrics.utilities.plot import _AX_TYPE, _PLOT_OUT_TYPE -__doctest_skip__ = ["FrechetInceptionDistance.__init__"] if not _TORCH_GREATER_EQUAL_1_9 else [] - if not _MATPLOTLIB_AVAILABLE: - __doctest_skip__ += ["FrechetInceptionDistance.plot"] + __doctest_skip__ = ["FrechetInceptionDistance.plot"] if _TORCH_FIDELITY_AVAILABLE: from torch_fidelity.feature_extractor_inceptionv3 import FeatureExtractorInceptionV3 as _FeatureExtractorInceptionV3 @@ -42,9 +40,6 @@ class _FeatureExtractorInceptionV3(Module): # type: ignore[no-redef] __doctest_skip__ = ["FrechetInceptionDistance", "FrechetInceptionDistance.plot"] -if not _TORCH_GREATER_EQUAL_1_9: - __doctest_skip__ = ["FrechetInceptionDistance", "FrechetInceptionDistance.plot"] - class NoTrainInceptionV3(_FeatureExtractorInceptionV3): """Module that never leaves evaluation mode.""" @@ -285,10 +280,6 @@ def __init__( **kwargs: Any, ) -> None: super().__init__(**kwargs) - - if not _TORCH_GREATER_EQUAL_1_9: - raise ValueError("FrechetInceptionDistance metric requires that PyTorch is version 1.9.0 or higher.") - if isinstance(feature, int): num_features = feature if not _TORCH_FIDELITY_AVAILABLE: diff --git a/src/torchmetrics/image/mifid.py b/src/torchmetrics/image/mifid.py index d4284938234..c5c16aab666 100644 --- a/src/torchmetrics/image/mifid.py +++ b/src/torchmetrics/image/mifid.py @@ -20,7 +20,7 @@ from torchmetrics.image.fid import NoTrainInceptionV3, _compute_fid from torchmetrics.metric import Metric from torchmetrics.utilities.data import dim_zero_cat -from torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE, _TORCH_FIDELITY_AVAILABLE, _TORCH_GREATER_EQUAL_1_10 +from torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE, _TORCH_FIDELITY_AVAILABLE from torchmetrics.utilities.plot import _AX_TYPE, _PLOT_OUT_TYPE __doctest_requires__ = { @@ -29,12 +29,6 @@ ] } -if not _TORCH_GREATER_EQUAL_1_10: - __doctest_skip__ = [ - "MemorizationInformedFrechetInceptionDistance", - "MemorizationInformedFrechetInceptionDistance.plot", - ] - if not _MATPLOTLIB_AVAILABLE: __doctest_skip__ = ["MemorizationInformedFrechetInceptionDistance.plot"] @@ -166,11 +160,6 @@ def __init__( **kwargs: Any, ) -> None: super().__init__(**kwargs) - if not _TORCH_GREATER_EQUAL_1_10: - raise RuntimeError( - "MemorizationInformedFrechetInceptionDistance metric requires PyTorch version greater or equal to 1.10" - ) - if isinstance(feature, int): if not _TORCH_FIDELITY_AVAILABLE: raise ModuleNotFoundError( diff --git a/src/torchmetrics/utilities/checks.py b/src/torchmetrics/utilities/checks.py index c35556aaabb..96455064c3a 100644 --- a/src/torchmetrics/utilities/checks.py +++ b/src/torchmetrics/utilities/checks.py @@ -656,7 +656,7 @@ def check_forward_full_state_property( Example (states in ``update`` are independent, save to set ``full_state_update=False``) >>> from torchmetrics.classification import MulticlassConfusionMatrix - >>> check_forward_full_state_property( # doctest: +ELLIPSIS + >>> check_forward_full_state_property( # doctest: +SKIP ... MulticlassConfusionMatrix, ... init_args = {'num_classes': 3}, ... input_args = {'preds': torch.randint(3, (100,)), 'target': torch.randint(3, (100,))}, diff --git a/src/torchmetrics/utilities/compute.py b/src/torchmetrics/utilities/compute.py index c8cb48a8cdb..10201eaa2e7 100644 --- a/src/torchmetrics/utilities/compute.py +++ b/src/torchmetrics/utilities/compute.py @@ -16,8 +16,6 @@ import torch from torch import Tensor -from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_9 - def _safe_matmul(x: Tensor, y: Tensor) -> Tensor: """Safe calculation of matrix multiplication. @@ -101,7 +99,7 @@ def _auc_compute_without_check(x: Tensor, y: Tensor, direction: float, axis: int def _auc_compute(x: Tensor, y: Tensor, reorder: bool = False) -> Tensor: with torch.no_grad(): if reorder: - x, x_idx = torch.sort(x, stable=True) if _TORCH_GREATER_EQUAL_1_9 else torch.sort(x) + x, x_idx = torch.sort(x, stable=True) y = y[x_idx] dx = x[1:] - x[:-1] diff --git a/src/torchmetrics/utilities/imports.py b/src/torchmetrics/utilities/imports.py index 624fa4a8e36..9b769b0a6d9 100644 --- a/src/torchmetrics/utilities/imports.py +++ b/src/torchmetrics/utilities/imports.py @@ -23,8 +23,6 @@ _PYTHON_VERSION = ".".join(map(str, [sys.version_info.major, sys.version_info.minor, sys.version_info.micro])) _PYTHON_LOWER_3_8 = parse(_PYTHON_VERSION) < Version("3.8") _TORCH_LOWER_1_12_DEV: Optional[bool] = compare_version("torch", operator.lt, "1.12.0.dev") -_TORCH_GREATER_EQUAL_1_9: Optional[bool] = compare_version("torch", operator.ge, "1.9.0") -_TORCH_GREATER_EQUAL_1_10: Optional[bool] = compare_version("torch", operator.ge, "1.10.0") _TORCH_GREATER_EQUAL_1_11: Optional[bool] = compare_version("torch", operator.ge, "1.11.0") _TORCH_GREATER_EQUAL_1_12: Optional[bool] = compare_version("torch", operator.ge, "1.12.0") _TORCH_GREATER_EQUAL_1_13: Optional[bool] = compare_version("torch", operator.ge, "1.13.0") diff --git a/tests/unittests/classification/test_calibration_error.py b/tests/unittests/classification/test_calibration_error.py index 60cad273bbe..56090278312 100644 --- a/tests/unittests/classification/test_calibration_error.py +++ b/tests/unittests/classification/test_calibration_error.py @@ -29,7 +29,7 @@ multiclass_calibration_error, ) from torchmetrics.metric import Metric -from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_9, _TORCH_GREATER_EQUAL_1_13 +from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_13 from unittests import NUM_CLASSES from unittests.classification.inputs import _binary_cases, _multiclass_cases @@ -228,8 +228,6 @@ def test_multiclass_calibration_error_differentiability(self, inputs): def test_multiclass_calibration_error_dtype_cpu(self, inputs, dtype): """Test dtype support of the metric on CPU.""" preds, target = inputs - if dtype == torch.half and not _TORCH_GREATER_EQUAL_1_9: - pytest.xfail(reason="torch.max in metric not supported before pytorch v1.9 for cpu + half") if (preds < 0).any() and dtype == torch.half: pytest.xfail(reason="torch.softmax in metric does not support cpu + half precision") self.run_precision_test_cpu( diff --git a/tests/unittests/classification/test_ranking.py b/tests/unittests/classification/test_ranking.py index befe6a9330d..1ba4f054a70 100644 --- a/tests/unittests/classification/test_ranking.py +++ b/tests/unittests/classification/test_ranking.py @@ -30,7 +30,6 @@ multilabel_ranking_average_precision, multilabel_ranking_loss, ) -from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_9 from unittests import NUM_CLASSES from unittests.classification.inputs import _multilabel_cases @@ -124,11 +123,6 @@ def test_multilabel_ranking_dtype_cpu(self, inputs, metric, functional_metric, r pytest.xfail( reason="multilabel_ranking_average_precision requires torch.unique which is not implemented for half" ) - if dtype == torch.half and not _TORCH_GREATER_EQUAL_1_9 and functional_metric == multilabel_coverage_error: - pytest.xfail( - reason="multilabel_coverage_error requires torch.min which is only implemented for half" - " in v1.9 or higher of torch." - ) self.run_precision_test_cpu( preds=preds, target=target, diff --git a/tests/unittests/image/test_fid.py b/tests/unittests/image/test_fid.py index 2fe3529f4c6..83b243200da 100644 --- a/tests/unittests/image/test_fid.py +++ b/tests/unittests/image/test_fid.py @@ -20,7 +20,7 @@ from torch.nn import Module from torch.utils.data import Dataset from torchmetrics.image.fid import FrechetInceptionDistance, NoTrainInceptionV3 -from torchmetrics.utilities.imports import _TORCH_FIDELITY_AVAILABLE, _TORCH_GREATER_EQUAL_1_9 +from torchmetrics.utilities.imports import _TORCH_FIDELITY_AVAILABLE torch.manual_seed(42) @@ -34,7 +34,6 @@ def test_no_train_network_missing_torch_fidelity(): NoTrainInceptionV3(name="inception-v3-compat", features_list=["2048"]) -@pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_9, reason="test requires torch>=1.9") @pytest.mark.skipif(not _TORCH_FIDELITY_AVAILABLE, reason="test requires torch-fidelity") def test_no_train(): """Assert that metric never leaves evaluation mode.""" @@ -53,7 +52,6 @@ def forward(self, x): assert not model.metric.inception.training, "FID metric was changed to training mode which should not happen" -@pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_9, reason="test requires torch>=1.9") @pytest.mark.skipif(not _TORCH_FIDELITY_AVAILABLE, reason="test requires torch-fidelity") def test_fid_pickle(): """Assert that we can initialize the metric and pickle it.""" @@ -67,28 +65,21 @@ def test_fid_pickle(): def test_fid_raises_errors_and_warnings(): """Test that expected warnings and errors are raised.""" - if _TORCH_GREATER_EQUAL_1_9: - if _TORCH_FIDELITY_AVAILABLE: - with pytest.raises(ValueError, match="Integer input to argument `feature` must be one of .*"): - _ = FrechetInceptionDistance(feature=2) - else: - with pytest.raises( - ModuleNotFoundError, - match="FID metric requires that `Torch-fidelity` is installed." - " Either install as `pip install torchmetrics[image-quality]` or `pip install torch-fidelity`.", - ): - _ = FrechetInceptionDistance() - - with pytest.raises(TypeError, match="Got unknown input to argument `feature`"): - _ = FrechetInceptionDistance(feature=[1, 2]) + if _TORCH_FIDELITY_AVAILABLE: + with pytest.raises(ValueError, match="Integer input to argument `feature` must be one of .*"): + _ = FrechetInceptionDistance(feature=2) else: with pytest.raises( - ValueError, match="FrechetInceptionDistance metric requires that PyTorch is version 1.9.0 or higher." + ModuleNotFoundError, + match="FID metric requires that `Torch-fidelity` is installed." + " Either install as `pip install torchmetrics[image-quality]` or `pip install torch-fidelity`.", ): _ = FrechetInceptionDistance() + with pytest.raises(TypeError, match="Got unknown input to argument `feature`"): + _ = FrechetInceptionDistance(feature=[1, 2]) + -@pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_9, reason="test requires torch>=1.9") @pytest.mark.skipif(not _TORCH_FIDELITY_AVAILABLE, reason="test requires torch-fidelity") @pytest.mark.parametrize("feature", [64, 192, 768, 2048]) def test_fid_same_input(feature): @@ -120,7 +111,6 @@ def __len__(self) -> int: @pytest.mark.skipif(not torch.cuda.is_available(), reason="test is too slow without gpu") -@pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_9, reason="test requires torch>=1.9") @pytest.mark.skipif(not _TORCH_FIDELITY_AVAILABLE, reason="test requires torch-fidelity") @pytest.mark.parametrize("equal_size", [False, True]) def test_compare_fid(tmpdir, equal_size, feature=768): @@ -157,7 +147,6 @@ def test_compare_fid(tmpdir, equal_size, feature=768): assert torch.allclose(tm_res.cpu(), torch.tensor([torch_fid["frechet_inception_distance"]]), atol=1e-3) -@pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_9, reason="test requires torch>=1.9") @pytest.mark.parametrize("reset_real_features", [True, False]) def test_reset_real_features_arg(reset_real_features): """Test that `reset_real_features` argument works as expected.""" @@ -187,7 +176,6 @@ def test_reset_real_features_arg(reset_real_features): assert metric.real_features_cov_sum.shape == torch.Size([64, 64]) -@pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_9, reason="test requires torch>=1.9") @pytest.mark.parametrize("normalize", [True, False]) def test_normalize_arg(normalize): """Test that normalize argument works as expected.""" @@ -206,7 +194,6 @@ def test_normalize_arg(normalize): metric.update(img, real=True) -@pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_9, reason="test requires torch>=1.9") def test_not_enough_samples(): """Test that an error is raised if not enough samples were provided.""" img = torch.randint(0, 255, (1, 3, 299, 299), dtype=torch.uint8) @@ -219,7 +206,6 @@ def test_not_enough_samples(): metric.compute() -@pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_9, reason="test requires torch>=1.9") def test_dtype_transfer_to_submodule(): """Test that change in dtype also changes the default inception net.""" imgs = torch.randn(1, 3, 256, 256) diff --git a/tests/unittests/image/test_lpips.py b/tests/unittests/image/test_lpips.py index f17aa0f59fb..cb317a1aba7 100644 --- a/tests/unittests/image/test_lpips.py +++ b/tests/unittests/image/test_lpips.py @@ -19,7 +19,7 @@ from lpips import LPIPS as LPIPS_reference # noqa: N811 from torch import Tensor from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity -from torchmetrics.utilities.imports import _LPIPS_AVAILABLE, _TORCH_GREATER_EQUAL_1_9 +from torchmetrics.utilities.imports import _LPIPS_AVAILABLE from unittests.helpers import seed_all from unittests.helpers.testers import MetricTester @@ -73,8 +73,6 @@ def test_lpips_differentiability(self): # LPIPS half + cpu does not work due to missing support in torch.min for older version of torch def test_lpips_half_cpu(self): """Test for half + cpu support.""" - if not _TORCH_GREATER_EQUAL_1_9: - pytest.xfail(reason="LPIPS metric does not support cpu + half precision for v1.8.1 or lower of Pytorch") self.run_precision_test_cpu(_inputs.img1, _inputs.img2, LearnedPerceptualImagePatchSimilarity) @pytest.mark.skipif(not torch.cuda.is_available(), reason="test requires cuda") diff --git a/tests/unittests/image/test_mifid.py b/tests/unittests/image/test_mifid.py index 40fdbf1a2c9..fd96328e5a6 100644 --- a/tests/unittests/image/test_mifid.py +++ b/tests/unittests/image/test_mifid.py @@ -19,7 +19,7 @@ import torch from scipy.linalg import sqrtm from torchmetrics.image.mifid import MemorizationInformedFrechetInceptionDistance, NoTrainInceptionV3 -from torchmetrics.utilities.imports import _TORCH_FIDELITY_AVAILABLE, _TORCH_GREATER_EQUAL_1_10 +from torchmetrics.utilities.imports import _TORCH_FIDELITY_AVAILABLE def _compare_mifid(preds, target, cosine_distance_eps: float = 0.1): @@ -95,7 +95,6 @@ def calculate_mifid(m1, s1, features1, m2, s2, features2): return fid_private / (distance_private_thresholded + 1e-15) -@pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_10, reason="test requires torch>=1.10") @pytest.mark.skipif(not _TORCH_FIDELITY_AVAILABLE, reason="test requires torch-fidelity") def test_no_train(): """Assert that metric never leaves evaluation mode.""" @@ -114,7 +113,6 @@ def forward(self, x): assert not model.metric.inception.training, "MiFID metric was changed to training mode which should not happen" -@pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_10, reason="test requires torch>=1.10") def test_mifid_raises_errors_and_warnings(): """Test that expected warnings and errors are raised.""" if _TORCH_FIDELITY_AVAILABLE: @@ -138,7 +136,6 @@ def test_mifid_raises_errors_and_warnings(): _ = MemorizationInformedFrechetInceptionDistance(cosine_distance_eps=1.1) -@pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_10, reason="test requires torch>=1.10") @pytest.mark.skipif(not _TORCH_FIDELITY_AVAILABLE, reason="test requires torch-fidelity") @pytest.mark.parametrize("feature", [64, 192, 768, 2048]) def test_fid_same_input(feature): @@ -157,7 +154,6 @@ def test_fid_same_input(feature): @pytest.mark.skipif(not torch.cuda.is_available(), reason="test is too slow without gpu") -@pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_10, reason="test requires torch>=1.10") @pytest.mark.skipif(not _TORCH_FIDELITY_AVAILABLE, reason="test requires torch-fidelity") @pytest.mark.parametrize("equal_size", [False, True]) def test_compare_mifid(equal_size): @@ -184,7 +180,6 @@ def test_compare_mifid(equal_size): assert torch.allclose(tm_res.cpu(), torch.tensor(compare_val, dtype=tm_res.dtype), atol=1e-3) -@pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_10, reason="test requires torch>=1.10") @pytest.mark.parametrize("normalize", [True, False]) def test_normalize_arg(normalize): """Test that normalize argument works as expected.""" diff --git a/tests/unittests/pairwise/test_pairwise_distance.py b/tests/unittests/pairwise/test_pairwise_distance.py index d80377df432..4e12d4bcdf8 100644 --- a/tests/unittests/pairwise/test_pairwise_distance.py +++ b/tests/unittests/pairwise/test_pairwise_distance.py @@ -30,7 +30,6 @@ pairwise_manhattan_distance, pairwise_minkowski_distance, ) -from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_9 from unittests import BATCH_SIZE, NUM_BATCHES from unittests.helpers import seed_all @@ -112,8 +111,6 @@ def test_pairwise_half_cpu(self, x, y, metric_functional, sk_fn, reduction, requ """Test half precision support on cpu.""" if "euclidean" in request.node.callspec.id: pytest.xfail("pairwise_euclidean_distance metric does not support cpu + half precision") - if "minkowski" in request.node.callspec.id and not _TORCH_GREATER_EQUAL_1_9: - pytest.xfail("pairwise_minkowski_distance metric does not support cpu + half precision for pytorch<1.9") self.run_precision_test_cpu(x, y, None, metric_functional, metric_args={"reduction": reduction}) @pytest.mark.skipif(not torch.cuda.is_available(), reason="test requires cuda") diff --git a/tests/unittests/regression/test_minkowski_distance.py b/tests/unittests/regression/test_minkowski_distance.py index 3ee9f047208..cd88f765883 100644 --- a/tests/unittests/regression/test_minkowski_distance.py +++ b/tests/unittests/regression/test_minkowski_distance.py @@ -7,7 +7,6 @@ from torchmetrics.functional import minkowski_distance from torchmetrics.regression import MinkowskiDistance from torchmetrics.utilities.exceptions import TorchMetricsUserError -from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_9 from unittests import BATCH_SIZE, NUM_BATCHES from unittests.helpers import seed_all @@ -77,9 +76,6 @@ def test_minkowski_distance_functional(self, preds, target, ref_metric, p): metric_args={"p": p}, ) - @pytest.mark.skipif( - not _TORCH_GREATER_EQUAL_1_9, reason="minkowski half + cpu not supported for older versions of pytorch" - ) def test_minkowski_distance_half_cpu(self, preds, target, ref_metric, p): """Test dtype support of the metric on CPU.""" self.run_precision_test_cpu(preds, target, MinkowskiDistance, minkowski_distance, metric_args={"p": p}) diff --git a/tests/unittests/regression/test_tweedie_deviance.py b/tests/unittests/regression/test_tweedie_deviance.py index ea0a7c67d7c..ea876d601cf 100644 --- a/tests/unittests/regression/test_tweedie_deviance.py +++ b/tests/unittests/regression/test_tweedie_deviance.py @@ -20,7 +20,6 @@ from torch import Tensor from torchmetrics.functional.regression.tweedie_deviance import tweedie_deviance_score from torchmetrics.regression.tweedie_deviance import TweedieDevianceScore -from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_9 from unittests import BATCH_SIZE, NUM_BATCHES from unittests.helpers import seed_all @@ -95,8 +94,10 @@ def test_deviance_scores_differentiability(self, preds, targets, power): # Tweedie Deviance Score half + cpu does not work for power=[1,2] due to missing support in torch.log def test_deviance_scores_half_cpu(self, preds, targets, power): """Test dtype support of the metric on CPU.""" - if not _TORCH_GREATER_EQUAL_1_9 or power in [1, 2]: - pytest.xfail(reason="TweedieDevianceScore metric does not support cpu + half precision for older Pytorch") + if power in [1, 2]: + pytest.skip( + "Tweedie Deviance Score half + cpu does not work for power=[1,2] due to missing support in torch.log" + ) metric_args = {"power": power} self.run_precision_test_cpu( preds, diff --git a/tests/unittests/utilities/test_plot.py b/tests/unittests/utilities/test_plot.py index f28a6444e6f..42a21023dd7 100644 --- a/tests/unittests/utilities/test_plot.py +++ b/tests/unittests/utilities/test_plot.py @@ -172,8 +172,6 @@ WordInfoPreserved, ) from torchmetrics.utilities.imports import ( - _TORCH_GREATER_EQUAL_1_9, - _TORCH_GREATER_EQUAL_1_10, _TORCHAUDIO_GREATER_EQUAL_0_10, ) from torchmetrics.utilities.plot import _get_col_row_split @@ -669,7 +667,6 @@ def test_plot_methods(metric_class: object, preds: Callable, target: Callable, n lambda: torch.randint(0, 200, (30, 3, 299, 299), dtype=torch.uint8), False, id="frechet inception distance", - marks=pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_9, reason="test requires torch>=1.9"), ), pytest.param( partial(InceptionScore, feature=64), @@ -684,7 +681,6 @@ def test_plot_methods(metric_class: object, preds: Callable, target: Callable, n lambda: torch.randint(0, 200, (30, 3, 299, 299), dtype=torch.uint8), False, id="memorization informed frechet inception distance", - marks=pytest.mark.skipif(not _TORCH_GREATER_EQUAL_1_10, reason="test requires torch>=1.9"), ), ], )