def checkpoint(self, epoch_info: EpochInfo, model: Model):
self.clean(epoch_info.global_epoch_idx - <NUM_LIT:1>)<EOL>self._make_sure_dir_exists()<EOL>torch.save(model.state_dict(), self.checkpoint_filename(epoch_info.global_epoch_idx))<EOL>hidden_state = epoch_info.state_dict()<EOL>self.checkpoint_strategy.write_state_dict(hidden_state)<EOL>torch.save(hidden_state, self.checkpoint_hidden_filename(epoch_info.global_epoch_idx))<EOL>if epoch_info.global_epoch_idx > <NUM_LIT:1> and self.checkpoint_strategy.should_delete_previous_checkpoint(<EOL>epoch_info.global_epoch_idx):<EOL><INDENT>prev_epoch_idx = epoch_info.global_epoch_idx - <NUM_LIT:1><EOL>os.remove(self.checkpoint_filename(prev_epoch_idx))<EOL>os.remove(self.checkpoint_hidden_filename(prev_epoch_idx))<EOL><DEDENT>if self.checkpoint_strategy.should_store_best_checkpoint(epoch_info.global_epoch_idx, epoch_info.result):<EOL><INDENT>best_checkpoint_idx = self.checkpoint_strategy.current_best_checkpoint_idx<EOL>if best_checkpoint_idx is not None:<EOL><INDENT>os.remove(self.checkpoint_best_filename(best_checkpoint_idx))<EOL><DEDENT>torch.save(model.state_dict(), self.checkpoint_best_filename(epoch_info.global_epoch_idx))<EOL>self.checkpoint_strategy.store_best_checkpoint_idx(epoch_info.global_epoch_idx)<EOL><DEDENT>self.backend.store(epoch_info.result)<EOL>
When epoch is done, we persist the training state