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

TuneSearchCV not using Colab GPU #218

Closed sadia closed 2 years ago

sadia commented 3 years ago

When I check my usage metrics in Colab while TuneSearchCV is running, it says 0.0GB of GPU used.

# Install and import libraries
!pip install -U 'ray[tune]'
!pip install -U tune_sklearn

import pandas as pd
import ray
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import GridSearchCV
from tune_sklearn import TuneSearchCV

# Load data
cancer = load_breast_cancer()
X = cancer.data
y = cancer.target

# Train-test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Random Forest Classifier
model = RandomForestClassifier(random_state=1234)

# Create the hyperparams grid
param_dists = {
    'max_features':  ['sqrt', 'log2', None],
    'max_depth': [int(x) for x in np.linspace(10, 110, num = 11)].append(None),
    'min_samples_split':  [2, 5, 10],
    'min_samples_leaf': min_samples_leaf,
    'bootstrap':  [True, False],
    'warm_start':  [True, False]
}

# Tune model
tuner = TuneSearchCV(estimator = model, 
                          param_distributions = param_dists,
                          cv = 10, 
                          use_gpu = True, 
                          early_stopping = True,
                          max_iters = 10,
                          verbose = 2)

tuner.fit(X_train, y_train)
print('Best Parameters :', tuner.best_params_)

My model has been running with the above configurations, but GPU usage is showing 0.0GB

image

richardliaw commented 2 years ago

Yeah, TuneSearchCV will not automatically convert your model to run on GPU. Though that would be nice, I think you need to actually use RAPIDS/CuML.

sadia commented 2 years ago

Thanks @richardliaw. So does the use_gpu = True parameter only work on personal devices?

Yard1 commented 2 years ago

It only works if the model that you are trying to tune actually uses GPUs

sadia commented 2 years ago

Closing due to code working as expected