Skip to content

Commit

Permalink
Modify the timing manner of data timer and forward timer (open-mmlab#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jihanyang authored Aug 17, 2022
1 parent 57b1955 commit dd2edf9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tools/train_utils/train_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def train_one_epoch(model, optimizer, train_loader, model_func, lr_scheduler, ac
batch_time = common_utils.AverageMeter()
forward_time = common_utils.AverageMeter()

end = time.time()
for cur_it in range(total_it_each_epoch):
end = time.time()
try:
batch = next(dataloader_iter)
except StopIteration:
Expand All @@ -46,16 +46,16 @@ def train_one_epoch(model, optimizer, train_loader, model_func, lr_scheduler, ac

loss, tb_dict, disp_dict = model_func(model, batch)

forward_timer = time.time()
cur_forward_time = forward_timer - data_timer

loss.backward()
clip_grad_norm_(model.parameters(), optim_cfg.GRAD_NORM_CLIP)
optimizer.step()

accumulated_iter += 1


cur_forward_time = time.time() - data_timer
cur_batch_time = time.time() - end
end = time.time()

# average reduce
avg_data_time = commu_utils.average_reduce_value(cur_data_time)
avg_forward_time = commu_utils.average_reduce_value(cur_forward_time)
Expand Down

0 comments on commit dd2edf9

Please sign in to comment.