在 Ubuntu 18.04 上的 mlr R 包中运行随机搜索需要太长时间

Running Random Search in mlr R package on Ubuntu 18.04 takes too long

在 Ubuntu 18.04 上使用 R 中的 mlr 包,使用随机搜索方法搜索 xgboost 的最佳超参数时遇到问题。这是搜索的设置代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
eta_value <- 0.05
set.seed(12345)

# 2. Create tasks
train.both$y <- as.factor(train.both$y) # altering y in train.both!
traintask <- makeClassifTask(data = train.both,target ="y")

# 3. Create learner
lrn <- makeLearner("classif.xgboost",predict.type ="prob")
lrn$par.vals <- list(
  objective="binary:logistic",
  booster ="gbtree",
  eval_metric="auc",
  early_stopping_rounds=10,
  nrounds=xgbcv$best_iteration,
  eta=eta_value,
  weight = train_data$weights
)

# 4. Set parameter space
params <- makeParamSet(
  makeDiscreteParam("max_depth", values = c(4,6,8,10)),
  makeNumericParam("min_child_weight",lower = 1L,upper = 10L),
  makeDiscreteParam("subsample", values = c(0.5, 0.75, 1)),
  makeDiscreteParam("colsample_bytree", values = c(0.4, 0.6, 0.8, 1)),
  makeNumericParam("gamma",lower = 0L,upper = 7L)
)

# 5. Set resampling strategy
rdesc <- makeResampleDesc("CV",stratify = T,iters=10L)

# 6. Search strategy
ctrl <- makeTuneControlRandom(maxit = 60L, tune.threshold = F)

# Set parallel backend and tune parameters
parallelStartMulticore(cpus = detectCores())

# 7. Parameter tuning
timer <- proc.time()
mytune <- tuneParams(learner = lrn,
                     task = traintask,
                     resampling = rdesc,
                     measures = auc,
                     par.set = params,
                     control = ctrl,
                     show.info = T)
proc.time() - timer
parallelStop

如您所见,我在所有 CPU 内核之间分配了搜索任务。问题是已经超过5天了,任务还在运行——这是任务的mlr输出(在任务运行时显示):

1
2
3
4
5
6
7
8
9
10
[Tune] Started tuning learner classif.xgboost for parameter set:
                     Type len Def        Constr Req Tunable Trafo
max_depth        discrete   -   -      4,6,8,10   -    TRUE     -
min_child_weight  numeric   -   -       1 to 10   -    TRUE     -
subsample        discrete   -   -    0.5,0.75,1   -    TRUE     -
colsample_bytree discrete   -   - 0.4,0.6,0.8,1   -    TRUE     -
gamma             numeric   -   -        0 to 7   -    TRUE     -
With control class: TuneControlRandom
Imputation value: -0
Mapping in parallel: mode = multicore; level = mlr.tuneParams; cpus = 16; elements = 60.

我曾经在我的 macbook pro 笔记本电脑上运行过它,它在大约 8 小时内完成。笔记本电脑是 15 英寸 2018 2.6 GHz intel core i7(6 核),32 GB 内存 DDR4。
现在我在一台更强大的计算机上运行它 - 唯一改变的是这是一个 Ubuntu 操作系统。我遇到这个问题的机器是一台带有 Intel i9-9900K CPU @ 3.60GHz x 16 核的固定计算机。桌面为 GNOME 3.28.2,操作系统类型为 64 位,64GB RAM。

我附上了一张我在运行 mlr 搜索任务期间截取的屏幕截图 - 它显示并非所有 CPU 内核都在使用,当我在 MacBook Pro 笔记本电脑上运行时正好相反。

这里有什么问题?这是否与 Ubuntu 系统及其并行化能力有关?
我在这里找到了一个有点类似的问题,但那里也没有明显的解决方案。

enter

当我尝试从终端而不是从 RStudio 运行它时,内核似乎仍然没有被占用:
run

你可以再试一次。如果这不起作用,请尝试将并行化模式切换为"socket"。

很难发现问题的真正根源,因为游戏中涉及多个玩家(端口、与 openMP 的冲突等)。