CosyVoice icon indicating copy to clipboard operation
CosyVoice copied to clipboard

CosyVoice 2.0用4090生成10个字需要4.5秒

Open JV-X opened this issue 1 year ago • 18 comments

你好,我尝试运行了这个Python脚本,在这个脚本中我添加了三个print语句输出使用不同方法生成语音的耗时:

import sys
sys.path.append('third_party/Matcha-TTS')
from cosyvoice.cli.cosyvoice import CosyVoice, CosyVoice2
from cosyvoice.utils.file_utils import load_wav
import torchaudio
import time

model_path = './pretrained_models'

cosyvoice = CosyVoice2(model_path, load_jit=False, load_trt=False, fp16=False)

start = time.time()
# NOTE if you want to reproduce the results on https://funaudiollm.github.io/cosyvoice2, please add text_frontend=False during inference
# zero_shot usage
prompt_speech_16k = load_wav('./asset/zero_shot_prompt.wav', 16000)
for i, j in enumerate(cosyvoice.inference_zero_shot('收到好友从远方寄来的', '希望你以后能够做的比我还好呦。', prompt_speech_16k, stream=False)):
    end = time.time()
    print(f'inference_zero_shot cost: {end - start}')
    torchaudio.save('zero_shot_{}.wav'.format(i), j['tts_speech'], cosyvoice.sample_rate)

start = time.time()
# fine grained control, for supported control, check cosyvoice/tokenizer/tokenizer.py#L248
for i, j in enumerate(cosyvoice.inference_cross_lingual('在他讲述那个荒诞故事的过程中,他突然[laughter]停下来,因为他自己也被逗笑了[laughter]。', prompt_speech_16k, stream=False)):
    end = time.time()
    print(f'inference_cross_lingual cost:  {end - start}')
    torchaudio.save('fine_grained_control_{}.wav'.format(i), j['tts_speech'], cosyvoice.sample_rate)

# instruct usage
start = time.time()
for i, j in enumerate(cosyvoice.inference_instruct2('收到好友从远方寄来的生日礼物,那份意外的惊喜与深深的祝福让我心中充满了甜蜜的快乐,笑容如花儿般绽放。', '用四川话说这句话', prompt_speech_16k, stream=False)):
    end = time.time()
    print(f'inference_instruct2 cost:  {end - start}')
    torchaudio.save('instruct_{}.wav'.format(i), j['tts_speech'], cosyvoice.sample_rate)

模型: CosyVoice2-0.5B, 显卡: RTX-4090D, CPU: i9-14900KF 内存16GB 从日志来看,调用不同的方法生成结果的耗时最好也是在四秒以上,这个结果正常吗,和预期的差的太多了,是我调用方式有问题吗?

log:

(base) hygx@hygx:~/code/Cosyvoice2.0/CosyVoice$  cd /home/hygx/code/Cosyvoice2.0/CosyVoice ; /usr/bin/env /home/hygx/anaconda3/envs/cosyvoice2/bin/python /home/hygx/.vscode-server/extensions/ms-python.debugpy-2025.0.1-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher 45638 -- /home/hygx/code/Cosyvoice2.0/CosyVoice/2.py 
2025-02-21 11:25:18,869 - modelscope - INFO - PyTorch version 2.3.1+cu121 Found.
2025-02-21 11:25:18,869 - modelscope - INFO - Loading ast index from /home/hygx/.cache/modelscope/ast_indexer
2025-02-21 11:25:18,890 - modelscope - INFO - Loading done! Current index file version is 1.15.0, with md5 0cdac163f9eacaa59eb9a28862fe5da6 and a total number of 980 components indexed
/home/hygx/anaconda3/envs/cosyvoice2/lib/python3.10/site-packages/diffusers/models/lora.py:393: FutureWarning: `LoRACompatibleLinear` is deprecated and will be removed in version 1.0.0. Use of `LoRACompatibleLinear` is deprecated. Please switch to PEFT backend by installing PEFT: `pip install peft`.
  deprecate("LoRACompatibleLinear", "1.0.0", deprecation_message)
2025-02-21 11:25:27,230 INFO input frame rate=25
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
2025-02-21 11:25:29.013705445 [W:onnxruntime:, transformer_memcpy.cc:74 ApplyImpl] 8 Memcpy nodes are added to the graph main_graph for CUDAExecutionProvider. It might have negative impact on performance (including unable to run CUDA graph). Set session_options.log_severity_level=1 to see the detail logs before this message.
2025-02-21 11:25:29.015552774 [W:onnxruntime:, session_state.cc:1166 VerifyEachNodeIsAssignedToAnEp] Some nodes were not assigned to the preferred execution providers which may or may not have an negative impact on performance. e.g. ORT explicitly assigns shape related ops to CPU to improve perf.
2025-02-21 11:25:29.015570548 [W:onnxruntime:, session_state.cc:1168 VerifyEachNodeIsAssignedToAnEp] Rerunning with verbose output on a non-minimal build will show node assignments.
text.cc: festival_Text_init
open voice lang map failed
  0%|                                                                  | 0/1 [00:00<?, ?it/s]2025-02-21 11:25:35,827 INFO synthesis text 收到好友从远方寄来的。
2025-02-21 11:25:38,336 INFO yield speech len 3.2, rtf 0.7840371131896973
inference_zero_shot cost: 4.522935628890991
100%|██████████████████████████████████████████████████████████| 1/1 [00:04<00:00,  4.44s/it]
  0%|                                                                  | 0/1 [00:00<?, ?it/s]2025-02-21 11:25:38,426 INFO synthesis text 在他讲述那个荒诞故事的过程中,他突然[laughter]停下来,因为他自己也被逗笑了[laughter]。
2025-02-21 11:25:48,163 INFO yield speech len 22.24, rtf 0.43784292052975665
inference_cross_lingual cost:  9.821248531341553
100%|██████████████████████████████████████████████████████████| 1/1 [00:09<00:00,  9.80s/it]
  0%|                                                                  | 0/1 [00:00<?, ?it/s]2025-02-21 11:25:48,237 INFO synthesis text 收到好友从远方寄来的生日礼物,那份意外的惊喜与深深的祝福让我心中充满了甜蜜的快乐,笑容如花儿般绽放。
2025-02-21 11:25:53,081 INFO yield speech len 11.12, rtf 0.4355493209344878
inference_instruct2 cost:  4.9083335399627686
100%|██████████████████████████████████████████████████████████| 1/1 [00:04<00:00,  4.89s/it]

有办法提升音频生成速度吗? 期待您的回复,谢谢!

JV-X avatar Feb 21 '25 03:02 JV-X

这个速度是正常的,因为我们目前cosyvoice2的llm没有任何加速手段

aluminumbox avatar Feb 23 '25 09:02 aluminumbox

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

AIStorm-boop avatar Feb 24 '25 14:02 AIStorm-boop

请问是如何做优化提速的

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

bazinga233-ai avatar Feb 25 '25 02:02 bazinga233-ai

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

同问,可以分享下优化提速的方法吗

Dagoli avatar Feb 25 '25 03:02 Dagoli

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

同问

wjddd avatar Feb 25 '25 03:02 wjddd

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

同问

Sunnycl avatar Feb 26 '25 08:02 Sunnycl

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

同问,可以分享一下优化方法吗

wulianpu avatar Feb 26 '25 15:02 wulianpu

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

同问

1234yrtsrg avatar Mar 01 '25 16:03 1234yrtsrg

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

好厉害,怎么做到的

zte-tcb avatar Mar 03 '25 03:03 zte-tcb

可以介绍一下怎么优化的吗?

tangchb @.***> 于2025年3月3日周一 11:10写道:

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

好厉害,怎么做到的

— Reply to this email directly, view it on GitHub https://github.com/FunAudioLLM/CosyVoice/issues/1003#issuecomment-2693174883, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG6JUKYCFZSM5GAS7NRMQI32SPBYVAVCNFSM6AAAAABXSJAT6KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOJTGE3TIOBYGM . You are receiving this because you authored the thread.Message ID: @.***> [image: zte-tcb]zte-tcb left a comment (FunAudioLLM/CosyVoice#1003) https://github.com/FunAudioLLM/CosyVoice/issues/1003#issuecomment-2693174883

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

好厉害,怎么做到的

— Reply to this email directly, view it on GitHub https://github.com/FunAudioLLM/CosyVoice/issues/1003#issuecomment-2693174883, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG6JUKYCFZSM5GAS7NRMQI32SPBYVAVCNFSM6AAAAABXSJAT6KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOJTGE3TIOBYGM . You are receiving this because you authored the thread.Message ID: @.***>

JV-X avatar Mar 04 '25 07:03 JV-X

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

同问怎么优化的,谢谢

lihuikenny avatar Mar 05 '25 02:03 lihuikenny

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

同问大佬如何优化,十分感谢!

MC-XiaoHei avatar Mar 06 '25 12:03 MC-XiaoHei

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

mark,同问。哈哈,楼上太多人了已经

Healthyyue avatar Mar 07 '25 01:03 Healthyyue

@AIStorm-boop 请问您使用的是哪款显卡?

HK16831 avatar Mar 07 '25 07:03 HK16831

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

同问,怎么优化的

hjj-lmx avatar Apr 08 '25 10:04 hjj-lmx

同问,怎么优化的

jxaujunjun avatar Apr 08 '25 12:04 jxaujunjun

同问,怎么优化的

Xr-TenderLIfe avatar Apr 14 '25 05:04 Xr-TenderLIfe

我上了优化后提速特别多,300个汉字大概耗时2-3s吧,但是怎么及时流式还没头绪

单进程优化吗。还是用到了并行方法

wukongbuku avatar Apr 21 '25 09:04 wukongbuku