You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请问reuse_actors=True应添加到TuneGridSearchCV代码的哪个位置?

问题:如何在代码中添加reuse_actors=True参数以减少初始化开销?

系统提示信息

INFO trainable.py:172 – Trainable.setup took 2940.989 seconds. if your trainable is slow to initialize, consider setting reuse_actors=True to reduce actor creation overheads

原代码片段

import ray
ray.init(address="auto", _temp_dir='/home/ray_dir')

rnd = random.seed(8)
grid_cv = StratifiedKFold(n_splits=3,random_state=rnd, shuffle=True)

from xgboost.callback import EarlyStopping
early_stopping = EarlyStopping(rounds = 50, maximize=True, save_best=True)
clf = xgb.XGBClassifier(
                tree_method='gpu_hist',
                max_bin=512, 
                learning_rate = 0.0001,
                n_estimators=1000,
                objective='binary:logistic', reg_alpha=0.01,
                scale_pos_weight = pos_weight, eval_metric= 'aucpr',
                callbacks=[early_stopping],
                verbosity = 0,
                nthread = 96
                )


param = {
    'eta': [0.01, 0.1, 0.3],
    'min_child_weight': [1,3,8,16],
    'max_depth':[25,50,100,500],
    'colsample_bytree': [0.4,0.6,0.8],
    'subsample': [0.4,0.6,0.8],
    'gamma':[0,0.5,2,10],
}

gs = TuneGridSearchCV (estimator=clf, param_grid=param,  cv=grid_cv, n_jobs = -1, refit=True, return_train_score = True, verbose=3, scoring = 'average_precision', use_gpu = True )

gs.fit(X_train, y_train, eval_set= eval_set_xgboost, verbose=True)

解决方案

reuse_actors=True参数需要添加到**TuneGridSearchCV的初始化参数列表中**,这是Ray Tune用于控制actor复用的配置项,能有效减少重复创建actor带来的初始化开销。

修改后的TuneGridSearchCV初始化代码如下:

gs = TuneGridSearchCV(
    estimator=clf,
    param_grid=param,
    cv=grid_cv,
    n_jobs=-1,
    refit=True,
    return_train_score=True,
    verbose=3,
    scoring='average_precision',
    use_gpu=True,
    reuse_actors=True  # 新增该参数
)

内容的提问来源于stack exchange,提问作者Animesh Kumar Paul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 10:20:25