Skip to content

Commit

Permalink
Do not prefer Apple MPS (#8446)
Browse files Browse the repository at this point in the history
Require explicit request for MPS, i.e.
```bash
python detect.py --device mps
```

Reverts #8210 for preferring MPS if available. 

Note that torch MPS is experiencing ongoing compatibility issues in pytorch/pytorch#77886
  • Loading branch information
glenn-jocher authored Jul 2, 2022
1 parent da2ee39 commit 29d79a6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions utils/torch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def select_device(device='', batch_size=0, newline=True):
assert torch.cuda.is_available() and torch.cuda.device_count() >= len(device.replace(',', '')), \
f"Invalid CUDA '--device {device}' requested, use '--device cpu' or pass valid CUDA device(s)"

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

0 comments on commit 29d79a6

Please sign in to comment.