Skip to content

Commit 5e1a955

Browse files
authored
AutoBatch cudnn.benchmark=True fix (#9448)
* AutoBatch `cudnn.benchmark=True` fix May resolve #9287 Signed-off-by: Glenn Jocher <[email protected]> * Update autobatch.py Signed-off-by: Glenn Jocher <[email protected]> * Update autobatch.py Signed-off-by: Glenn Jocher <[email protected]> * Update general.py Signed-off-by: Glenn Jocher <[email protected]> Signed-off-by: Glenn Jocher <[email protected]>
1 parent db06f49 commit 5e1a955

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

utils/autobatch.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def autobatch(model, imgsz=640, fraction=0.8, batch_size=16):
3333
if device.type == 'cpu':
3434
LOGGER.info(f'{prefix}CUDA not detected, using default CPU batch-size {batch_size}')
3535
return batch_size
36+
if torch.backends.cudnn.benchmark:
37+
LOGGER.info(f'{prefix} ⚠️ Requires torch.backends.cudnn.benchmark=False, using default batch-size {batch_size}')
38+
return batch_size
3639

3740
# Inspect CUDA memory
3841
gb = 1 << 30 # bytes to GiB (1024 ** 3)

utils/general.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def init_seeds(seed=0, deterministic=False):
223223
torch.manual_seed(seed)
224224
torch.cuda.manual_seed(seed)
225225
torch.cuda.manual_seed_all(seed) # for Multi-GPU, exception safe
226-
torch.backends.cudnn.benchmark = True # for faster training
226+
# torch.backends.cudnn.benchmark = True # AutoBatch problem https://github.com/ultralytics/yolov5/issues/9287
227227
if deterministic and check_version(torch.__version__, '1.12.0'): # https://github.com/ultralytics/yolov5/pull/8213
228228
torch.use_deterministic_algorithms(True)
229229
torch.backends.cudnn.deterministic = True

0 commit comments

Comments
 (0)