Skip to content

Commit

Permalink
Set compute_type based on device capability
Browse files Browse the repository at this point in the history
Signed-off-by: makaveli10 <[email protected]>
  • Loading branch information
makaveli10 committed Sep 3, 2024
1 parent 30f78a2 commit 380f073
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 380f073

Please sign in to comment.