Repository navigation
Open
Description
I am having issues with nested future calls.
Here I'm using mlr3 and furrr, both using future package. When using them both together I'm having issues to have the parallelized calls to terminate.
library(magrittr)
library(mlr3)
library(mlr3learners)
dtas_lst <-
list(
dta1 = iris %>% dplyr::select(-Species) %>% utils::head(75),
dta2 = iris %>% dplyr::select(-Species) %>% utils::tail(75)
)
run_xgb <- function(dta, target_column = "Sepal.Length") {
ttsk <- mlr3::TaskRegr$new("ttsk", backend = dta, target = target_column)
learner <-
mlr3::lrn(
"regr.xgboost",
objective = "reg:linear",
eval_metric = "rmse",
nrounds = 100,
verbose = 0
)
learner$train(ttsk)
learner$predict(ttsk)$response
}
future::plan(list(future::sequential))
furrr::future_map(dtas_lst, run_xgb, .progress = TRUE) # works!
future::plan(list(future::multiprocess, future::sequential))
furrr::future_map(dtas_lst, run_xgb, .progress = TRUE) # doesn't terminateI've had cases where the parallel runs do work once during a session, but then not terminating on a rerun.
Sometimes when closing down the session (after manually terminating the parallel run), I get the below message
# Error while shutting down parallel: unable to terminate some child processesUpon googling this, I found that I could do the following check.
parallel::mcparallel(scan(n = 1, quiet = TRUE))
# $pid
# [1] 32763
# $fd
# [1] 21 24
# attr(,"class")
# [1] "parallelJob" "childProcess" "process"Does anyone have any solutions to this? Is this perhaps a bug? Related to future or perhaps parallel or other package? I was having the same issue when I was running the mlr package.
> Sys.info()
sysname
"Linux"
release
"4.15.0-66-generic"
version
"#75-Ubuntu SMP Tue Oct 1 05:24:09 UTC 2019"
...
machine
"x86_64"
...
Activity
HenrikBengtsson commentedon Nov 7, 2019
Are you saying it hangs when you use:
but not
which effectively should be identical because when no more plans are specified, it'll fall back to using
sequential?Also, what's you
sessionInfo()?EmilRehnberg commentedon Nov 8, 2019
Using
plan(sequential)works well.Using any parallelization does not. The
furrrprogress bar goes to 100% and hangs / don't seem to finish.Thank you for the quick reply. Can you reproduce this?
EmilRehnberg commentedon Nov 8, 2019
Also, I think I forgot to mention that if I run do
furrrandmlr3parallel runs without nesting, everything's working great.EmilRehnberg commentedon Nov 10, 2019
@HenrikBengtsson
I got a segfault when I ran the parallelized run on a mac. (Sequential run was fine)
Mac session info
HenrikBengtsson commentedon Nov 10, 2019
Hi. I haven't had time to reproduce/troubleshoot your original problem, but I'm suspect you're hitting issues because forked processes are in place (=
multiprocess->multicore) and some of the packages are not fork-proof. On top of that you might hit issues because there's multi-threading going on to that is then forked (e.g. xgboost). I don't have a reference of hand, but I think some of the R code folks (Tomas Kalibera?) have strongly adviced against using forking and multi-threading at the same time.I would switch to using
multisession. That will most likely reveal that there's code in there that can not be parallelized.HenrikBengtsson commentedon Nov 10, 2019
Just to clarify, this is not specific to the future framework. So, if the fork+threading is the cause of your problem, then there is no solution to it. Instead, you need to turn to workarounds, such as launching xgboost on each worker independently of the others.
Oh... and I forgot to say, set
that will help identify cases where there're non-exportable objects in the parallelized code, cf. https://cran.r-project.org/web/packages/future/vignettes/future-4-non-exportable-objects.html
EmilRehnberg commentedon Dec 10, 2019
Thank you so much for the feedback @HenrikBengtsson
This is a well-known factor for you then. Should I add
xgboostas mention in your docs?HenrikBengtsson commentedon Dec 10, 2019
I wouldn't call it a well-known factor for me. I've only heard anecdotal from various savvy R users, but I don't have a solid example yet (at least not one I recall).
I do not know for sure that
xgboostis to blame here, so I don't really want to add it to the docs without further proof. It would be great to get a minimal reproducible (as far as possible) example showing how it can happen. If one then can forcexgboostto run in single-threaded mode, and it does not fail then, then we have a likely candidate for this and for documenting it. To force single-threaded processing, it could be that some of the comments in https://github.com/HenrikBengtsson/future/issues/255 are helpful.A lower hanging fruit might be:
If that's the culprit and one can find a reasonable argument for that being the problem, then it could be added to the list of common examples. (Some onReference errors are false positives because the underlying package was designed to handle lost external pointers).
HenrikBengtsson commentedon Jan 2, 2020
I can reproduce the "stall" on R 3.6.1 on Linux (Ubuntu 18.04):
Disabling multi-threading for xgboost using:
seems to fix the problem.
However, for me it also works to set something less that the default eight (8) max threads. Even:
works for me. That confuses me.
See also
There's a related xgboost issue over topepo/caret#1106 (comment).