From 93769be72ff8d1a9a1b5a21a9bd8b55dd67900f5 Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Tue, 13 Aug 2024 12:45:36 +0200 Subject: [PATCH 1/2] is_autocast_enabled: fix deprecation warning --- kornia/utils/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kornia/utils/helpers.py b/kornia/utils/helpers.py index 3738ee21c6..42f5f7f286 100644 --- a/kornia/utils/helpers.py +++ b/kornia/utils/helpers.py @@ -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: @@ -316,7 +316,7 @@ def is_autocast_enabled(both: bool = True) -> bool: return False if both: - return torch.is_autocast_enabled() or torch.is_autocast_cpu_enabled() + return torch.is_autocast_enabled() or torch.is_autocast_enabled("cpu") return torch.is_autocast_enabled() From 90185f58c8f66a541c003526f051b8d607c4a8a7 Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Wed, 14 Aug 2024 17:16:40 +0200 Subject: [PATCH 2/2] Check torch version --- kornia/utils/helpers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kornia/utils/helpers.py b/kornia/utils/helpers.py index 42f5f7f286..4805afdae1 100644 --- a/kornia/utils/helpers.py +++ b/kornia/utils/helpers.py @@ -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_enabled("cpu") + 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()