(pipe, args)
| 62 | |
| 63 | |
| 64 | def save_checkpoint(pipe, args): |
| 65 | |
| 66 | latest_step = pipe.global_step |
| 67 | checkpoint_step_path = os.path.join(args.checkpoint_path, f"checkpoint_{latest_step}") |
| 68 | |
| 69 | os.system(f"mkdir -p {checkpoint_step_path}") |
| 70 | |
| 71 | torch.save( |
| 72 | pipe.model.model.state_dict(), |
| 73 | os.path.join( |
| 74 | checkpoint_step_path, f'prank_{get_pipeline_parallel_rank()}_checkpoint.pt' |
| 75 | ) |
| 76 | ) |
| 77 | |
| 78 | torch.save( |
| 79 | pipe.optimizer.state_dict(), |
| 80 | os.path.join( |
| 81 | checkpoint_step_path, f'prank_{get_pipeline_parallel_rank()}_optimizer.pt' |
| 82 | ) |
| 83 | ) |
| 84 | |
| 85 | torch.save( |
| 86 | pipe.scheduler.state_dict(), |
| 87 | os.path.join( |
| 88 | checkpoint_step_path, f'prank_{get_pipeline_parallel_rank()}_scheduler.pt' |
| 89 | ) |
| 90 | ) |
| 91 | |
| 92 | with open(os.path.join(checkpoint_step_path, 'meta.json'), 'w') as f: |
| 93 | json.dump({ |
| 94 | 'step': latest_step, |
| 95 | }, f) |
| 96 | |
| 97 | with open(os.path.join(args.checkpoint_path, 'latest'), 'w') as f: |
| 98 | f.write(f"{latest_step}") |
| 99 | |
| 100 | |
| 101 | def save_stream_dataloader_state_dict(dataloader, pipe, args): |
no test coverage detected