Skip to content

Commit

Permalink
is_autocast_enabled: fix deprecation warning (kornia#2981)
Browse files Browse the repository at this point in the history
* is_autocast_enabled: fix deprecation warning

* Check torch version
  • Loading branch information
adamjstewart authored Aug 26, 2024
1 parent f1561c1 commit 06bc50d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions kornia/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def is_autocast_enabled(both: bool = True) -> bool:
Returns:
Return a Bool,
will always return False for a torch without support, otherwise will be: if both is True
`torch.is_autocast_enabled() or torch.is_autocast_cpu_enabled()`. If both is False will return just
`torch.is_autocast_enabled() or torch.is_autocast_enabled('cpu')`. If both is False will return just
`torch.is_autocast_enabled()`.
"""
if TYPE_CHECKING:
Expand All @@ -316,7 +316,10 @@ def is_autocast_enabled(both: bool = True) -> bool:
return False

if both:
return torch.is_autocast_enabled() or torch.is_autocast_cpu_enabled()
if torch_version_ge(2, 4):
return torch.is_autocast_enabled() or torch.is_autocast_enabled("cpu")
else:
return torch.is_autocast_enabled() or torch.is_autocast_cpu_enabled()

return torch.is_autocast_enabled()

Expand Down

0 comments on commit 06bc50d

Please sign in to comment.