From 71f9c057a4d786227d9f5736d21be11ee0ca3a46 Mon Sep 17 00:00:00 2001 From: joecummings Date: Thu, 28 Nov 2024 09:41:49 -0800 Subject: [PATCH] Potential fix for 2090 --- torchtune/training/metric_logging.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/torchtune/training/metric_logging.py b/torchtune/training/metric_logging.py index 42882afa8b..e5399909ba 100644 --- a/torchtune/training/metric_logging.py +++ b/torchtune/training/metric_logging.py @@ -311,12 +311,13 @@ def log_dict(self, payload: Mapping[str, Scalar], step: int) -> None: self.log(name, data, step) def __del__(self) -> None: - if self._writer: + # extra check for when there is an import error + if hasattr(self, "_writer"): self._writer.close() self._writer = None def close(self) -> None: - if self._writer: + if hasattr(self, "_writer"): self._writer.close() self._writer = None