| 49 | |
| 50 | |
| 51 | def save_checkpoint(config, epoch, model, max_accuracy, optimizer, lr_scheduler, logger): |
| 52 | save_state = {'model': model.state_dict(), |
| 53 | 'optimizer': optimizer.state_dict(), |
| 54 | 'lr_scheduler': lr_scheduler.state_dict(), |
| 55 | 'max_accuracy': max_accuracy, |
| 56 | 'epoch': epoch, |
| 57 | 'config': config} |
| 58 | |
| 59 | save_path = os.path.join(config.OUTPUT, f'ckpt_epoch_{epoch}.pth') |
| 60 | logger.info(f"{save_path} saving......") |
| 61 | torch.save(save_state, save_path) |
| 62 | logger.info(f"{save_path} saved !!!") |
| 63 | |
| 64 | |
| 65 | def get_grad_norm(parameters, norm_type=2): |