Repository navigation
Send the parallel CV folds only the data that they need - #663
Merged
Merged
Conversation
… mu in all reference models
aloctavodia
approved these changes
Nov 19, 2026
# Conflicts: # R/cv_varsel.R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The parallel LOO and K-fold CV of
cv_varsel()sent each worker data that the folds do not need. Parallel K-fold CV now takes 15.6 % to 36.1 % less time, and parallel LOO CV 6.5 % to 22.5 % less, in the cases below. The rankings and elpd values do not change.Changes
one_obs()readlw[, i]andsearch_out_rks[[run_index]]from its enclosing environment. Thus each future got the whole S x n matrixlwand all rankings. Each fold now gets its column and its ranking as an element of.X, as inone_fold()of the K-fold CV.mu_offsis the objectmu, and with the identity link,muis the objecteta. A serialized reference model holds a copy of each.refmodel_for_folds()now removesmu_offsandetaif they are identical tomu(refmodel_drop_dup_draws()), andone_obs()andone_fold()restore them on the worker (refmodel_restore_draws()). For K-fold CV, this also applies to the reference model of each fold.Gaussian reference model, S = 4000 draws, 50 predictors, forward search with
validate_search = TRUE, 20 clusters,nterms_max = 5, 8 workers; full LOO CV and K-fold CV with K = 10. CSC Roihu (R 4.6.1, future 1.82.0, future.mirai 1.1.0), jobs 3208224 and 3208318, medians of 3 runs. Master and this PR (2a272a6; later commits change only tests and comments) ran one after the other on one node:multisession(s), mastermirai_multisession(s), masterLimitations
muof the reference model and the log-likelihood matrix of the weight perturbation. The folds need both.refmodel_for_folds()removes only the matrices that are identical tomu.Tests
test_parallel.R: The LOO fold function has neitherlwnorsearch_out_rksin its environment. No reference model for the workers holdsmu_offsoretaas a copy ofmu(all reference models of the test setup, also for the latent and the augmented-data projection). The restore gives backmu,etaandmu_offs. K-fold CV through the parallel code path, but with the folds in this R session, gives the results of the sequential K-fold CV. The first two tests fail without the change (Aalto Triton job 21672365, CSC Roihu job 3210044).parallel = FALSE; full LOO CV with n = 300, K-fold CV with n = 1000,project()with four submodel types): the medians differ from master by at most 0.33 s, within the run-to-run variation, and the results are identical (CSC Roihu jobs 3211274 and 3212652).NOT_CRAN=trueat 6345151 on CSC Roihu (job 3209996; R 4.6.1, testthat 3.3.2, lme4 2.0.6, brms 2.23.1, rstanarm 2.32.2, future 1.82.0): 61,243 expectations, 0 failed. None of the 18 warnings comes from the changed code.This PR was assisted by Claude