From cb18cac33d7161ed938c1c4056e17c653df69ad0 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 6 Nov 2021 13:49:00 +0100 Subject: [PATCH] Update autobatch.py (#5538) * Update autobatch.py * Update autobatch.py * Update autobatch.py --- utils/autobatch.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/utils/autobatch.py b/utils/autobatch.py index 1632e9bc6a5a..3f2b4d1a4c38 100644 --- a/utils/autobatch.py +++ b/utils/autobatch.py @@ -35,11 +35,12 @@ def autobatch(model, imgsz=640, fraction=0.9, batch_size=16): return batch_size d = str(device).upper() # 'CUDA:0' - t = torch.cuda.get_device_properties(device).total_memory / 1024 ** 3 # (GB) - r = torch.cuda.memory_reserved(device) / 1024 ** 3 # (GB) - a = torch.cuda.memory_allocated(device) / 1024 ** 3 # (GB) + properties = torch.cuda.get_device_properties(device) # device properties + t = properties.total_memory / 1024 ** 3 # (GiB) + r = torch.cuda.memory_reserved(device) / 1024 ** 3 # (GiB) + a = torch.cuda.memory_allocated(device) / 1024 ** 3 # (GiB) f = t - (r + a) # free inside reserved - print(f'{prefix}{d} {t:.3g}G total, {r:.3g}G reserved, {a:.3g}G allocated, {f:.3g}G free') + print(f'{prefix}{d} ({properties.name}) {t:.2f}G total, {r:.2f}G reserved, {a:.2f}G allocated, {f:.2f}G free') batch_sizes = [1, 2, 4, 8, 16] try: @@ -52,5 +53,5 @@ def autobatch(model, imgsz=640, fraction=0.9, batch_size=16): batch_sizes = batch_sizes[:len(y)] p = np.polyfit(batch_sizes, y, deg=1) # first degree polynomial fit b = int((f * fraction - p[1]) / p[0]) # y intercept (optimal batch size) - print(f'{prefix}Using batch-size {b} for {d} {t * fraction:.3g}G/{t:.3g}G ({fraction * 100:.0f}%)') + print(f'{prefix}Using batch-size {b} for {d} {t * fraction:.2f}G/{t:.2f}G ({fraction * 100:.0f}%)') return b