Skip to content

Commit 1a34a67

Browse files
glenn-jocherClay Januhowski
authored andcommitted
Do not prefer Apple MPS (ultralytics#8446)
Require explicit request for MPS, i.e. ```bash python detect.py --device mps ``` Reverts ultralytics#8210 for preferring MPS if available. Note that torch MPS is experiencing ongoing compatibility issues in pytorch/pytorch#77886
1 parent 059f940 commit 1a34a67

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

utils/torch_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def select_device(device='', batch_size=0, newline=True):
6262
assert torch.cuda.is_available() and torch.cuda.device_count() >= len(device.replace(',', '')), \
6363
f"Invalid CUDA '--device {device}' requested, use '--device cpu' or pass valid CUDA device(s)"
6464

65-
if not cpu and torch.cuda.is_available(): # prefer GPU if available
65+
if not (cpu or mps) and torch.cuda.is_available(): # prefer GPU if available
6666
devices = device.split(',') if device else '0' # range(torch.cuda.device_count()) # i.e. 0,1,6,7
6767
n = len(devices) # device count
6868
if n > 1 and batch_size > 0: # check batch_size is divisible by device_count
@@ -72,7 +72,7 @@ def select_device(device='', batch_size=0, newline=True):
7272
p = torch.cuda.get_device_properties(i)
7373
s += f"{'' if i == 0 else space}CUDA:{d} ({p.name}, {p.total_memory / (1 << 20):.0f}MiB)\n" # bytes to MB
7474
arg = 'cuda:0'
75-
elif not cpu and getattr(torch, 'has_mps', False) and torch.backends.mps.is_available(): # prefer MPS if available
75+
elif mps and getattr(torch, 'has_mps', False) and torch.backends.mps.is_available(): # prefer MPS if available
7676
s += 'MPS\n'
7777
arg = 'mps'
7878
else: # revert to CPU

0 commit comments

Comments
 (0)