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

Uses MPS (Mac acceleration) by default when available #382

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
MPS (Mac acceleration) by default if available
  • Loading branch information
dwarkeshsp committed Oct 21, 2022
commit bdd0d79b8e533a794e39ed525f59118c0c54513f
7 changes: 6 additions & 1 deletion whisper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ def load_model(name: str, device: Optional[Union[str, torch.device]] = None, dow
"""

if device is None:
device = "cuda" if torch.cuda.is_available() else "cpu"
if torch.cuda.is_available():
device = "cuda"
elif torch.backends.mps.is_available():
device = "mps"
else:
device = "cpu"
if download_root is None:
download_root = os.getenv(
"XDG_CACHE_HOME",
Expand Down
2 changes: 2 additions & 0 deletions whisper/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def transcribe(
if model.device == torch.device("cpu"):
if torch.cuda.is_available():
warnings.warn("Performing inference on CPU when CUDA is available")
if torch.backends.mps.is_available():
warnings.warn("Performing inference on CPU when MPS is available")
if dtype == torch.float16:
warnings.warn("FP16 is not supported on CPU; using FP32 instead")
dtype = torch.float32
Expand Down