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

Set compute_type based on device capability #274

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading