Langchain-Chatchat icon indicating copy to clipboard operation
Langchain-Chatchat copied to clipboard

你好,请教个问题,api.py部署的时候,如何改为多线程调用?谢谢

Open cristianohello opened this issue 1 year ago • 5 comments

目前的api.py脚本不支持多线程

cristianohello avatar May 31 '23 02:05 cristianohello

api是fastapi做的,你把视图函数前面的async去掉,它会自动放到线程池运行。但你要考虑好模型的跨线程共用问题。

liunux4odoo avatar May 31 '23 04:05 liunux4odoo

@liunux4odoo 你好,用多线程会增加模型问答的速度吧?模型的跨线程共用问题是什么问题呢?

cristianohello avatar May 31 '23 05:05 cristianohello

@liunux4odoo 多线程的话,修改uvicorn.run(app, host=args.host, port=args.port)就行了吧?uvicorn.run(app, host=args.host, port=args.port, workers = 2),这样是两个线程吧?

cristianohello avatar May 31 '23 05:05 cristianohello

@liunux4odoo 多线程的话,修改uvicorn.run(app, host=args.host, port=args.port)就行了吧?uvicorn.run(app, host=args.host, port=args.port, workers = 2),这样是两个线程吧?

uvicorn的workers是多进程,这样每个进程都要占用GPU。

@liunux4odoo 你好,用多线程会增加模型问答的速度吧?模型的跨线程共用问题是什么问题呢?

我对langchain的模型运行还不太了解,但如果只有一个全局的模型可供使用,并且阻塞主要在模型这边,用多线程意义不大。

liunux4odoo avatar May 31 '23 06:05 liunux4odoo

@liunux4odoo 谢谢解答。还请教个问题,后端部署api.py的时候,能不能流式输出curl的结果,让后端监测到第一个字就输出,这样表面上提升速度。

cristianohello avatar May 31 '23 06:05 cristianohello