Skip to content

Commit

Permalink
Fix dependency incompatibility in github tests (#207)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #207

Reviewed By: JKSenthil

Differential Revision: D62472378

fbshipit-source-id: 200c0395ede64c764f7b67ddb796d2545cb35b64
  • Loading branch information
diego-urgell authored and facebook-github-bot committed Sep 11, 2024
1 parent a88a579 commit de4d85e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/unit_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ 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]"
- name: Run unit tests with coverage
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
Expand Down
4 changes: 3 additions & 1 deletion tests/metrics/aggregation/test_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

# pyre-strict

from typing import List

import torch
from torcheval.metrics import Covariance
from torcheval.utils.test_utils.metric_class_tester import MetricClassTester


class TestCovariance(MetricClassTester):
def _test_covariance_with_input(self, batching: list[int]) -> None:
def _test_covariance_with_input(self, batching: List[int]) -> None:
gen = torch.Generator()
gen.manual_seed(3)
X = torch.randn(sum(batching), 4, generator=gen)
Expand Down
10 changes: 4 additions & 6 deletions torcheval/metrics/aggregation/cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@

# pyre-strict

from collections.abc import Iterable
from typing import Tuple, TypeVar
from typing import Iterable, 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)
Expand All @@ -31,9 +30,8 @@ def __init__(self, *, device: torch.device | None = None) -> None:
)
self.n: int = self._add_state_and_return("n", default=0)

# pyre-fixme[31]: Expression `_T` is not a valid type.
def _add_state_and_return(self, name: str, default: _T) -> _T:
# Helper funcction for pyre
# Helper function for pyre
self._add_state(name, default)
return getattr(self, name)

Expand Down

0 comments on commit de4d85e

Please sign in to comment.