title: H2O "grid: Cannot append new models to a grid with different training input" error when parallelizing the execution of autoML in a foreach loop
body: <p>I'm trying to parallelize the training of multiple ML models using the autoML feature provided by H2O. The core code I'm using is the following:</p>
  
  <pre><code>library(foreach)
  library(doParallel)
  
  project_folder &lt;- "/home/user/Documents/"
  
  ncores &lt;- parallel::detectCores(logical = FALSE)
  nlogiccpu &lt;- parallel::detectCores()
  max_mem_size &lt;- "4G"
  
  cl&lt;-makeCluster(nlogiccpu)
  
  registerDoParallel(cl)
  
  df4 &lt;-foreach(i = as.numeric(seq(1,length(divisions))), .combine=rbind) %dopar% {
    library(dplyr)
    library(h2o)
    h2o.init(nthreads = ncores, max_mem_size = max_mem_size)
  
    div &lt;- divisions[i]
  
    df.h2o &lt;- as.h2o(
      df %&gt;% filter(code == div) )
  
    y &lt;- "TARGET"
    x &lt;- names(df.train.x.discretized)
  
    automl.models.h2o &lt;- h2o.automl(
      x = x,
      y = y,
      training_frame = df.h2o,
      nfolds = 10,
      seed = 111,
      project_name = paste0("PRJ_", div)
    )
  
    leader &lt;- automl.models.h2o@leader
  
    div_folder &lt;- file.path(project_folder, paste0("Division_", div))
    h2o.saveModel(leader,
                  path = file.path(div_folder, "TARGET_model_bin"))
    ...
  }
  </code></pre>
  
  <p>Only a part of all the models are trained and saved in their folder, because at some point I got the following error:</p>
  
  <blockquote>
    <p>water.exceptions.H2OIllegalArgumentException: Illegal argument:
    training_frame of function: grid: Cannot append new models to a grid
    with different training input</p>
  </blockquote>
  
  <p>I suppose grids are used during the autoML phase, so I tried to find a parameter to pass the <code>grid_id</code> as I can do in the <code>h2o.grid</code> function as following:</p>
  
  <pre><code>grid &lt;- h2o.grid(“gbm”,  grid_id = paste0(“gbm_grid_id”, div),
                   ...)
  </code></pre>
  
  <p>but I can't find the way to do that.
  The H2O package version I'm using is the 3.24.0.2.</p>
  
  <p>Any suggestion?</p>