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

Add support for Nvidia optimum #113

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.vscode/
.vscode/
.idea/
30 changes: 21 additions & 9 deletions src/insanely_fast_whisper/cli.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import json
import argparse
import torch
from transformers import pipeline
from pyannote.audio import Pipeline
from rich.progress import Progress, TimeElapsedColumn, BarColumn, TextColumn
import torch


from .utils.diarize import (
diarize_audio,
Expand Down Expand Up @@ -94,9 +91,24 @@
)


def get_pipeline(device_id):
try:
if device_id != "cuda":
from transformers import pipeline
else:
from optimum.nvidia.pipelines import pipeline
return pipeline
except ImportError as e:
raise ImportError(f"Failed to import the required pipeline module: {e}")
except Exception as e:
raise Exception(f"An unexpected error occurred: {e}")


def main():
args = parser.parse_args()

pipeline = get_pipeline(args.device_id)

pipe = pipeline(
"automatic-speech-recognition",
model=args.model_name,
Expand All @@ -116,9 +128,9 @@ def main():
language = None if args.language == "None" else args.language

with Progress(
TextColumn("🤗 [progress.description]{task.description}"),
BarColumn(style="yellow1", pulse_style="white"),
TimeElapsedColumn(),
TextColumn("🤗 [progress.description]{task.description}"),
BarColumn(style="yellow1", pulse_style="white"),
TimeElapsedColumn(),
) as progress:
progress.add_task("[yellow]Transcribing...", total=None)

Expand All @@ -139,9 +151,9 @@ def main():
torch.device("mps" if args.device_id == "mps" else f"cuda:{args.device_id}")
)
with Progress(
TextColumn("🤗 [progress.description]{task.description}"),
BarColumn(style="yellow1", pulse_style="white"),
TimeElapsedColumn(),
TextColumn("🤗 [progress.description]{task.description}"),
BarColumn(style="yellow1", pulse_style="white"),
TimeElapsedColumn(),
) as progress:
progress.add_task("[yellow]Segmenting...", total=None)

Expand Down