INNER CODE UNIT · TypeScript

_cleanup_old_checkpoints

theaniketgiri/create-llm · src/python-callback-templates.ts:181

    def _cleanup_old_checkpoints(self):
        """Remove old checkpoints to keep only save_total_limit"""
        if len(self.checkpoints) > self.save_total_limit:
            # Remove oldest checkpoint
            old_checkpoint = self.checkpoints.pop(0)
            if old_checkpoint.exists():
                old_checkpoint.unlink()
                if self.verbose:
                    print(f"Removed old checkpoint: {old_checkpoint}")
    
    def load_checkpoint(self, checkpoint_path: str, trainer: Any):
        """Load a checkpoint"""
        checkpoint = torch.load(checkpoint_path)
        
        trainer.model.load_state_dict(checkpoint['model_state_dict'])
        trainer.optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
        
        if 'scheduler_state_dict' in checkpoint and hasattr(trainer, 'scheduler'):

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…