Back to Cosyvoice

README.Cosyvoice2.Unet

runtime/triton_trtllm/README.Cosyvoice2.Unet.md

2.06.2 KB
Original Source

Accelerating CosyVoice with NVIDIA Triton Inference Server and TensorRT-LLM

Contributed by Yuekai Zhang (NVIDIA).

Quick Start

Launch the service directly with Docker Compose:

sh
docker compose -f docker-compose.cosyvoice2.unet.yml up

Build the Docker Image

To build the image from scratch:

sh
docker build . -f Dockerfile.server -t soar97/triton-cosyvoice:25.06

Run a Docker Container

sh
your_mount_dir=/mnt:/mnt
docker run -it --name "cosyvoice-server" --gpus all --net host -v $your_mount_dir --shm-size=2g soar97/triton-cosyvoice:25.06

Understanding run.sh

The run.sh script orchestrates the entire workflow through numbered stages.

You can run a subset of stages with:

sh
bash run.sh <start_stage> <stop_stage> [service_type]
  • <start_stage>: The stage to start from (0-5).
  • <stop_stage>: The stage to stop after (0-5).

Stages:

  • Stage 0: Downloads the cosyvoice-2 0.5B model from HuggingFace.
  • Stage 1: Converts the HuggingFace checkpoint to the TensorRT-LLM format and builds the TensorRT engines.
  • Stage 2: Creates the Triton model repository and configures the model files. The configuration is adjusted based on whether Decoupled=True (streaming) or Decoupled=False (offline) will be used.
  • Stage 3: Launches the Triton Inference Server.
  • Stage 4: Runs the single-utterance HTTP client for testing.
  • Stage 5: Runs the gRPC benchmark client.
  • Stage 6: Runs the offline inference benchmark test.

Export Models and Launch Server

Inside the Docker container, prepare the models and start the Triton server by running stages 0-3:

sh
# This command runs stages 0, 1, 2, and 3
bash run.sh 0 3

[!TIP] Both streaming and offline (non-streaming) TTS modes are supported. For streaming TTS, set Decoupled=True. For offline TTS, set Decoupled=False. You need to rerun stage 2 if you switch between modes.

Single-Utterance HTTP Client

Sends a single HTTP inference request. This is intended for testing the offline TTS mode (Decoupled=False):

sh
bash run.sh 4 4

Benchmark with client-server mode

To benchmark the running Triton server, pass streaming or offline as the third argument:

sh
bash run.sh 5 5 # [streaming|offline]

# You can also customize parameters such as the number of tasks and the dataset split:
# python3 client_grpc.py --num-tasks 2 --huggingface-dataset yuekai/seed_tts_cosy2 --split-name test_zh --mode [streaming|offline]

[!TIP] It is recommended to run the benchmark multiple times to get stable results after the initial server warm-up.

Benchmark with offline inference mode

For offline inference mode benchmark, please check the below command:

sh
# install FlashCosyVoice for token2wav batching
# git clone https://github.com/yuekaizhang/FlashCosyVoice.git /workspace/FlashCosyVoice -b trt
# cd /workspace/FlashCosyVoice
# pip install -e .
# cd -
# wget https://huggingface.co/yuekai/cosyvoice2_flow_onnx/resolve/main/flow.decoder.estimator.fp32.dynamic_batch.onnx -O $model_scope_model_local_dir/flow.decoder.estimator.fp32.dynamic_batch.onnx

bash run.sh 6 6

# You can also switch to huggingface backend by setting backend=hf

Benchmark Results

The following results were obtained by decoding on a single L20 GPU with 26 prompt audio/target text pairs from the yuekai/seed_tts dataset (approximately 170 seconds of audio):

Client-Server Mode: Streaming TTS (First Chunk Latency)

ModeConcurrencyAvg Latency (ms)P50 Latency (ms)RTF
Streaming, use_spk2info_cache=False1220.43218.070.1237
Streaming, use_spk2info_cache=False2476.97369.250.1022
Streaming, use_spk2info_cache=False41107.341243.750.0922
Streaming, use_spk2info_cache=True1189.88184.810.1155
Streaming, use_spk2info_cache=True2323.04316.830.0905
Streaming, use_spk2info_cache=True4977.68903.680.0733

If your service only needs a fixed speaker, you can set use_spk2info_cache=True in run.sh. To add more speakers, refer to the instructions here.

Client-Server Mode: Offline TTS (Full Sentence Latency)

ModeNoteConcurrencyAvg Latency (ms)P50 Latency (ms)RTF
Offline, Decoupled=False, use_spk2info_cache=FalseCommit1758.04615.790.0891
Offline, Decoupled=False, use_spk2info_cache=FalseCommit21025.93901.680.0657
Offline, Decoupled=False, use_spk2info_cache=FalseCommit41914.131783.580.0610

Offline Inference Mode: Hugginface LLM V.S. TensorRT-LLM

BackendBatch Sizellm_time_secondstotal_time_secondsRTF
HF139.2644.310.2494
HF230.5435.620.2064
HF418.6323.900.1421
HF811.2216.450.0947
HF168.4213.780.0821
TRTLLM112.4617.310.0987
TRTLLM27.6412.650.0739
TRTLLM44.899.380.0539
TRTLLM82.927.230.0418
TRTLLM162.016.630.0386

OpenAI-Compatible Server

To launch an OpenAI-compatible API service, run the following commands:

sh
git clone https://github.com/yuekaizhang/Triton-OpenAI-Speech.git
cd Triton-OpenAI-Speech
pip install -r requirements.txt

# After the Triton service is running, start the FastAPI bridge:
python3 tts_server.py --url http://localhost:8000 --ref_audios_dir ./ref_audios/ --port 10086 --default_sample_rate 24000

# Test the service with curl:
bash test/test_cosyvoice.sh

[!NOTE] Currently, only the offline TTS mode is compatible with the OpenAI-compatible server.

Acknowledgements

This work originates from the NVIDIA CISI project. For more multimodal resources, please see mair-hub.