Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoneType object has no attribute set_input_shape #869

Open
cpken opened this issue Jan 10, 2025 · 3 comments
Open

NoneType object has no attribute set_input_shape #869

cpken opened this issue Jan 10, 2025 · 3 comments

Comments

@cpken
Copy link

cpken commented Jan 10, 2025

更新了今天(2025-01-10)最新的代码与模型(CosyVoice2-0.5B),我运行的是多线程方式。

import multiprocessing as mp
from cosyvoice.cli.cosyvoice import CosyVoice, CosyVoice2

def worker_process():
···
    model_id = "pretrained_models/CosyVoice2-0.5B"
    CosyVoiceModel = CosyVoice2(model_id, load_jit=False, load_trt=True, fp16=True)
····

processes = []
    for _ in range(3):
        p = mp.Process(target=worker_process)
        p.start()
        processes.append(p)

    for p in processes:
        p.join()

在运行 CosyVoiceModel.inference_cross_lingual(tts_text, prompt_speech_16k) 后报错如下

<class 'AttributeError'>:'NoneType' object has no attribute 'set_input_shape'

感谢。

@aluminumbox
Copy link
Collaborator

改成了在线导出tensorrt模型,先启动一个线程,导出成功后,再启动其他线程

@cpken
Copy link
Author

cpken commented Jan 11, 2025

解决方案

import threading
import multiprocessing as mp
from funasr import AutoModel
from cosyvoice.cli.cosyvoice import CosyVoice, CosyVoice2
import asyncio
import os
from loguru import logger

async def main(pid, logger):
    pass

def export_tensorrt_model():
    """导出 TensorRT 模型的代码"""
    global SenseVoiceModel
    global CosyVoiceModel
    SenseVoiceModel = AutoModel()
    CosyVoiceModel = CosyVoice2(model_id, load_jit=False, load_trt=False, fp16=False)

def worker_process():
    # 启动一个线程来导出 TensorRT 模型
    export_thread = threading.Thread(target=export_tensorrt_model)
    export_thread.start()
    export_thread.join()  # 等待导出完成
    asyncio.run(main(os.getpid(), logger))


if __name__ == "__main__":
    processes = []
    for _ in range(SUB_PROCESS):
        p = mp.Process(target=worker_process)
        p.start()
        processes.append(p)

    for p in processes:
        p.join()

但是我如果这样子写,依然会报错

CosyVoiceModel = CosyVoice2(model_id, load_jit=False, load_trt=True, fp16=False)

不加载 load_trt 不会报错:

CosyVoiceModel = CosyVoice2(model_id, load_jit=False, load_trt=False, fp16=True)

@cpken cpken closed this as completed Jan 11, 2025
@cpken cpken reopened this Jan 11, 2025
@cpken
Copy link
Author

cpken commented Jan 11, 2025

改成了在线导出tensorrt模型,先启动一个线程,导出成功后,再启动其他线程

尝试改了代码,是 load_trt=True 的问题导致的,并且我在测试的时候,多线程没有一次成功的。

<class 'AttributeError'>:'NoneType' object has no attribute 'set_input_shape'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants