Skip to content

Commit

Permalink
AutoBatch cudnn.benchmark=True fix
Browse files Browse the repository at this point in the history
May resolve #9287

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
  • Loading branch information
glenn-jocher committed Sep 16, 2022
1 parent db06f49 commit 378742e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions utils/autobatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import numpy as np
import torch
from torch.backends import cudnn

from utils.general import LOGGER, colorstr
from utils.torch_utils import profile
Expand Down Expand Up @@ -46,11 +47,14 @@ def autobatch(model, imgsz=640, fraction=0.8, batch_size=16):

# Profile batch sizes
batch_sizes = [1, 2, 4, 8, 16]
bm = cudnn.benchmark
cudnn.benchmark = False # avoid benchmark interference https://github.com/ultralytics/yolov5/issues/9287
try:
img = [torch.empty(b, 3, imgsz, imgsz) for b in batch_sizes]
results = profile(img, model, n=3, device=device)
except Exception as e:
LOGGER.warning(f'{prefix}{e}')
cudnn.benchmark = bm # reset to original value

# Fit a solution
y = [x[2] for x in results if x] # memory [2]
Expand Down

0 comments on commit 378742e

Please sign in to comment.