I want to use XGBoost for online production purposes (Python 2.7 XGBoost API). In order to be able to do that I want to control and limit the number of threads used by XGBoost at the predict operation.
I'm using the sklearn compatible regressor offered by XGBoost (xgboost.XGBRegressor), and been trying to use the param nthread in the constructor of the regressor to limit the max threads used to 1.
Unfortunately, XGBoost keeps using multiple threads regardless of the value set in nthread.
Is there another way to limit XGBoost and force it to perform the predict operation using n=1 threads?
I ran into the same issue and figured it out. The correct answer is to set system environment variables. For python scripts:
import os
os.environ['OMP_NUM_THREADS'] = "1"
would work.
Make sure to put these two lines before you import any other package, otherwise it might not work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With