ray-project / tune-sklearn

A drop-in replacement for Scikit-Learn’s GridSearchCV / RandomizedSearchCV -- but with cutting edge hyperparameter tuning techniques.
https://docs.ray.io/en/master/tune/api_docs/sklearn.html
Apache License 2.0
465 stars 52 forks source link

For TuneGridSearchCV: Where should I put reuse_actors=True? #265

Open animeshkumarpaul opened 1 year ago

animeshkumarpaul commented 1 year ago

After running the below code, it says

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)

Ray asked me to consider setting reuse_actors=True. But, I did not find any way to do it.

My questions: a) Could anyone tell is it possible here to pass reuse_actors=True? b) It is taking a long time to start the training (Trainable.setup took 2940.989 seconds - 96CPUs and 8 GPUs). Is there any other way to make it faster?