From 302c707f79dbef50a3920baf11b76eba5ee4200e Mon Sep 17 00:00:00 2001 From: vfdev Date: Wed, 2 Oct 2024 16:39:37 +0200 Subject: [PATCH] Fix pytorch versions ci (#3289) * Fixed torch.pi usage unavailable in pytorch 1.5.1, 1.8.1 * Fix pytorch versions CI failures --- .github/workflows/pytorch-version-tests.yml | 14 ++++++++------ ignite/metrics/hsic.py | 1 + tests/ignite/metrics/test_hsic.py | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pytorch-version-tests.yml b/.github/workflows/pytorch-version-tests.yml index 0c5a0ae1c48..0ea40866aba 100644 --- a/.github/workflows/pytorch-version-tests.yml +++ b/.github/workflows/pytorch-version-tests.yml @@ -19,13 +19,8 @@ jobs: # will drop python version and related pytorch versions python-version: [3.8, 3.9, "3.10"] pytorch-version: - [2.3.1, 2.2.2, 2.1.2, 2.0.1, 1.13.1, 1.12.1, 1.10.0, 1.8.1, 1.5.1] + [2.3.1, 2.2.2, 2.1.2, 2.0.1, 1.13.1, 1.12.1, 1.10.0, 1.8.1] exclude: - - pytorch-version: 1.5.1 - python-version: 3.9 - - pytorch-version: 1.5.1 - python-version: "3.10" - # disabling python 3.9 support with PyTorch 1.7.1 and 1.8.1, to stop repeated pytorch-version test fail. # https://github.com/pytorch/ignite/issues/2383 - pytorch-version: 1.8.1 @@ -74,6 +69,13 @@ jobs: shell: bash -l {0} run: | conda install pytorch=${{ matrix.pytorch-version }} torchvision cpuonly python=${{ matrix.python-version }} -c pytorch + + # We should install numpy<2.0 for pytorch<2.3 + numpy_one_pth_version=$(python -c "import torch; print(float('.'.join(torch.__version__.split('.')[:2])) < 2.3)") + if [ "${numpy_one_pth_version}" == "True" ]; then + pip install -U "numpy<2.0" + fi + pip install -r requirements-dev.txt python setup.py install diff --git a/ignite/metrics/hsic.py b/ignite/metrics/hsic.py index a35d47f258b..2967db19e4f 100644 --- a/ignite/metrics/hsic.py +++ b/ignite/metrics/hsic.py @@ -134,6 +134,7 @@ def update(self, output: Sequence[Tensor]) -> None: vx: Union[Tensor, float] if self.sigma_x < 0: + # vx = torch.quantile(dxx, 0.5) vx = torch.quantile(dxx, 0.5) else: vx = self.sigma_x**2 diff --git a/tests/ignite/metrics/test_hsic.py b/tests/ignite/metrics/test_hsic.py index 6ee4237b96e..57af5fa2862 100644 --- a/tests/ignite/metrics/test_hsic.py +++ b/tests/ignite/metrics/test_hsic.py @@ -1,3 +1,4 @@ +import math from typing import Tuple import numpy as np @@ -74,7 +75,7 @@ def test_case(request) -> Tuple[Tensor, Tensor, int]: N = 200 b = 20 x = torch.randn(N, 5) - y = x @ torch.normal(0.0, torch.pi, size=(5, 3)) + y = x @ torch.normal(0.0, math.pi, size=(5, 3)) y = ( torch.stack([torch.sin(y[:, 0]), torch.cos(y[:, 1]), torch.exp(y[:, 2])], dim=1) + torch.randn_like(y) * 1e-4