From a2501e33dd80f27718d359b35bc3a5081f537f3e Mon Sep 17 00:00:00 2001 From: qqgu Date: Mon, 3 Jun 2024 11:22:53 +0800 Subject: [PATCH] fix: delete checkpoint files exceeding maximum limit --- dptb/plugins/saver.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dptb/plugins/saver.py b/dptb/plugins/saver.py index 4c969705..eb796bf4 100644 --- a/dptb/plugins/saver.py +++ b/dptb/plugins/saver.py @@ -68,6 +68,14 @@ def iteration(self, **kwargs): delete_path = os.path.join(self.checkpoint_path, delete_name+".pth") os.remove(delete_path) + if len(self.latest_quene) > max_ckpt: + delete_name = self.latest_quene.pop(0) + delete_path = os.path.join(self.checkpoint_path, delete_name+".pth") + try: + os.remove(delete_path) + except: + log.info(f"Failed to delete the checkpoint file {delete_path}.") + self._save( name=name, model=self.trainer.model,