Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

PaddlePaddle DS2 model load fails in Tornado server

Open shoegazerstella opened this issue 6 years ago • 4 comments

System information -PaddlePaddle version >= 1.6.0 -OS Platform ubuntu 18.04 -Python version: 3.7.4 -Name of Model: DeepSpeech2

I am trying to load a DeepSpeech2 model inside a tornado server using a SingletonMixin class and I have this error:

W0318 11:19:35.634687   150 init.cc:209] Warning: PaddlePaddle catches a failure signal, it may not work properly
W0318 11:19:35.634742   150 init.cc:211] You could check whether you killed PaddlePaddle thread/process accidentally or report the case to PaddlePaddle
W0318 11:19:35.634757   150 init.cc:214] The detail failure signal is:
W0318 11:19:35.634773   150 init.cc:217] *** Aborted at 1584530375 (unix time) try "date -d @1584530375" if you are using GNU date ***
W0318 11:19:35.637790   150 init.cc:217] PC: @                0x0 (unknown)
W0318 11:19:35.638175   150 init.cc:217] *** SIGSEGV (@0x130) received by PID 150 (TID 0x7fd82fb11f40) from PID 304; stack trace: ***
W0318 11:19:35.640535   150 init.cc:217]     @     0x7fd830016730 (unknown)
W0318 11:19:35.641213   150 init.cc:217]     @     0x7fd7e91a01aa pybind11::detail::make_new_python_type()
W0318 11:19:35.642088   150 init.cc:217]     @     0x7fd7e91a27b8 pybind11::detail::generic_type::initialize()
W0318 11:19:35.642894   150 init.cc:217]     @     0x7fd7e9316c94 _ZN8pybind115enum_IN10onnx_torch20TensorProto_DataTypeEEC1IJEEERKNS_6handleEPKcDpRKT_
W0318 11:19:35.644227   150 init.cc:217]     @     0x7fd7e931029c torch::onnx::initONNXBindings()
W0318 11:19:35.645166   150 init.cc:217]     @     0x7fd7e8fca218 initModule()
W0318 11:19:35.647357   150 init.cc:217]     @     0x7fd830265042 _PyImport_LoadDynamicModuleWithSpec
W0318 11:19:35.649078   150 init.cc:217]     @     0x7fd830264dc9 _imp_create_dynamic
W0318 11:19:35.651010   150 init.cc:217]     @     0x7fd830176025 _PyMethodDef_RawFastCallDict
W0318 11:19:35.652886   150 init.cc:217]     @     0x7fd830175d10 _PyCFunction_FastCallDict
W0318 11:19:35.654853   150 init.cc:217]     @     0x7fd8301eb833 _PyEval_EvalFrameDefault
W0318 11:19:35.657164   150 init.cc:217]     @     0x7fd8301e5831 _PyEval_EvalCodeWithName
W0318 11:19:35.659276   150 init.cc:217]     @     0x7fd830176982 _PyFunction_FastCallKeywords
W0318 11:19:35.661051   150 init.cc:217]     @     0x7fd8301ea3b2 _PyEval_EvalFrameDefault
W0318 11:19:35.662883   150 init.cc:217]     @     0x7fd8301768da _PyFunction_FastCallKeywords
W0318 11:19:35.664608   150 init.cc:217]     @     0x7fd8301e6992 _PyEval_EvalFrameDefault
W0318 11:19:35.666405   150 init.cc:217]     @     0x7fd8301768da _PyFunction_FastCallKeywords
W0318 11:19:35.668154   150 init.cc:217]     @     0x7fd8301e6bb1 _PyEval_EvalFrameDefault
W0318 11:19:35.670182   150 init.cc:217]     @     0x7fd8301768da _PyFunction_FastCallKeywords
W0318 11:19:35.672044   150 init.cc:217]     @     0x7fd8301e6bb1 _PyEval_EvalFrameDefault
W0318 11:19:35.674051   150 init.cc:217]     @     0x7fd8301768da _PyFunction_FastCallKeywords
W0318 11:19:35.676153   150 init.cc:217]     @     0x7fd8301e6bb1 _PyEval_EvalFrameDefault
W0318 11:19:35.678510   150 init.cc:217]     @     0x7fd83017704a _PyFunction_FastCallDict
W0318 11:19:35.679981   150 init.cc:217]     @     0x7fd8301765bd object_vacall
W0318 11:19:35.681828   150 init.cc:217]     @     0x7fd830177dbb _PyObject_CallMethodIdObjArgs
W0318 11:19:35.683385   150 init.cc:217]     @     0x7fd830200521 PyImport_ImportModuleLevelObject.localalias.22
W0318 11:19:35.685279   150 init.cc:217]     @     0x7fd8301e9b39 _PyEval_EvalFrameDefault
W0318 11:19:35.687129   150 init.cc:217]     @     0x7fd8301e5831 _PyEval_EvalCodeWithName
W0318 11:19:35.689189   150 init.cc:217]     @     0x7fd8301e5539 PyEval_EvalCodeEx
W0318 11:19:35.691130   150 init.cc:217]     @     0x7fd8301e54fb PyEval_EvalCode
W0318 11:19:35.692857   150 init.cc:217]     @     0x7fd83025f114 builtin_exec
W0318 11:19:35.695096   150 init.cc:217]     @     0x7fd830176025 _PyMethodDef_RawFastCallDict
Segmentation fault

the signleton class:

class ResourceLoader(SingletonMixin):

    def __init__(self):

        self.deepspeech2_model = None

    def load_ds2_model(self):
        """LOAD DeepSpeech2 model"""
       self.deepspeech2_model = load_deepspeech2_model(DEEPSPEECH2_MODEL_PATH, vocab_path, mean_std_path)

I am executing this script which is the tornado run app:

class WebServer(threading.Thread):
    def run(self):
        asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
        asyncio.get_event_loop().set_default_executor(ThreadPoolExecutor(max_workers=1))
        app = application()
        app.listen(PORT)
        tornado.ioloop.IOLoop.instance().start()

if __name__ == "__main__":
      ResourceLoader.instance().load_ds2_model()
      WebServer().start()

From inside the Docker container, the script that does load + inference alone works fine. The problem appears when I try to load it through the singleton inside tornado. Thank you for your help!

shoegazerstella avatar Mar 18 '20 11:03 shoegazerstella

@shoegazerstella I cannot see the details but I guess it is because you run the DS2 model in a child thread, please avoid this execution way.

kuke avatar Mar 18 '20 14:03 kuke

Thanks for replying @kuke Do you think it could work if I convert the model to onnx as shown in this repo?

even though from the logs above I see this:

W0318 11:19:35.642894   150 init.cc:217]     @     0x7fd7e9316c94 _ZN8pybind115enum_IN10onnx_torch20TensorProto_DataTypeEEC1IJEEERKNS_6handleEPKcDpRKT_
W0318 11:19:35.644227   150 init.cc:217]     @     0x7fd7e931029c torch::onnx::initONNXBindings()

is some kind of conversion already being done there?

shoegazerstella avatar Mar 19 '20 11:03 shoegazerstella

It turns out the server startup gives a segmentation fault because pytorch is imported. I have tried to import torch inside the script that does the DS2 inference, that was previously working just fine, and it gives a segmentation fault without any other error log. I have this version of torch in my server:

Name: torch
Version: 1.0.0

Do you know with which version of torch it should work fine? Thanks!

shoegazerstella avatar Mar 24 '20 09:03 shoegazerstella

With this version of torch is works just fine!

torch==1.4.0

I am closing the issue, although could be interesting to understand why there was a conflict with version 1.0.0 in the first place.

shoegazerstella avatar Mar 24 '20 15:03 shoegazerstella