Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer MPS over CPU if available #8210

Merged
merged 3 commits into from
Jun 17, 2022
Merged

Prefer MPS over CPU if available #8210

merged 3 commits into from
Jun 17, 2022

Conversation

glenn-jocher
Copy link
Member

@glenn-jocher glenn-jocher commented Jun 14, 2022

Attempts to prefer Apple MPS if supported and available over CPU for all YOLOv5 ops. May resolve #8207

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Improvements in device selection logic for YOLOv5 model loading.

📊 Key Changes

  • Refactored device selection code in hubconf.py by removing a redundant check that defaulted to CUDA if available.
  • Updated select_device() function in utils/torch_utils.py:
    • Simplified the CUDA device selection condition.
    • Included a check for Apple's Metal Performance Shaders (MPS), leveraging GPU-like acceleration if available and not on CPU.
    • Automatically defaults to using the CPU if neither CUDA nor MPS is available.
    • Cleaned up code readability and documented preference order (CUDA > MPS > CPU).

🎯 Purpose & Impact

  • 🎨 Streamlines the device selection process for users, offering a clearer logic flow.
  • 🏃‍♂️ Speeds up initial loading of the YOLOv5 model by prioritizing GPU usage when available for better performance.
  • 🍏 Exploits MPS on compatible Apple devices, enhancing performance on Mac hardware where MPS is supported.
  • 🆕 Ensures compatibility across a wider range of devices by properly handling device options and fallbacks.
  • 💻 Users without GPU support will automatically fall back to CPU without needing extra configuration.

@glenn-jocher glenn-jocher self-assigned this Jun 14, 2022
@glenn-jocher glenn-jocher mentioned this pull request Jun 14, 2022
@glenn-jocher glenn-jocher merged commit 303f378 into master Jun 17, 2022
@glenn-jocher glenn-jocher deleted the mps/prefer branch June 17, 2022 16:28
glenn-jocher added a commit that referenced this pull request Jul 2, 2022
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
glenn-jocher added a commit that referenced this pull request Jul 2, 2022
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
Shivvrat pushed a commit to Shivvrat/epic-yolov5 that referenced this pull request Jul 12, 2022
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
ctjanuhowski pushed a commit to ctjanuhowski/yolov5 that referenced this pull request Sep 8, 2022
* Prefer MPS over CPU if available

* Update torch_utils.py
ctjanuhowski pushed a commit to ctjanuhowski/yolov5 that referenced this pull request Sep 8, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant