Skip to content

Commit

Permalink
Merge pull request #182 from jhj0517/fix/mac-compatibility
Browse files Browse the repository at this point in the history
Fix mac device bug
  • Loading branch information
jhj0517 authored Jun 26, 2024
2 parents 5cbd5e7 + ed88f88 commit 8f3aba1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/whisper/faster_whisper_inference.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import time
import numpy as np
import torch
from typing import BinaryIO, Union, Tuple, List
import faster_whisper
from faster_whisper.vad import VadOptions
Expand All @@ -25,6 +26,7 @@ def __init__(self,
args=args
)
self.model_paths = self.get_model_paths()
self.device = self.get_device()
self.available_models = self.model_paths.keys()
self.available_compute_types = ctranslate2.get_supported_compute_types(
"cuda") if self.device == "cuda" else ctranslate2.get_supported_compute_types("cpu")
Expand Down Expand Up @@ -155,3 +157,12 @@ def get_model_paths(self):
if model_name not in whisper.available_models():
model_paths[model_name] = os.path.join(webui_dir, self.model_dir, model_name)
return model_paths

@staticmethod
def get_device():
if torch.cuda.is_available():
return "cuda"
elif torch.backends.mps.is_available():
return "auto"
else:
return "cpu"

0 comments on commit 8f3aba1

Please sign in to comment.