@@ -640,7 +640,7 @@ def _save_last_checkpoint(self, trainer: "pl.Trainer", monitor_candidates: Dict[
640
640
previous , self .last_model_path = self .last_model_path , filepath
641
641
self ._save_checkpoint (trainer , filepath )
642
642
if previous and previous != filepath :
643
- trainer . strategy . remove_checkpoint ( previous )
643
+ self . _remove_checkpoint ( trainer , previous )
644
644
645
645
def _save_monitor_checkpoint (self , trainer : "pl.Trainer" , monitor_candidates : Dict [str , Tensor ]) -> None :
646
646
assert self .monitor
@@ -659,7 +659,7 @@ def _save_none_monitor_checkpoint(self, trainer: "pl.Trainer", monitor_candidate
659
659
previous , self .best_model_path = self .best_model_path , filepath
660
660
self ._save_checkpoint (trainer , filepath )
661
661
if self .save_top_k == 1 and previous and previous != filepath :
662
- trainer . strategy . remove_checkpoint ( previous )
662
+ self . _remove_checkpoint ( trainer , previous )
663
663
664
664
def _update_best_and_save (
665
665
self , current : Tensor , trainer : "pl.Trainer" , monitor_candidates : Dict [str , Tensor ]
@@ -701,7 +701,7 @@ def _update_best_and_save(
701
701
self ._save_checkpoint (trainer , filepath )
702
702
703
703
if del_filepath is not None and filepath != del_filepath :
704
- trainer . strategy . remove_checkpoint ( del_filepath )
704
+ self . _remove_checkpoint ( trainer , del_filepath )
705
705
706
706
def to_yaml (self , filepath : Optional [_PATH ] = None ) -> None :
707
707
"""Saves the `best_k_models` dict containing the checkpoint paths with the corresponding scores to a YAML
@@ -718,3 +718,7 @@ def file_exists(self, filepath: _PATH, trainer: "pl.Trainer") -> bool:
718
718
state to diverge between ranks."""
719
719
exists = self ._fs .exists (filepath )
720
720
return trainer .strategy .broadcast (exists )
721
+
722
+ def _remove_checkpoint (self , trainer : "pl.Trainer" , filepath : str ) -> None :
723
+ """Calls the strategy to remove the checkpoint file."""
724
+ trainer .strategy .remove_checkpoint (filepath )
0 commit comments