| 62 | |
| 63 | |
| 64 | def save_checkpoint(config, epoch, model, max_accuracy, optimizer, lr_scheduler, logger): |
| 65 | save_state = {'model': model.state_dict(), |
| 66 | 'optimizer': optimizer.state_dict(), |
| 67 | 'lr_scheduler': lr_scheduler.state_dict(), |
| 68 | 'max_accuracy': max_accuracy, |
| 69 | 'epoch': epoch, |
| 70 | 'config': config} |
| 71 | if config.AMP_OPT_LEVEL != "O0": |
| 72 | save_state['amp'] = amp.state_dict() |
| 73 | |
| 74 | save_path = os.path.join(config.OUTPUT, f'ckpt_epoch_{epoch}.pth') |
| 75 | logger.info(f"{save_path} saving......") |
| 76 | torch.save(save_state, save_path) |
| 77 | torch.save(save_state, os.path.join(config.OUTPUT, f'checkpoint.pth')) |
| 78 | logger.info(f"{save_path} saved !!!") |
| 79 | |
| 80 | |
| 81 | def get_grad_norm(parameters, norm_type=2): |