MCPcopy Create free account
hub / github.com/SwinTransformer/Transformer-SSL / save_checkpoint

Function save_checkpoint

utils.py:64–78  ·  view source on GitHub ↗
(config, epoch, model, max_accuracy, optimizer, lr_scheduler, logger)

Source from the content-addressed store, hash-verified

62
63
64def 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
81def get_grad_norm(parameters, norm_type=2):

Callers 3

mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected