-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Python predict() does not work with multiprocessing #4246
Comments
Is there any update on this. It seems that this is complete stoper from using xgb on Production...? |
Any update? I am just discovering this now. This is indeed a problem...
What do you mean exactly? In my context, I have a pool of processes that each load a pickled model and then try to make predictions, which is where I get the Here is the error stack:
It seems that CUDA is somehow involved in this. If that helps, I have CUDA I tried to run it on a machine in the cloud that doesn't have any GPU and it seems to work as intended. |
I ran into the same problem recently. I noticed that if you use an older version of xgboost (0.72.1) the problem of "it hangs and doesn’t do anything" seems to disappear, but the process takes way too long. Just for comparison I used multi Threading (which is slower than multi processing) on the latest version (0.90). |
Some related thoughts: The |
Any update on this? I have the same issue here |
Thanks for reminding. Let's see if I can get to this at the weekend. |
I implemented a workaround using ZMQ Load Balancer. So I cut out the code where XGBoost models are initialized and loaded in my master script, and put the code into an independent python script and implemented a worker routine that uses ZMQ load balancing techniques to serve the XGBoost models in the backend. Due to system memory limit, I only initiated 4 workers, so 4 independent XGBoost models as backend workers. The frontend is still in the multiprocessing part of the original master script, but instead of utilizing XGBoost models to make predictions directly, the frontend now sends requests to backend XGBoost workers and receive the predictions from backend. Now no more dmlc errors. Still, it will be awesome if XGBoost eventually make predict() work with multiprocessing |
Hi I implemented a demo which shows how ZMQ load balancer can help with this issue: |
Right now another workaround is don't initialize XGBoost before forking (Like loading pickle only after fork). Maybe we can utilize some low level driver API to maintain the cuda context ourselves, but simply using a distributed framework like dask seems much simpler. |
A quick update on this, thread safe prediction/inplace-prediction are now supported. |
… in parallel with multiple processes" This reverts commit 34de11c. We can't run the evaluation right after training otherwise, because of dmlc/xgboost#4246. Performing test selection in parallel doesn't buy us that much anyway as XGBoost already works in parallel (only the generation of the elements to pass to XGBoost would be parallel).
hi @trivialfis , did this problem fixed now or not? |
@colin-zhou You can now use |
@trivialfis @hcho3 I'm still experiencing this issue with the latest v1.7.1 release and predts = self.get_booster().inplace_predict(
data=X,
iteration_range=iteration_range,
predict_type="margin" if output_margin else "value",
missing=self.missing,
base_margin=base_margin,
validate_features=validate_features,
) |
Hi, the inplace predict is an alternative to using multi-process. The
hang is caused by fork safety issue in libgomp in gcc, which we cannot
fix. Please take a look at
#7044 (comment) for
a potential workaround and more background.
…On 11/20/22 21:48, Evan Sangaline wrote:
You can now use |inplace_predict()| for thread-safe prediction.
@trivialfis <https://github.com/trivialfis> @hcho3
<https://github.com/hcho3> I'm still experiencing this issue with the
latest v1.7.1 release and |model.inplace_predict()|. When loading a
pickled model before forking, any call to |XGBClassifier.predict()|
after forking will hang. The predictor is set to |auto| on a machine
with no GPU or CUDA installed, and |model._can_use_inplace_predict()|
returns |True|. The hang occurs here
<https://github.com/dmlc/xgboost/blob/v1.7.1/python-package/xgboost/sklearn.py#L1140-L1147>:
predts = self.get_booster().inplace_predict(
data=X,
iteration_range=iteration_range,
predict_type="margin" if output_margin else "value",
missing=self.missing,
base_margin=base_margin,
validate_features=validate_features,
)
—
Reply to this email directly, view it on GitHub
<#4246 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD7YPKKYT6JKX3C5NYXOC4TWJIT2BANCNFSM4G5FTZSQ>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Related:
It has been reported that the
predict()
function in the Python interface does not work well with multiprocessing. We should find a way to allow multiple processes to predict with the same model simultaneously.The text was updated successfully, but these errors were encountered: