Fix pickling error with CSVLogger (#10388)
* Don't store csv.Dictwriter in ExperimentWriter * Add test for pickle after .save() * Add entry in changelog
This commit is contained in:
parent
c58f84c176
commit
89e1360e75
|
@ -98,6 +98,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
|
|||
- Fixed failure when `DataLoader(batch_size=None)` is passed ([#10345](https://github.com/PyTorchLightning/pytorch-lightning/issues/10345))
|
||||
|
||||
|
||||
- Fixed issue with pickling `CSVLogger` after a call to `CSVLogger.save` ([#10388](https://github.com/PyTorchLightning/pytorch-lightning/pull/10388))
|
||||
|
||||
-
|
||||
|
||||
|
||||
|
|
|
@ -95,9 +95,9 @@ class ExperimentWriter:
|
|||
metrics_keys = list(last_m.keys())
|
||||
|
||||
with open(self.metrics_file_path, "w", newline="") as f:
|
||||
self.writer = csv.DictWriter(f, fieldnames=metrics_keys)
|
||||
self.writer.writeheader()
|
||||
self.writer.writerows(self.metrics)
|
||||
writer = csv.DictWriter(f, fieldnames=metrics_keys)
|
||||
writer.writeheader()
|
||||
writer.writerows(self.metrics)
|
||||
|
||||
|
||||
class CSVLogger(LightningLoggerBase):
|
||||
|
|
|
@ -263,6 +263,10 @@ def _test_loggers_pickle(tmpdir, monkeypatch, logger_class):
|
|||
# the logger needs to remove it from the state before pickle
|
||||
_ = logger.experiment
|
||||
|
||||
# logger also has to avoid adding un-picklable attributes to self in .save
|
||||
logger.log_metrics({"a": 1})
|
||||
logger.save()
|
||||
|
||||
# test pickling loggers
|
||||
pickle.dumps(logger)
|
||||
|
||||
|
|
Loading…
Reference in New Issue