mlr-org / mlr3learners

Recommended learners for mlr3
https://mlr3learners.mlr-org.com
GNU Lesser General Public License v3.0
89 stars 14 forks source link

set env vars for xgboost #267

Open sebffischer opened 1 year ago

sebffischer commented 1 year ago

Sys.setenv(OMP_NUM_THREADS=1) Sys.setenv(OMP_THREAD_LIMIT=1)

be-marc commented 8 months ago

The nthread parameter works as expected.

library(mlr3learners)

task = tsk("spam")

learner = lrn("classif.xgboost", nrounds = 2000)
system.time(learner$train(task))
#    user  system elapsed
#  24.984   0.024  20.503

learner = lrn("classif.xgboost", nrounds = 2000, nthread = 2)
system.time(learner$train(task))
#    user  system elapsed 
#  28.974   0.329  12.362 

Run on the lrz. Looks like there is no problem. The increase in training time can be explained by the fact that the training data set becomes larger when there are more folds. The longer total runtime is due to future.

library(mlr3learners)

task = tsk("spam")

learner = lrn("classif.xgboost", nrounds = 2000)
system.time(learner$train(task))
#    user  system elapsed
#  24.984   0.024  20.503

future::plan("multisession", workers = 3)
system.time({rr = resample(task, learner, rsmp("cv", folds = 3))})
#  user  system elapsed
# 2.079   0.093  17.363

mean(mlr3misc::map_dbl(rr$learners, function(x) x$state$train_time))
# [1] 13.21067

future::plan("multisession", workers = 6)
system.time({rr = resample(task, learner, rsmp("cv", folds = 6))})
  #  user  system elapsed
  # 2.822   0.054  22.336

mean(mlr3misc::map_dbl(rr$learners, function(x) x$state$train_time))
# [1] 16.67617

future::plan("multisession", workers = 12)
system.time({rr = resample(task, learner, rsmp("cv", folds = 12))})
  #  user  system elapsed
  # 4.345   0.119  28.737

mean(mlr3misc::map_dbl(rr$learners, function(x) x$state$train_time))
# [1] 18.75075

future::plan("multisession", workers = 40)
system.time({rr = resample(task, learner, rsmp("cv", folds = 40))})
 #   user  system elapsed
 # 16.879   0.337  53.033

mean(mlr3misc::map_dbl(rr$learners, function(x) x$state$train_time))
# [1] 21.87785

The environment variables don't change the results.

sebffischer commented 8 months ago

Ok weird, I think Lukas reported that adding this to his .Rprofile improved stuff for him.

be-marc commented 8 months ago

Yes a year ago this also fixed my benchmark. Either this has since been fixed in xgboost or it was a weird data.table with xgboost combination after all. But good to know that our nthread parameter works.

be-marc commented 8 months ago

On my local machine it's different but this might due to high and low performance cores. The environment variables also don't change the results on my local machine.