()
| 23 | |
| 24 | |
| 25 | def main(): |
| 26 | args = parser.parse_args() |
| 27 | |
| 28 | dist_init() |
| 29 | |
| 30 | C = Config(args.config) |
| 31 | if args.expname is not None: |
| 32 | C.config['expname'] = args.expname |
| 33 | |
| 34 | S = solver_entry(C) |
| 35 | config_save_to = os.path.join(S.ckpt_path, 'config.yaml') |
| 36 | |
| 37 | # auto resume strategy for spring.submit arun |
| 38 | if args.auto_resume is not None: |
| 39 | args.auto_resume = os.path.join(S.out_dir, args.auto_resume) |
| 40 | if os.path.isdir(args.auto_resume): |
| 41 | max_iter = 0 |
| 42 | filename = os.listdir(args.auto_resume) |
| 43 | for file in filename: |
| 44 | if file.startswith('ckpt_task0') and file.endswith('.pth.tar'): |
| 45 | cur_iter = int(file.split('_')[-1].split('.')[0]) |
| 46 | max_iter = max(max_iter, cur_iter) |
| 47 | if max_iter > 0: |
| 48 | args.load_path = os.path.join(args.auto_resume, |
| 49 | 'ckpt_task_iter_{}.pth.tar'.format(str(max_iter))) |
| 50 | args.recover = True |
| 51 | args.ignore = [] |
| 52 | print('auto-resume from: {}'.format(args.load_path)) |
| 53 | elif args.auto_resume.endswith('.pth.tar'): |
| 54 | tmpl = args.auto_resume.replace('ckpt_task_', 'ckpt_task*_') |
| 55 | import glob |
| 56 | ckpt = glob.glob(tmpl) |
| 57 | if len(ckpt) > 0: |
| 58 | args.load_path = args.auto_resume |
| 59 | args.recover = True |
| 60 | args.ignore = [] |
| 61 | print('auto-resume from: {}'.format(args.load_path)) |
| 62 | else: |
| 63 | print('auto-resume not work:{}'.format(args.auto_resume)) |
| 64 | |
| 65 | #tmp = torch.Tensor(1).cuda() |
| 66 | if not os.path.exists(config_save_to): |
| 67 | shutil.copy(args.config, config_save_to) |
| 68 | |
| 69 | S.initialize(args) |
| 70 | |
| 71 | S.run() |
| 72 | |
| 73 | |
| 74 | if __name__ == '__main__': |
no test coverage detected