Open sebffischer opened 1 year 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.
Ok weird, I think Lukas reported that adding this to his .Rprofile improved stuff for him.
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.
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.
Sys.setenv(OMP_NUM_THREADS=1) Sys.setenv(OMP_THREAD_LIMIT=1)