PaddlePaddle / Paddle

PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习&机器学习高性能单机、分布式训练和跨平台部署)
http://www.paddlepaddle.org/
Apache License 2.0
22.16k stars 5.57k forks source link

paddle多线程报错。MemoryError: (ResourceExhausted) Another thread is waitting #47225

Open levinxo opened 1 year ago

levinxo commented 1 year ago

bug描述 Describe the Bug

多线程使用jieba+paddle时,会报各类错误/段错误,MemoryError是其中一种 多进程即multiprocessing下运行是OK的,稳定不报错。

MemoryError: (ResourceExhausted) Another thread is waitting. (at /paddle/paddle/fluid/framework/new_executor/workqueue/events_waiter.cc:104)
import _thread as thread
import jieba
import jieba.posseg as pseg
import paddle
paddle.enable_static()
jieba.enable_paddle()

def call_pseg():
    while True:
        text = "你好"
        s = pseg.lcut(text, use_paddle=True)

def main():
    t_num = 6
    for i in range(t_num):
        thread.start_new_thread(call_pseg, ())
    while True:
        pass

main()

系统为Ubuntu 20.04(docker镜像,cpu下运行) python版本为3.8.10

PIP版本信息: paddlepaddle 2.3.1 jieba 0.42.1

其他补充信息 Additional Supplementary Information

No response

paddle-bot[bot] commented 1 year ago

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

zhangbo9674 commented 1 year ago

你好,经过分析,初步判断是新执行器问题,目前尚未定位到具体原因,可先通过设置FLAGS_USE_STANDALONE_EXECUTOR=0使用旧执行器来避免该问题,修复该问题后,我们会尽快回复您。

zhangbo9674 commented 1 year ago

你好,我们系统分析了jieba+paddle在这个case下的问题,jieba源码中在predict模块中声明了一个paddle的静态图执行器executor,在predict模块的get_result函数中调用该执行器执行,在这个多线程的示例中,由于python的标准import不会对一个模块重复载入,所以只声明了一个执行器,多个线程同时使用该执行器执行,这是无法保证正确性的。 predict模块的代码如下:https://github.com/fxsjy/jieba/blob/master/jieba/lac_small/predict.py ''' import paddle exe = fluid.Executor(place) def get_result(str1): result = exe.run() return result '''

levinxo commented 1 year ago

好的,谢谢!目前暂时通过多进程解决此问题