Skip to content

Commit 29826ef

Browse files
authored
perf: zero_grad(set_to_none=True) and reduce checkpoint I/O (#83)
* perf: use zero_grad(set_to_none=True) to reduce memory bandwidth * perf: only save HuggingFace checkpoint at final step to reduce I/O stalls
1 parent 30a7f46 commit 29826ef

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

training/train.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def wrap_ddp(model):
664664
for pfc in list_module_pfc:
665665
clip_grad_norm_(pfc.parameters(), max_norm=5, norm_type=2)
666666
opt.step()
667-
opt.zero_grad()
667+
opt.zero_grad(set_to_none=True)
668668

669669
lr_scheduler.step()
670670

@@ -692,8 +692,6 @@ def wrap_ddp(model):
692692
list_head_names=args.list_head_names,
693693
keep_num=20,
694694
)
695-
# Also save in HuggingFace format
696-
save_hf_checkpoint(args.output, backbone, global_step=global_step, image_size=args.image_size[0])
697695

698696
if global_step > args.total_steps:
699697
save_checkpoint(

0 commit comments

Comments
 (0)