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

Warmup on uneven last-batch-size in validate.py #2243

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
14 changes: 9 additions & 5 deletions validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,15 @@ def validate(args):
model.eval()
with torch.no_grad():
# warmup, reduce variability of first batch time, especially for comparing torchscript vs non
input = torch.randn((args.batch_size,) + tuple(data_config['input_size'])).to(device)
if args.channels_last:
input = input.contiguous(memory_format=torch.channels_last)
with amp_autocast():
model(input)
inputs = [torch.randn((args.batch_size,) + tuple(data_config['input_size'])).to(device)]
last_batch_size = len(dataset) % args.batch_size
if last_batch_size:
inputs.append(torch.randn((last_batch_size,) + tuple(data_config['input_size'])).to(device))
for inp in inputs:
if args.channels_last:
inp = inp.contiguous(memory_format=torch.channels_last)
with amp_autocast():
model(inp)

end = time.time()
for batch_idx, (input, target) in enumerate(loader):
Expand Down