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

Adding CUDA / GPU support to whisper model #809

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion buzz/transcriber/recording_transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import threading
from typing import Optional

import torch
import numpy as np
import sounddevice
from sounddevice import PortAudioError
Expand Down Expand Up @@ -60,7 +61,8 @@
keep_samples = int(0.15 * self.sample_rate)

if self.transcription_options.model.model_type == ModelType.WHISPER:
model = whisper.load_model(model_path)
device = "cuda" if torch.cuda.is_available() else "cpu"
model = whisper.load_model(model_path, device=device)

Check warning on line 65 in buzz/transcriber/recording_transcriber.py

View check run for this annotation

Codecov / codecov/patch

buzz/transcriber/recording_transcriber.py#L64-L65

Added lines #L64 - L65 were not covered by tests
elif self.transcription_options.model.model_type == ModelType.WHISPER_CPP:
model = WhisperCpp(model_path)
elif self.transcription_options.model.model_type == ModelType.FASTER_WHISPER:
Expand Down
4 changes: 3 additions & 1 deletion buzz/transcriber/whisper_file_transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import multiprocessing
import re
import sys
import torch
from multiprocessing.connection import Connection
from threading import Thread
from typing import Optional, List
Expand Down Expand Up @@ -168,7 +169,8 @@ def transcribe_faster_whisper(cls, task: FileTranscriptionTask) -> List[Segment]

@classmethod
def transcribe_openai_whisper(cls, task: FileTranscriptionTask) -> List[Segment]:
model = whisper.load_model(task.model_path)
device = "cuda" if torch.cuda.is_available() else "cpu"
model = whisper.load_model(task.model_path, device=device)

if task.transcription_options.word_level_timings:
stable_whisper.modify_model(model)
Expand Down
Loading