From 056b32bf16635ffcf1018cf049603b3fce5f4087 Mon Sep 17 00:00:00 2001 From: Philip Blair Date: Thu, 11 Feb 2021 16:44:29 +0100 Subject: [PATCH] Fix: Allow hashing of metrics with lists in their state --- pytorch_lightning/metrics/metric.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pytorch_lightning/metrics/metric.py b/pytorch_lightning/metrics/metric.py index 2c910edb8e404d..a4e64090ca99c5 100644 --- a/pytorch_lightning/metrics/metric.py +++ b/pytorch_lightning/metrics/metric.py @@ -333,7 +333,11 @@ def __hash__(self): hash_vals = [self.__class__.__name__] for key in self._defaults.keys(): - hash_vals.append(getattr(self, key)) + val = getattr(self, key) + # Special case: allow list values, so long as their elements are hashable + if isinstance(val, list): + val = tuple(val) + hash_vals.append(val) return hash(tuple(hash_vals))