Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/schnetpack/train/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ def on_fit_start(self, trainer, pl_module: AtomisticTask):
if self._to_load is not None:
self.ema.load_state_dict(self._to_load)
self._to_load = None
if self.ema.collected_params is not None:
# checkpoints hold the EMA average (saved during validation);
# restore the raw training weights before store()/copy_to()
self.ema.restore()

# load average parameters, to have same starting point as after validation
self.ema.store()
Expand All @@ -141,6 +145,10 @@ def on_train_batch_end(self, trainer, pl_module: AtomisticTask, *args, **kwargs)
def on_validation_epoch_start(
self, trainer: "pl.Trainer", pl_module: AtomisticTask, *args, **kwargs
):
if trainer.sanity_checking:
# on_fit_start already stored the raw weights and copied the EMA
# average in; storing again would overwrite them with the average
return
self.ema.store()
self.ema.copy_to()

Expand Down
Loading