Update autobatch.py (#5538)
Browse files* Update autobatch.py
* Update autobatch.py
* Update autobatch.py
- utils/autobatch.py +6 -5
utils/autobatch.py
CHANGED
@@ -35,11 +35,12 @@ def autobatch(model, imgsz=640, fraction=0.9, batch_size=16):
|
|
35 |
return batch_size
|
36 |
|
37 |
d = str(device).upper() # 'CUDA:0'
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
41 |
f = t - (r + a) # free inside reserved
|
42 |
-
print(f'{prefix}{d} {t:.
|
43 |
|
44 |
batch_sizes = [1, 2, 4, 8, 16]
|
45 |
try:
|
@@ -52,5 +53,5 @@ def autobatch(model, imgsz=640, fraction=0.9, batch_size=16):
|
|
52 |
batch_sizes = batch_sizes[:len(y)]
|
53 |
p = np.polyfit(batch_sizes, y, deg=1) # first degree polynomial fit
|
54 |
b = int((f * fraction - p[1]) / p[0]) # y intercept (optimal batch size)
|
55 |
-
print(f'{prefix}Using batch-size {b} for {d} {t * fraction:.
|
56 |
return b
|
|
|
35 |
return batch_size
|
36 |
|
37 |
d = str(device).upper() # 'CUDA:0'
|
38 |
+
properties = torch.cuda.get_device_properties(device) # device properties
|
39 |
+
t = properties.total_memory / 1024 ** 3 # (GiB)
|
40 |
+
r = torch.cuda.memory_reserved(device) / 1024 ** 3 # (GiB)
|
41 |
+
a = torch.cuda.memory_allocated(device) / 1024 ** 3 # (GiB)
|
42 |
f = t - (r + a) # free inside reserved
|
43 |
+
print(f'{prefix}{d} ({properties.name}) {t:.2f}G total, {r:.2f}G reserved, {a:.2f}G allocated, {f:.2f}G free')
|
44 |
|
45 |
batch_sizes = [1, 2, 4, 8, 16]
|
46 |
try:
|
|
|
53 |
batch_sizes = batch_sizes[:len(y)]
|
54 |
p = np.polyfit(batch_sizes, y, deg=1) # first degree polynomial fit
|
55 |
b = int((f * fraction - p[1]) / p[0]) # y intercept (optimal batch size)
|
56 |
+
print(f'{prefix}Using batch-size {b} for {d} {t * fraction:.2f}G/{t:.2f}G ({fraction * 100:.0f}%)')
|
57 |
return b
|