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

[Bug] Multiple warnings and errors using the Readme example #72

Closed rohan-gt closed 4 years ago

rohan-gt commented 4 years ago

Running the following example from the Readme on Google Colab:

from tune_sklearn import TuneSearchCV

# Other imports
import scipy
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.linear_model import SGDClassifier

# Set training and validation sets
X, y = make_classification(n_samples=11000, n_features=1000, n_informative=50, n_redundant=0, n_classes=10, class_sep=2.5)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=1000)

# Example parameter distributions to tune from SGDClassifier
# Note the use of tuples instead if non-random optimization is desired
param_dists = {
    'alpha': (1e-4, 1e-1),
    'epsilon': (1e-2, 1e-1)
}

bohb_tune_search = TuneSearchCV(SGDClassifier(),
    param_distributions=param_dists,
    n_iter=2,
    max_iters=10,
    search_optimization="bohb"
)

bohb_tune_search.fit(X_train, y_train)

gives the following warnings and errors:

/usr/local/lib/python3.6/dist-packages/tune_sklearn/tune_basesearch.py:249: UserWarning: Early stopping is not enabled. To enable early stopping, pass in a supported scheduler from Tune and ensure the estimator has `partial_fit`.
  warnings.warn("Early stopping is not enabled. "
/usr/local/lib/python3.6/dist-packages/tune_sklearn/tune_basesearch.py:382: UserWarning: Hiding process output by default. To show process output, set verbose=2.
  warnings.warn("Hiding process output by default. "
Trial Runner checkpointing failed.
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/ray/tune/trial_runner.py", line 373, in step
    self.checkpoint()
  File "/usr/local/lib/python3.6/dist-packages/ray/tune/trial_runner.py", line 302, in checkpoint
    self._local_checkpoint_dir, session_str=self._session_str)
  File "/usr/local/lib/python3.6/dist-packages/ray/tune/suggest/search_generator.py", line 194, in save_to_dir
    self.CKPT_FILE_TMPL.format(session_str))
  File "/usr/local/lib/python3.6/dist-packages/ray/tune/suggest/search_generator.py", line 32, in _atomic_save
    pickle.dump(state, f)
AttributeError: Can't pickle local object 'TuneSearchCV._fill_config_hyperparam.<locals>.get_sample.<locals>.<lambda>'
Trial Runner checkpointing failed.
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/ray/tune/trial_runner.py", line 373, in step
    self.checkpoint()
  File "/usr/local/lib/python3.6/dist-packages/ray/tune/trial_runner.py", line 302, in checkpoint
    self._local_checkpoint_dir, session_str=self._session_str)
  File "/usr/local/lib/python3.6/dist-packages/ray/tune/suggest/search_generator.py", line 194, in save_to_dir
    self.CKPT_FILE_TMPL.format(session_str))
  File "/usr/local/lib/python3.6/dist-packages/ray/tune/suggest/search_generator.py", line 32, in _atomic_save
    pickle.dump(state, f)
AttributeError: Can't pickle local object 'TuneSearchCV._fill_config_hyperparam.<locals>.get_sample.<locals>.<lambda>'
Trial Runner checkpointing failed.
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/ray/tune/tune.py", line 360, in run
    runner.checkpoint(force=True)
  File "/usr/local/lib/python3.6/dist-packages/ray/tune/trial_runner.py", line 302, in checkpoint
    self._local_checkpoint_dir, session_str=self._session_str)
  File "/usr/local/lib/python3.6/dist-packages/ray/tune/suggest/search_generator.py", line 194, in save_to_dir
    self.CKPT_FILE_TMPL.format(session_str))
  File "/usr/local/lib/python3.6/dist-packages/ray/tune/suggest/search_generator.py", line 32, in _atomic_save
    pickle.dump(state, f)
AttributeError: Can't pickle local object 'TuneSearchCV._fill_config_hyperparam.<locals>.get_sample.<locals>.<lambda>'
/usr/local/lib/python3.6/dist-packages/sklearn/base.py:197: FutureWarning: From version 0.24, get_params will raise an AttributeError if a parameter cannot be retrieved as an instance attribute. Previously it would return None.
  FutureWarning)
TuneSearchCV(cv=None, early_stopping=None, error_score=nan,
             estimator=SGDClassifier(alpha=0.0001, average=False,
                                     class_weight=None, early_stopping=False,
                                     epsilon=0.1, eta0=0.0, fit_intercept=True,
                                     l1_ratio=0.15, learning_rate='optimal',
                                     loss='hinge', max_iter=1000,
                                     n_iter_no_change=5, n_jobs=None,
                                     penalty='l2', power_t=0.5,
                                     random_state=None, shuffle=True, tol=0.001,
                                     validation_fraction=0.1, verbose=0,
                                     warm_start=False),
             local_dir='~/ray_results', max_iters=1, n_iter=None, n_jobs=None,
             param_distributions={'alpha': (0.0001, 0.1),
                                  'epsilon': (0.01, 0.1)},
             random_state=None, refit=True, return_train_score=False,
             scoring=<function _passthrough_scorer at 0x7fec7a066598>,
             search_optimization='bohb', sk_n_jobs=-1, use_gpu=False,
             verbose=0)
richardliaw commented 4 years ago

cc @Yard1

Yard1 commented 4 years ago

That's... Odd. I will check it locally. I recall it working fine in terminal.

richardliaw commented 4 years ago

Ah I think I know what the problem is. This is a recent Tune logging issue, I will fix this asap (sorry for the false alarm)!

@rohan-gt you can add the following to the top of your script to mute:


import logging
logging.getLogger("ray").setLevel("CRITICAL")