从内存中释放 H2O 网格?

Release H2O Grid From Memory?

我正在努力寻找正确的 API 来为 H2O 网格创建的对象释放内存。此代码是别人预先编写的,我目前正在维护它。

#train grid search
gbm_grid1 <- h2o.grid(algorithm = "gbm"                                  #specifies gbm algorithm is used
                      ,grid_id = paste("gbm_grid1",current_date,sep="_")   #defines a grid identification
                      ,x = predictors                                    #defines column variables to use as predictors
                      ,y = y                                             #specifies the response variable
                      ,training_frame = train1                           #specifies the training frame
                      
                      #gbm parameters to remain fixed
                      ,nfolds = 5                     #specify number of folds for cross-validation is 5 (this acceptable here in order to reduce training time)
                      ,distribution = "bernoulli"     #specify that we are predicting a binary dependent variable
                      ,ntrees = 1000                  #specify the number of trees to build (1000 as essentially the maximum number of trees that can be built. Early stopping parameters defined later will make it unlikely our model will reach 1000 trees)
                      ,learn_rate = 0.1               #specify the learn rate used of for gradient descent optimization (goal is to use as small a learn rate as possible)
                      ,learn_rate_annealing = 0.995   #specifies that the learn rate will perpetually decrease by a factor of 0.995 (this can help speed up traing for our grid search)
                      ,max_depth = tuned_max_depth
                      ,min_rows = tuned_min_rows
                      ,sample_rate = 0.8              #specify the amount of row observations used when making a split decision
                      ,col_sample_rate = 0.8          #specify the amount of column observations used when making a split decision
                      ,stopping_metric = "logloss"    #specify loss function
                      ,stopping_tolerance = 0.001     #specify minimum change required in stopping metric for individual model to continue training
                      ,stopping_rounds = 5            #specify maximum amount of training rounds stopping metric has to change in excess of stopping tolerance
                      
                      #specifies hyperparameters to fluctuate during model building in the grid search
                      ,hyper_params = gbm_hp2
                      
                      #specifies the search criteria that includes stop training etrics to speed up model building
                      ,search_criteria = search_criteria2
                      
                      #sets a reproducible seed
                      ,seed = 123456                         
)

h2o.rm(gbm_grid1)

问题是我相信这段代码是不久前写的,从那以后就被弃用了。 h2o.rm(gbm_grid1) 失败,R Studio 告诉我需要一个十六进制标识符。所以我为我的对象分配了一个标识符并尝试了 h2o.rm(gbm_grid1, "identifier.hex"),它告诉我我不能释放这种类型的对象。

问题是如果我继续脚本的后续步骤,我 运行 内存不足。我该怎么办?

这是我用 H2O.ls()

得到的结果

是的,您可以使用 h2o.rm() 删除对象。您可以使用变量名或键。

h2o.rm(your_object)
h2o.rm(‘your_key’)

您可以使用h2o.ls() 来检查内存中有哪些对象。此外,您可以将参数 cascade = TRUE 添加到 rm 方法以删除子模型。

查看更多here