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

Tensorrt model warmup #116

Merged
merged 7 commits into from
Jan 31, 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
5 changes: 3 additions & 2 deletions TensorRT_whisper.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ python -c "import torch; import tensorrt; import tensorrt_llm"
- We build `small.en` and `small` multilingual TensorRT engine. The script logs the path of the directory with Whisper TensorRT engine. We need the model_path to run the server.
```bash
# convert small.en
bash build_whisper_tensorrt /root/TensorRT-LLM-examples small.en
bash scripts/build_whisper_tensorrt.sh /root/TensorRT-LLM-examples small.en

# convert small multilingual model
bash build_whisper_tensorrt /root/TensorRT-LLM-examples small
bash scripts/build_whisper_tensorrt.sh /root/TensorRT-LLM-examples small
```

## Run WhisperLive Server with TensorRT Backend
```bash
cd /home/WhisperLive

# Install requirements
bash scripts/setup.sh
pip install -r requirements/server.txt

# Required to create mel spectogram
Expand Down
6 changes: 5 additions & 1 deletion requirements/server.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ faster-whisper==0.10.0
torch
websockets
onnxruntime==1.16.0
numba
numba
openai-whisper
kaldialign
soundfile
ffmpeg-python
7 changes: 7 additions & 0 deletions whisper_live/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ def __init__(
language=self.language,
task=self.task
)
self.warmup()

# threading
self.trans_thread = threading.Thread(target=self.speech_to_text)
Expand All @@ -410,6 +411,12 @@ def __init__(
}
)
)

def warmup(self, warmup_steps=10):
logging.info("[INFO:] Warming up TensorRT engine..")
mel, duration = self.transcriber.log_mel_spectrogram("tests/jfk.flac")
for i in range(warmup_steps):
last_segment = self.transcriber.transcribe(mel)

def set_eos(self, eos):
self.lock.acquire()
Expand Down
4 changes: 2 additions & 2 deletions whisper_live/transcriber_tensorrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from whisper.tokenizer import get_tokenizer
from whisper_live.tensorrt_utils import (mel_filters, store_transcripts,
write_error_stats, load_audio_wav_format,
pad_or_trim)
pad_or_trim, load_audio)

import tensorrt_llm
import tensorrt_llm.logger as logger
Expand Down Expand Up @@ -337,4 +337,4 @@ def decode_wav_file(
if normalizer:
prediction = normalizer(prediction)

return prediction.strip()
return prediction.strip()
Loading