Skip to content

Commit

Permalink
Merge pull request #274 from makaveli10/fallback_to_fp32
Browse files Browse the repository at this point in the history
Set compute_type based on device capability.
  • Loading branch information
zoq authored Sep 3, 2024
2 parents 30f78a2 + 380f073 commit 8e7e329
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion whisper_live/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,9 +787,15 @@ def __init__(self, websocket, task="transcribe", device=None, language=None, cli
self.no_speech_thresh = 0.45

device = "cuda" if torch.cuda.is_available() else "cpu"
if device == "cuda":
major, _ = torch.cuda.get_device_capability(device)
self.compute_type = "float16" if major >= 7 else "float32"
else:
self.compute_type = "int8"

if self.model_size_or_path is None:
return
logging.info(f"Using Device={device} with precision {self.compute_type}")

if single_model:
if ServeClientFasterWhisper.SINGLE_MODEL is None:
Expand Down Expand Up @@ -822,7 +828,7 @@ def create_model(self, device):
self.transcriber = WhisperModel(
self.model_size_or_path,
device=device,
compute_type="int8" if device == "cpu" else "float16",
compute_type=self.compute_type,
local_files_only=False,
)

Expand Down

0 comments on commit 8e7e329

Please sign in to comment.