xgboost icon indicating copy to clipboard operation
xgboost copied to clipboard

setting "nthread" does not work for R xgboost?

Open ushanbrisk opened this issue 10 years ago • 7 comments

Hi, I am using xgboost R package to do some optimizaton, and in order to speed computation, I tried multi-thread. The problem is after I set "nthread", it seems no speed improvement. Does any one have idea how I should configure? My environment is Ubuntu + R. Thanks a lot!

ushanbrisk avatar Aug 25 '16 08:08 ushanbrisk

Please fill the issue template when opening a new one (detailed ). Including the required information makes the problem solving process faster.

Specifically, please include

If you are using R package, please provide

1. The R `sessionInfo()`
2. The command to install `xgboost` if you are not installing from source

## Steps to reproduce

1.
2.
3.

## What have you tried?

1.
2.
3.

hetong007 avatar Aug 25 '16 23:08 hetong007

thank you very much! If you are using R package, please provide

  1. The R sessionInfo()

    sessionInfo() R version 3.2.5 (2016-04-14) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 14.04.2 LTS

locale: [1] LC_CTYPE=zh_CN.UTF-8 LC_NUMERIC=C
[3] LC_TIME=zh_CN.UTF-8 LC_COLLATE=zh_CN.UTF-8
[5] LC_MONETARY=zh_CN.UTF-8 LC_MESSAGES=zh_CN.UTF-8
[7] LC_PAPER=zh_CN.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=zh_CN.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] stats graphics grDevices utils datasets methods base

  1. The command to install xgboost if you are not installing from source I install xgboost using
    R> install.packages('xgboost')

Steps to reproduce

  1. The code is a bit to large, I actually I called the xgboost train function like this:

    model <- xgb.train(params = params, data = dtrain, obj = Gradfun, feval = Lossfun, nrounds, watchlist = watchlist, early.stop.round = early.stop.round, maximize = F, verbose = verbose, print.every.n = print.every.n)

    the 'nthread' parameter is set in 'params'

What have you tried?

  1. I just found the consumed time after I set nthread to 1 and to 4 are almost the same

do not know how to check whether I am in the right track.

thanks a lot!

ushanbrisk avatar Aug 26 '16 02:08 ushanbrisk

there is difference of time consuming after I setting different nthread value , although it is not such significant enhancement , it seems works. Do you have any idea how to further improve the speed?

ushanbrisk avatar Aug 26 '16 03:08 ushanbrisk

My machine has 24 cpus, and after a rough test, when setting nthread = 8 , gives a little better result, while setting nthread = 16 or 24 is even worse than single thread.

ushanbrisk avatar Aug 26 '16 03:08 ushanbrisk

  1. What is the size of your data, i.e. rows and columns?
  2. What is the change of the CPU rate when you change the nthread setting?

hetong007 avatar Aug 26 '16 04:08 hetong007

  1. the size of data is like: rows = 300k , columns = 1000
  2. when nthread goes from 1 to 8, the total time spent reduced by 50%, while nthread goes further to 16 and 24, the total time much longer.

ushanbrisk avatar Aug 29 '16 01:08 ushanbrisk

i've tried various input datasets, with various hyperparameter tunings, on a large machine (128 cores) and have seen similar behavior (after ~16 threads, performance gets worse)

skamkar avatar May 18 '17 21:05 skamkar