run.sh 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. export CUDA_VISIBLE_DEVICES=0
  2. export PYTHONPATH=/home/scratch.yuekaiz_wwfo_1/tts/cosyvoice/CosyVoice:$PYTHONPATH
  3. export PYTHONPATH=/home/scratch.yuekaiz_wwfo_1/tts/cosyvoice/CosyVoice/third_party/Matcha-TTS:$PYTHONPATH
  4. stage=$1
  5. stop_stage=$2
  6. huggingface_model_local_dir=/home/scratch.yuekaiz_wwfo_1/tts/cosyvoice/cosyvoice2_llm
  7. model_scope_model_local_dir=/home/scratch.yuekaiz_wwfo_1/tts/cosyvoice/CosyVoice2-0.5B
  8. trt_dtype=bfloat16
  9. trt_weights_dir=/home/scratch.yuekaiz_wwfo_1/tts/cosyvoice/trt_weights_${trt_dtype}
  10. trt_engines_dir=/home/scratch.yuekaiz_wwfo_1/tts/cosyvoice/trt_engines_${trt_dtype}
  11. model_repo=./model_repo_cosyvoice2
  12. if [ $stage -le 0 ] && [ $stop_stage -ge 0 ]; then
  13. echo " "
  14. huggingface-cli download --local-dir cosyvoice2_llm yuekai/cosyvoice2_llm
  15. modelscope download --model iic/CosyVoice2-0.5B --local_dir ./CosyVoice2-0.5B/
  16. git clone --recursive https://github.com/FunAudioLLM/CosyVoice.git
  17. cd CosyVoice
  18. git submodule update --init --recursive
  19. fi
  20. if [ $stage -le 1 ] && [ $stop_stage -ge 1 ]; then
  21. echo "Converting checkpoint to TensorRT weights"
  22. python3 scripts/convert_checkpoint.py --model_dir $huggingface_model_local_dir \
  23. --output_dir $trt_weights_dir \
  24. --dtype $trt_dtype || exit 1
  25. echo "Building TensorRT engines"
  26. trtllm-build --checkpoint_dir $trt_weights_dir \
  27. --output_dir $trt_engines_dir \
  28. --max_batch_size 16 \
  29. --max_num_tokens 32768 \
  30. --gemm_plugin $trt_dtype || exit 1
  31. fi
  32. if [ $stage -le 2 ] && [ $stop_stage -ge 2 ]; then
  33. echo "Testing TensorRT engines"
  34. python3 ./test_llm.py --input_text "你好,请问你叫什么?" \
  35. --tokenizer_dir $huggingface_model_local_dir \
  36. --top_k 50 --top_p 0.95 --temperature 0.8 \
  37. --engine_dir=$trt_engines_dir || exit 1
  38. fi
  39. if [ $stage -le 3 ] && [ $stop_stage -ge 3 ]; then
  40. echo "Creating model repository"
  41. rm -rf $model_repo
  42. mkdir -p $model_repo
  43. cosyvoice2_dir="cosyvoice2"
  44. cp -r ./model_repo/${cosyvoice2_dir} $model_repo
  45. cp -r ./model_repo/audio_tokenizer $model_repo
  46. cp -r ./model_repo/tensorrt_llm $model_repo
  47. cp -r ./model_repo/token2wav $model_repo
  48. ENGINE_PATH=$trt_engines_dir
  49. MAX_QUEUE_DELAY_MICROSECONDS=0
  50. MODEL_DIR=$model_scope_model_local_dir
  51. LLM_TOKENIZER_DIR=$huggingface_model_local_dir
  52. BLS_INSTANCE_NUM=4
  53. TRITON_MAX_BATCH_SIZE=16
  54. DECOUPLED_MODE=False
  55. python3 scripts/fill_template.py -i ${model_repo}/token2wav/config.pbtxt model_dir:${MODEL_DIR},triton_max_batch_size:${TRITON_MAX_BATCH_SIZE},max_queue_delay_microseconds:${MAX_QUEUE_DELAY_MICROSECONDS}
  56. python3 scripts/fill_template.py -i ${model_repo}/audio_tokenizer/config.pbtxt model_dir:${MODEL_DIR},triton_max_batch_size:${TRITON_MAX_BATCH_SIZE},max_queue_delay_microseconds:${MAX_QUEUE_DELAY_MICROSECONDS}
  57. python3 scripts/fill_template.py -i ${model_repo}/${cosyvoice2_dir}/config.pbtxt model_dir:${MODEL_DIR},bls_instance_num:${BLS_INSTANCE_NUM},llm_tokenizer_dir:${LLM_TOKENIZER_DIR},triton_max_batch_size:${TRITON_MAX_BATCH_SIZE},decoupled_mode:${DECOUPLED_MODE},max_queue_delay_microseconds:${MAX_QUEUE_DELAY_MICROSECONDS}
  58. python3 scripts/fill_template.py -i ${model_repo}/tensorrt_llm/config.pbtxt triton_backend:tensorrtllm,triton_max_batch_size:${TRITON_MAX_BATCH_SIZE},decoupled_mode:${DECOUPLED_MODE},max_beam_width:1,engine_dir:${ENGINE_PATH},max_tokens_in_paged_kv_cache:2560,max_attention_window_size:2560,kv_cache_free_gpu_mem_fraction:0.5,exclude_input_in_output:True,enable_kv_cache_reuse:False,batching_strategy:inflight_fused_batching,max_queue_delay_microseconds:${MAX_QUEUE_DELAY_MICROSECONDS},encoder_input_features_data_type:TYPE_FP16,logits_datatype:TYPE_FP32
  59. fi
  60. if [ $stage -le 4 ] && [ $stop_stage -ge 4 ]; then
  61. tritonserver --model-repository $model_repo
  62. fi
  63. if [ $stage -le 5 ] && [ $stop_stage -ge 5 ]; then
  64. echo "Testing TensorRT engines"
  65. python3 client_http.py \
  66. --reference-audio ./prompt_audio.wav \
  67. --reference-text "吃燕窝就选燕之屋,本节目由26年专注高品质燕窝的燕之屋冠名播出。豆奶牛奶换着喝,营养更均衡,本节目由豆本豆豆奶特约播出。" \
  68. --target-text "身临其境,换新体验。塑造开源语音合成新范式,让智能语音更自然。" \
  69. --model-name cosyvoice2
  70. fi
  71. if [ $stage -le 6 ] && [ $stop_stage -ge 6 ]; then
  72. echo "Running benchmark client"
  73. num_task=4
  74. python3 client_grpc.py \
  75. --server-addr localhost \
  76. --model-name cosyvoice2 \
  77. --num-tasks $num_task \
  78. --mode offline \
  79. --huggingface-dataset yuekai/seed_tts_cosy2 \
  80. --log-dir ./log_concurrent_tasks_${num_task}_offline_bls_4_${trt_dtype}
  81. fi