Use the export_trt.sh script to convert CosyVoice2 ONNX models into TensorRT engine plans (.plan files). This process requires a local installation of TensorRT compatible with your CUDA version.
Prerequisites
- Download TensorRT: Obtain the appropriate TensorRT version from the NVIDIA TensorRT download page.
- Compatibility: Ensure your TensorRT version matches your system and CUDA version (e.g., for Linux + CUDA 12.4, use
TensorRT-10.0.1.6.Linux.x86_64-gnu.cuda-12.4.tar.gz).
Usage
Before running the script, you must configure the following environment variables within the script:
TRT_DIR: The path to your extracted TensorRT directory.MODEL_DIR: The directory containing the CosyVoice2 ONNX models.
The script performs two main exports for the flow.decoder.estimator.fp32.onnx model:
- FP32 Engine: Saves to
$MODEL_DIR/flow.decoder.estimator.fp32.mygpu.plan. - FP16 Engine: Uses the
--fp16 flag and saves to $MODEL_DIR/flow.decoder.estimator.fp16.mygpu.plan.
Note: The script automatically updates LD_LIBRARY_PATH to include the TensorRT library path and the standard CUDA library path.
# Edit these variables in cosyvoice/bin/export_trt.sh
TRT_DIR=<YOUR_TRT_DIR>
MODEL_DIR=<COSYVOICE2_MODEL_DIR>
# The script then executes trtexec commands similar to:
$TRT_DIR/bin/trtexec --onnx=$MODEL_DIR/flow.decoder.estimator.fp32.onnx --saveEngine=$MODEL_DIR/flow.decoder.estimator.fp32.mygpu.plan --minShapes=x:2x80x4,mask:2x1x4,mu:2x80x4,cond:2x80x4 --optShapes=x:2x80x193,mask:2x1x193,mu:2x80x193,cond:2x80x193 --maxShapes=x:2x80x6800,mask:2x1x6800,mu:2x80x6800,cond:2x80x6800 --inputIOFormats=fp32:chw,fp32:chw,fp32:chw,fp32:chw,fp32:chw,fp32:chw --outputIOFormats=fp32:chw