Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move trainer.step() before metric.update to overlap between backward pass and allreduce #1609

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripts/detection/faster_rcnn/train_faster_rcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,13 @@ def train(net, train_data, val_data, eval_metric, batch_size, ctx, args):
metric_losses[k].append(result[k])
for k in range(len(add_losses)):
add_losses[k].append(result[len(metric_losses) + k])
trainer.step(batch_size)

for metric, record in zip(metrics, metric_losses):
metric.update(0, record)
for metric, records in zip(metrics2, add_losses):
for pred in records:
metric.update(pred[0], pred[1])
trainer.step(batch_size)

# update metrics
if (not args.horovod or hvd.rank() == 0) and args.log_interval \
Expand Down
7 changes: 5 additions & 2 deletions scripts/instance/mask_rcnn/train_mask_rcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
os.environ['MXNET_EXEC_BULK_EXEC_MAX_NODE_TRAIN_BWD'] = '25'
os.environ['MXNET_GPU_COPY_NTHREADS'] = '1'
os.environ['MXNET_OPTIMIZER_AGGREGATION_SIZE'] = '54'
os.environ['MXNET_USE_FUSION'] = '0
os.environ['MXNET_USE_FUSION'] = '0'

import logging
import time
Expand Down Expand Up @@ -559,6 +559,7 @@ def train(net, train_data, val_data, eval_metric, batch_size, ctx, logger, args)
metric.reset()
tic = time.time()
btic = time.time()
speed = []
train_data_iter = iter(train_data)
next_data_batch = next(train_data_iter)
next_data_batch = split_and_load(next_data_batch, ctx_list=ctx)
Expand Down Expand Up @@ -595,12 +596,14 @@ def train(net, train_data, val_data, eval_metric, batch_size, ctx, logger, args)
except StopIteration:
pass

trainer.step(batch_size)

for metric, record in zip(metrics, metric_losses):
metric.update(0, record)
for metric, records in zip(metrics2, add_losses):
for pred in records:
metric.update(pred[0], pred[1])
trainer.step(batch_size)

if (not args.horovod or hvd.rank() == 0) and args.log_interval \
and not (i + 1) % args.log_interval:
msg = ','.join(['{}={:.3f}'.format(*metric.get()) for metric in metrics + metrics2])
Expand Down