R中H2O深度学习网格搜索遇CURL超时错误求助
H2O深度学习网格搜索CURL超时问题解决
问题场景
在R 4.2.0版本环境中运行H2O深度学习二分类模型的网格搜索,使用的代码如下:
hyper_params <- list( activation = c("Rectifier", "Maxout", "Tanh", "RectifierWithDropout", "MaxoutWithDropout", "TanhWithDropout"), hidden = list(c(5, 5, 5, 5, 5), c(10, 10, 10, 10), c(50, 50, 50), c(100, 100, 100)), epochs = c(50, 100, 200), l1 = c(0, 0.00001, 0.0001), l2 = c(0, 0.00001, 0.0001), rate = c(0, 01, 0.005, 0.001), rate_annealing = c(1e-8, 1e-7, 1e-6), rho = c(0.9, 0.95, 0.99, 0.999), epsilon = c(1e-10, 1e-8, 1e-6, 1e-4), momentum_start = c(0, 0.5), momentum_stable = c(0.99, 0.5, 0), input_dropout_ratio = c(0, 0.1, 0.2), max_w2 = c(10, 100, 1000, 3.4028235e+38) ) search_criteria <- list(strategy = "RandomDiscrete", max_models = 100, max_runtime_secs = 12000, stopping_tolerance = 0.001, stopping_rounds = 15, seed = 42) dl_grid <- h2o.grid(algorithm = "deeplearning", x = x, y = y, grid_id = "dl_grid", training_frame = df, validation_frame = tst, nfolds = 25, fold_assignment = "Stratified", hyper_params = hyper_params, search_criteria = search_criteria, seed = 42 )
运行后出现以下错误:
"na .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = urlSuffix, : Unexpected CURL error: Timeout was reached: [localhost:54321] Resolving timed out after 10180 milliseconds [1] "Job request failed Unexpected CURL error: Timeout was reached: [localhost:54321] Resolving timed out after 10180 milliseconds, will retry after 3s."
使用的R版本详情:
platform x86_64-w64-mingw32 arch x86_64 os mingw32 crt ucrt system x86_64, mingw32 status major 4 minor 2.0 year 2022 month 04 day 22 svn rev 82229 language R version.string R version 4.2.0 (2022-04-22 ucrt) nickname Vigorous Calisthenics
解决方法
- 修正参数语法错误:代码中
rate参数里的01是无效值,应改为0.01,避免因参数错误导致模型训练异常。 - 延长H2O超时时间:初始化H2O时增加超时参数,比如
h2o.init(timeout = 30000)(单位为毫秒),给API调用足够的等待时间。 - 简化超参数空间:当前超参数组合数量过大,即使随机选100个模型,计算量也极高。建议先只保留关键参数(如
activation、hidden、epochs)的候选值,其他参数用默认值,逐步缩小搜索范围。 - 降低交叉验证折数:25折交叉验证会大幅增加每个模型的训练时间,建议先降到5或10折,待找到较优参数范围后再提升折数。
- 增加H2O内存分配:重启H2O时指定更大内存,比如
h2o.init(max_mem_size = "8G")(根据机器实际内存调整),避免因内存不足导致训练卡顿超时。 - 检查本地端口与防火墙:确保localhost的54321端口未被防火墙或安全软件拦截,保证R与H2O服务的正常通信。
- 重启H2O服务:先用
h2o.shutdown()关闭现有服务,再用h2o.init()重新启动,清除可能的资源占用问题。
内容的提问来源于stack exchange,提问作者Achu A L
相关产品推荐
相关产品推荐

