Skip to content

imagenet: add rank indicator to progress summary when distributed #551

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 11 additions & 2 deletions imagenet/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def train(train_loader, model, criterion, optimizer, epoch, args):
top1 = AverageMeter('Acc@1', ':6.2f')
top5 = AverageMeter('Acc@5', ':6.2f')
progress = ProgressMeter(len(train_loader), batch_time, data_time, losses, top1,
top5, prefix="Epoch: [{}]".format(epoch))
top5, prefix="Epoch: [{}]{}".format(epoch, rank_indicator(args)))

# switch to train mode
model.train()
Expand Down Expand Up @@ -306,7 +306,7 @@ def validate(val_loader, model, criterion, args):
top1 = AverageMeter('Acc@1', ':6.2f')
top5 = AverageMeter('Acc@5', ':6.2f')
progress = ProgressMeter(len(val_loader), batch_time, losses, top1, top5,
prefix='Test: ')
prefix='Test{}: '.format(rank_indicator(args)))

# switch to evaluate mode
model.eval()
Expand Down Expand Up @@ -348,6 +348,15 @@ def save_checkpoint(state, is_best, filename='checkpoint.pth.tar'):
shutil.copyfile(filename, 'model_best.pth.tar')


def rank_indicator(args):
if args.distributed:
digits = len(str(args.world_size))
indicator = '[{rank:{width}}]'.format(rank=args.rank, width=digits)
else:
indicator = ''
return indicator


class AverageMeter(object):
"""Computes and stores the average and current value"""
def __init__(self, name, fmt=':f'):
Expand Down