MCPcopy Create free account
hub / github.com/togethercomputer/OpenChatKit / save_checkpoint

Function save_checkpoint

training/utils/dist_checkpoint_utils.py:64–98  ·  view source on GitHub ↗
(pipe, args)

Source from the content-addressed store, hash-verified

62
63
64def 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
101def save_stream_dataloader_state_dict(dataloader, pipe, args):

Callers 2

train_loopFunction · 0.85
train_loopFunction · 0.85

Calls 2

state_dictMethod · 0.45

Tested by

no test coverage detected