Skip to content

Commit

Permalink
Update dependencies and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
durandtibo committed Oct 7, 2023
1 parent 29dc621 commit fe3366f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
20 changes: 14 additions & 6 deletions src/coola/utils/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,17 @@ def is_mps_available() -> bool:
>>> from coola.utils.tensor import is_mps_available
>>> is_mps_available()
"""
return (
is_torch_available()
and hasattr(torch.backends, "mps")
and torch.backends.mps.is_available()
and torch.backends.mps.is_macos13_or_newer()
)
if not is_torch_available():
return False
try:
torch.ones(1, device=torch.device("mps"))
return True
except RuntimeError:
return False
# return (
# is_torch_available()
# and hasattr(torch.backends, "mps")
# and torch.backends.mps.is_available()
# and hasattr(torch.backends.mps, "is_macos13_or_newer")
# and torch.backends.mps.is_macos13_or_newer()
# )
24 changes: 7 additions & 17 deletions tests/unit/utils/test_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ def test_is_cuda_available_false() -> None:
assert not is_cuda_available()


@patch("coola.utils.tensor.is_torch_available", lambda *args, **kwargs: False)
def test_is_cuda_available_no_torch() -> None:
assert not is_cuda_available()


######################################
# Tests for is_mpa_available #
######################################
Expand All @@ -86,21 +91,6 @@ def test_is_mps_available() -> None:
assert isinstance(is_mps_available(), bool)


@torch_available
@patch("torch.backends.mps.is_available", lambda *args, **kwargs: True)
@patch("torch.backends.mps.is_macos13_or_newer", lambda *args, **kwargs: True)
def test_is_mps_available_true() -> None:
assert is_mps_available()


@torch_available
@patch("torch.backends.mps.is_available", lambda *args, **kwargs: False)
def test_is_mps_available_false_not_available() -> None:
assert not is_mps_available()


@torch_available
@patch("torch.backends.mps.is_available", lambda *args, **kwargs: True)
@patch("torch.backends.mps.is_macos13_or_newer", lambda *args, **kwargs: False)
def test_is_mps_available_false_old_macos() -> None:
@patch("coola.utils.tensor.is_torch_available", lambda *args, **kwargs: False)
def test_is_mps_available_no_torch() -> None:
assert not is_mps_available()

0 comments on commit fe3366f

Please sign in to comment.