From 9a9ef1c07f9c3dc84fa357a8ecbc50b1bfa9d9ba Mon Sep 17 00:00:00 2001 From: Diego Urgell Date: Wed, 11 Sep 2024 01:27:07 -0700 Subject: [PATCH] Fix dependency incompatibility in github tests (#207) Summary: Pull Request resolved: https://github.com/pytorch/torcheval/pull/207 Differential Revision: D62472378 --- .github/workflows/unit_test.yaml | 4 +--- torcheval/metrics/aggregation/cov.py | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unit_test.yaml b/.github/workflows/unit_test.yaml index 38996aad..b92a6d13 100644 --- a/.github/workflows/unit_test.yaml +++ b/.github/workflows/unit_test.yaml @@ -24,8 +24,7 @@ jobs: shell: bash -l {0} run: | set -eux - conda activate test - conda install pytorch torchaudio torchvision cpuonly -c pytorch-nightly + pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cpu pip install -r requirements.txt pip install -r dev-requirements.txt pip install --no-build-isolation -e ".[dev]" @@ -33,7 +32,6 @@ jobs: shell: bash -l {0} run: | set -eux - conda activate test pytest --cov=. --cov-report xml tests -vv - name: Upload Coverage to Codecov uses: codecov/codecov-action@v2 diff --git a/torcheval/metrics/aggregation/cov.py b/torcheval/metrics/aggregation/cov.py index 24a5af1c..8ff9bd69 100644 --- a/torcheval/metrics/aggregation/cov.py +++ b/torcheval/metrics/aggregation/cov.py @@ -7,21 +7,21 @@ # pyre-strict from collections.abc import Iterable -from typing import Tuple, TypeVar +from typing import Optional, Tuple, TypeVar, Union import torch from torcheval.metrics.metric import Metric from typing_extensions import Self, TypeAlias # TODO: use a NamedTuple? -_T = TypeVar("_T", bound=torch.Tensor | int) +_T = TypeVar("_T", bound=Union[torch.Tensor, int]) _Output: TypeAlias = Tuple[torch.Tensor, torch.Tensor] # mean, cov class Covariance(Metric[_Output]): """Fit sample mean + covariance to empirical distribution""" - def __init__(self, *, device: torch.device | None = None) -> None: + def __init__(self, *, device: Optional[torch.device] = None) -> None: super().__init__(device=device) self.sum: torch.Tensor = self._add_state_and_return( "sum", default=torch.as_tensor(0.0)