-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from makaveli10/tensorrt_backend
Tensorrt backend
- Loading branch information
Showing
13 changed files
with
1,460 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Whisper-TensorRT | ||
We have only tested the TensorRT backend in docker so, we recommend docker for a smooth TensorRT backend setup. | ||
**Note**: We use [our fork to setup TensorRT](https://github.com/makaveli10/TensorRT-LLM) | ||
|
||
## Installation | ||
- Install [docker](https://docs.docker.com/engine/install/) | ||
- Install [nvidia-container-toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html) | ||
|
||
- Clone this repo. | ||
```bash | ||
git clone https://github.com/collabora/WhisperLive.git | ||
cd WhisperLive | ||
``` | ||
|
||
- Pull the TensorRT-LLM docker image which we prebuilt for WhisperLive TensorRT backend. | ||
```bash | ||
docker pull ghcr.io/collabora/whisperbot-base:latest | ||
``` | ||
|
||
- Next, we run the docker image and mount WhisperLive repo to the containers `/home` directory. | ||
```bash | ||
docker run -it --gpus all --shm-size=8g \ | ||
--ipc=host --ulimit memlock=-1 --ulimit stack=67108864 \ | ||
-v /path/to/WhisperLive:/home/WhisperLive \ | ||
ghcr.io/collabora/whisperbot-base:latest | ||
``` | ||
|
||
- Make sure to test the installation. | ||
```bash | ||
# export ENV=${ENV:-/etc/shinit_v2} | ||
# source $ENV | ||
python -c "import torch; import tensorrt; import tensorrt_llm" | ||
``` | ||
**NOTE**: Uncomment and update library paths if imports fail. | ||
|
||
## Whisper TensorRT Engine | ||
- 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 | ||
|
||
# convert small multilingual model | ||
bash build_whisper_tensorrt /root/TensorRT-LLM-examples small | ||
``` | ||
|
||
## Run WhisperLive Server with TensorRT Backend | ||
```bash | ||
cd /home/WhisperLive | ||
|
||
# Install requirements | ||
pip install -r requirements/server.txt | ||
|
||
# Required to create mel spectogram | ||
wget --directory-prefix=assets assets/mel_filters.npz https://raw.githubusercontent.com/openai/whisper/main/whisper/assets/mel_filters.npz | ||
|
||
# Run English only model | ||
python3 run_server.py --port 9090 \ | ||
--backend tensorrt \ | ||
--trt_model_path "path/to/whisper_trt/from/build/step" | ||
|
||
# Run Multilingual model | ||
python3 run_server.py --port 9090 \ | ||
--backend tensorrt \ | ||
--trt_model_path "path/to/whisper_trt/from/build/step" \ | ||
--trt_multilingual | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
PyAudio | ||
faster-whisper==0.10.0 | ||
--extra-index-url https://download.pytorch.org/whl/cu111 | ||
torch==1.10.1 | ||
torchaudio==0.10.1 | ||
torch | ||
websockets | ||
onnxruntime==1.16.0 | ||
onnxruntime==1.16.0 | ||
numba |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/bin/bash | ||
|
||
download_and_build_model() { | ||
local model_name="$1" | ||
local model_url="" | ||
|
||
case "$model_name" in | ||
"tiny.en") | ||
model_url="https://openaipublic.azureedge.net/main/whisper/models/d3dd57d32accea0b295c96e26691aa14d8822fac7d9d27d5dc00b4ca2826dd03/tiny.en.pt" | ||
;; | ||
"tiny") | ||
model_url="https://openaipublic.azureedge.net/main/whisper/models/65147644a518d12f04e32d6f3b26facc3f8dd46e5390956a9424a650c0ce22b9/tiny.pt" | ||
;; | ||
"base.en") | ||
model_url="https://openaipublic.azureedge.net/main/whisper/models/25a8566e1d0c1e2231d1c762132cd20e0f96a85d16145c3a00adf5d1ac670ead/base.en.pt" | ||
;; | ||
"base") | ||
model_url="https://openaipublic.azureedge.net/main/whisper/models/ed3a0b6b1c0edf879ad9b11b1af5a0e6ab5db9205f891f668f8b0e6c6326e34e/base.pt" | ||
;; | ||
"small.en") | ||
model_url="https://openaipublic.azureedge.net/main/whisper/models/f953ad0fd29cacd07d5a9eda5624af0f6bcf2258be67c92b79389873d91e0872/small.en.pt" | ||
;; | ||
"small") | ||
model_url="https://openaipublic.azureedge.net/main/whisper/models/9ecf779972d90ba49c06d968637d720dd632c55bbf19d441fb42bf17a411e794/small.pt" | ||
;; | ||
"medium.en") | ||
model_url="https://openaipublic.azureedge.net/main/whisper/models/d7440d1dc186f76616474e0ff0b3b6b879abc9d1a4926b7adfa41db2d497ab4f/medium.en.pt" | ||
;; | ||
"medium") | ||
model_url="https://openaipublic.azureedge.net/main/whisper/models/345ae4da62f9b3d59415adc60127b97c714f32e89e936602e85993674d08dcb1/medium.pt" | ||
;; | ||
"large-v1") | ||
model_url="https://openaipublic.azureedge.net/main/whisper/models/e4b87e7e0bf463eb8e6956e646f1e277e901512310def2c24bf0e11bd3c28e9a/large-v1.pt" | ||
;; | ||
"large-v2") | ||
model_url="https://openaipublic.azureedge.net/main/whisper/models/81f7c96c852ee8fc832187b0132e569d6c3065a3252ed18e56effd0b6a73e524/large-v2.pt" | ||
;; | ||
"large-v3" | "large") | ||
model_url="https://openaipublic.azureedge.net/main/whisper/models/e5b1a55b89c1367dacf97e3e19bfd829a01529dbfdeefa8caeb59b3f1b81dadb/large-v3.pt" | ||
;; | ||
*) | ||
echo "Invalid model name: $model_name" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
echo "Downloading $model_name..." | ||
# wget --directory-prefix=assets "$model_url" | ||
# echo "Download completed: ${model_name}.pt" | ||
if [ ! -f "assets/${model_name}.pt" ]; then | ||
wget --directory-prefix=assets "$model_url" | ||
echo "Download completed: ${model_name}.pt" | ||
else | ||
echo "${model_name}.pt already exists in assets directory." | ||
fi | ||
|
||
local output_dir="whisper_${model_name//./_}" | ||
echo "$output_dir" | ||
echo "Running build script for $model_name with output directory $output_dir" | ||
python3 build.py --output_dir "$output_dir" --use_gpt_attention_plugin --use_gemm_plugin --use_bert_attention_plugin --model_name "$model_name" | ||
echo "Whisper $model_name TensorRT engine built." | ||
echo "=========================================" | ||
echo "Model is located at: $(pwd)/$output_dir" | ||
} | ||
|
||
if [ "$#" -lt 1 ]; then | ||
echo "Usage: $0 <path-to-tensorrt-examples-dir> [model-name]" | ||
exit 1 | ||
fi | ||
|
||
tensorrt_examples_dir="$1" | ||
model_name="${2:-small.en}" | ||
|
||
cd $1/whisper | ||
pip install --no-deps -r requirements.txt | ||
|
||
download_and_build_model "$model_name" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.