tidymodels / tune

Tools for tidy parameter tuning
https://tune.tidymodels.org
Other
271 stars 42 forks source link

tune_grid levels and parallel processing cores #753

Closed jxu closed 9 months ago

jxu commented 9 months ago

When using a tunable model like logistic_reg(penalty=tune(), mixture=tune()) %>% set_engine("glmnet") and multi-dimensional grid like grid_regular(penalty(), mixture(), levels=5), there are 25 separate models. So after registerDoParallel(cores=32), why are only five processes are spawned? And without parallel and with control_grid(verbose=T), the progress still says model 1/5. Is this intended?

jxu commented 9 months ago

?glmnet says "The regularization path is computed for the lasso or elasticnet penalty at a grid of values for the regularization parameter lambda." I'm not sure if that means one process trains multiple models simultaneously.

EmilHvitfeldt commented 9 months ago

Hello 👋

This is happening because a glmnet model can be fit using the submodel trick, which you can read more about here: https://parsnip.tidymodels.org/articles/Submodels.html

So what is happening is that when you fit a glmnet model, it can be fit for multiple penalty values at once, and then at prediction decide which penalty value you want to use.

So in practice what happens is that instead of fitting 25 models, it fits 5 models, one for each unique value of mixture.

jxu commented 9 months ago

Thanks. Perhaps that can be added to the parsnip glmnet docs.

github-actions[bot] commented 9 months ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.