CosyVoice icon indicating copy to clipboard operation
CosyVoice copied to clipboard

请问 extract_speech_token 这一步是否可以加速呢?

Open TinaChen95 opened this issue 2 years ago • 4 comments

想要微调,但是抽特征的速度有点慢。 请问有没有建议的加速方法呢?

目前好像写死了 batch=1 推断,这块儿是否建议修改呢? 或者转成 tensorrt 之类的,不知道是否会有加速呢

TinaChen95 avatar Jul 24 '24 09:07 TinaChen95

请问你解决了吗?speech tokenizer可以调batchsize更大吗?

JunityZz avatar Jul 29 '24 17:07 JunityZz

请问你解决了吗?speech tokenizer可以调batchsize更大吗?

有可能是 onnx 没用 GPU 推理的问题

csu-roycheng avatar Aug 22 '24 01:08 csu-roycheng

用gpu的话, 10h能提取960h的speech tokens(以LibriTTS为例). 但是onnx相当吃cpu, 在12cpu上同时跑2个extractor speech token的脚本, cpu利用率就100%. 建议用gpu和更多的cpu来处理.

r666ay avatar Aug 23 '24 10:08 r666ay

请问你解决了吗?speech tokenizer可以调batchsize更大吗?

import onnx
import os
import struct

from argparse import ArgumentParser


def rebatch(infile, outfile, batch_size):
    model = onnx.load(infile)
    graph = model.graph

    # Change batch size in input, output and value_info
    for tensor in list(graph.input) + list(graph.value_info) + list(graph.output):
        tensor.type.tensor_type.shape.dim[0].dim_param = batch_size

    # Set dynamic batch size in reshapes (-1)
    for node in  graph.node:
        if node.op_type != 'Reshape':
            continue
        for init in graph.initializer:
            # node.input[1] is expected to be a reshape
            if init.name != node.input[1]:
                continue
            # Shape is stored as a list of ints
            if len(init.int64_data) > 0:
                # This overwrites bias nodes' reshape shape but should be fine
                init.int64_data[0] = -1
            # Shape is stored as bytes
            elif len(init.raw_data) > 0:
                shape = bytearray(init.raw_data)
                struct.pack_into('q', shape, 0, -1)
                init.raw_data = bytes(shape)

    onnx.save(model, outfile)

if __name__ == '__main__':
    parser = ArgumentParser('Replace batch size with \'N\'')
    parser.add_argument('infile')
    parser.add_argument('outfile')
    args = parser.parse_args()

    rebatch(args.infile, args.outfile, 'N')

pengzhendong avatar Sep 10 '24 11:09 pengzhendong