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
Gunicorn preload flag not working with PyTorch library #49555
Comments
Hey @hsilveiro, have you asked this question in stanza's repo? Do you know if they any distributed training feature from PyTorch (e.g., cc @cpuhrsch @zhangguanheng66 are you familiar with stanza? |
Yes, I already asked this question in stanza's repo (and also on gunicorn). |
Hey again |
@hsilveiro did you finally manage to solve this? I have a similar situation on haystack with gunicorn. Wondering if there is a way to prevent model loading for each worker (4!) |
This can be related to this issue: |
Anyone have a resolution for this? |
Hello,
We have been developing a FastAPI application where we use some external libraries to perform some NLP tasks, such as tokenization. On top of this, we are launching the service with Gunicorn so that we can parallelize the requests.
However, we are having difficulties using Stanza with Gunicorn’s preload flag active.
It is a requirement to use this flag because since Stanza models can be large, we want the models to be loaded only once, in the Gunicorn master process. This way, Gunicorn workers can access the models that were previously loaded in the master process.
The difficulties that we are facing resumes on the fact that Gunicorn workers hang when trying to make an inference over a given model (that was loaded initially by the master process).
We’ve done some research and debugging but we weren’t able to find a solution. However, we noticed that the worker hangs when the code reaches the prediction step on PyTorch.
Although we are talking about Stanza, this problem also occurred with Sentence Transformers library. And both of them are using the PyTorch library.
Following, I’ll present more details:
Environment:
Steps executed:
This way, the model can be loaded only once, in the master process.
Once the required workers are launched, they should have access to the previous model, without having to load it by themselves (saving computational resources).
The problem happens when we receive a request that will make use of the model that was initially loaded. The worker that will be responsible for handling the request, won’t be able to use the model for inference. As so, the worker will be hanged until the timeout occurs.
After analyzing the code and debugging it, we reached the following step until the code stopped working:
process()
method,class Pipeline
, on the core.py file of Stanza.process()
method, in this case from the tokenize_process.py,class TokenizeProcessor
output_predictions()
method, from the utils.pyclass Tokenizer(nn.Module)
,forward(self, x, feats) method
, in the following line:nontok = F.logsigmoid(-tok0)
. It seems that this line is calling some C++ code where we didn’t investigate any further.Of course, if we remove the --preload flag, everything will run smoothly. Removing it is something that we want to avoid because of the added computational resources that will be necessary (the models will be duplicated in every worker).
We looked through several other issues that could be related to this one, such as:
benoitc/gunicorn#2157
tiangolo/fastapi#2425
tiangolo/fastapi#596
benoitc/gunicorn#2124
and others...
After trying multiple solutions, it wasn’t possible to solve the issue. Do you have any suggestions to handle this? Or other tests that I can perform to give you more information?
Thanks in advance.
cc @zhangguanheng66
The text was updated successfully, but these errors were encountered: