Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix backward compatability for older versions of lightning #182

Merged
merged 14 commits into from
Apr 20, 2021
6 changes: 5 additions & 1 deletion torchmetrics/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from torchmetrics.utilities import apply_to_collection
from torchmetrics.utilities.data import _flatten, dim_zero_cat, dim_zero_mean, dim_zero_sum
from torchmetrics.utilities.distributed import gather_all_tensors
from torchmetrics.utilities.imports import _LIGHTNING_GREATER_THAN_1_2_8


class Metric(nn.Module, ABC):
Expand Down Expand Up @@ -256,7 +257,10 @@ def reset(self):
"""
This method automatically resets the metric state variables to their default value.
"""
self._computed = None
# lower lightning versions requires this implicitly to log metric objects correctly
# in self.log
if _LIGHTNING_GREATER_THAN_1_2_8:
self._computed = None
Borda marked this conversation as resolved.
Show resolved Hide resolved

for attr, default in self._defaults.items():
current_val = getattr(self, attr)
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/utilities/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ def _compare_version(package: str, op, version) -> bool:
_TORCH_LOWER_1_6 = _compare_version("torch", operator.lt, "1.6.0")
_TORCH_GREATER_EQUAL_1_6 = _compare_version("torch", operator.ge, "1.6.0")
_TORCH_GREATER_EQUAL_1_7 = _compare_version("torch", operator.ge, "1.7.0")
_LIGHTNING_GREATER_THAN_1_2_8 = _compare_version("pytorch_lightning", operator.gt, "1.2.8")