Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optuna.integration.XGBoostPruningCallback is not xgboost TrainingCallback #203

Closed
anhailing opened this issue Sep 15, 2023 · 2 comments
Closed
Labels
bug Issue/PR about behavior that is broken. Not for typos/CI but for example itself.

Comments

@anhailing
Copy link

Code downloaded at https://github.com/optuna/optuna-examples/blob/main/xgboost/xgboost_integration.py errored out during execution.

Environment

  • Optuna version: 3.3.0
  • Python version: 3.11
  • OS: windows
  • xgboost: 2.0.0

Error messages, stack traces, or logs

[Running] C:\Users\hahy\Miniconda3\envs\ml\python.exe -u "c:\Users\hahy\examples\xgboost_integration.py"
[I 2023-09-15 17:24:25,730] A new study created in memory with name: no-name-d56dde96-9338-4236-ad38-c39f799c7fdb
[W 2023-09-15 17:24:25,776] Trial 0 failed with parameters: {'booster': 'gbtree', 'lambda': 0.07152539971374029, 'alpha': 0.5186515246328354, 'max_depth': 5, 'eta': 2.503213997637747e-05, 'gamma': 0.001738417857798512, 'grow_policy': 'depthwise'} because of the following error: TypeError('callback must be an instance of `TrainingCallback`.').
Traceback (most recent call last):
  File "C:\Users\hahy\Miniconda3\envs\ml\Lib\site-packages\optuna\study\_optimize.py", line 200, in _run_trial
    value_or_values = func(trial)
                      ^^^^^^^^^^^
  File "c:\Users\hahy\examples\xgboost_integration.py", line 52, in objective
    bst = xgb.train(param, dtrain, evals=[(dvalid, "validation")], callbacks=[pruning_callback])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hahy\Miniconda3\envs\ml\Lib\site-packages\xgboost\core.py", line 729, in inner_f
    return func(**kwargs)
           ^^^^^^^^^^^^^^
  File "C:\Users\hahy\Miniconda3\envs\ml\Lib\site-packages\xgboost\training.py", line 167, in train
    cb_container = CallbackContainer(
                   ^^^^^^^^^^^^^^^^^^
  File "C:\Users\hahy\Miniconda3\envs\ml\Lib\site-packages\xgboost\callback.py", line 139, in __init__
    raise TypeError("callback must be an instance of `TrainingCallback`.")
TypeError: callback must be an instance of `TrainingCallback`.
[W 2023-09-15 17:24:25,780] Trial 0 failed with value None.
Traceback (most recent call last):
  File "c:\Users\hahy\examples\xgboost_integration.py", line 63, in <module>
    study.optimize(objective, n_trials=100)
  File "C:\Users\hahy\Miniconda3\envs\ml\Lib\site-packages\optuna\study\study.py", line 442, in optimize
    _optimize(
  File "C:\Users\hahy\Miniconda3\envs\ml\Lib\site-packages\optuna\study\_optimize.py", line 66, in _optimize
    _optimize_sequential(
  File "C:\Users\hahy\Miniconda3\envs\ml\Lib\site-packages\optuna\study\_optimize.py", line 163, in _optimize_sequential
    frozen_trial = _run_trial(study, func, catch)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hahy\Miniconda3\envs\ml\Lib\site-packages\optuna\study\_optimize.py", line 251, in _run_trial
    raise func_err
  File "C:\Users\hahy\Miniconda3\envs\ml\Lib\site-packages\optuna\study\_optimize.py", line 200, in _run_trial
    value_or_values = func(trial)
                      ^^^^^^^^^^^
  File "c:\Users\hahy\examples\xgboost_integration.py", line 52, in objective
    bst = xgb.train(param, dtrain, evals=[(dvalid, "validation")], callbacks=[pruning_callback])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hahy\Miniconda3\envs\ml\Lib\site-packages\xgboost\core.py", line 729, in inner_f
    return func(**kwargs)
           ^^^^^^^^^^^^^^
  File "C:\Users\hahy\Miniconda3\envs\ml\Lib\site-packages\xgboost\training.py", line 167, in train
    cb_container = CallbackContainer(
                   ^^^^^^^^^^^^^^^^^^
  File "C:\Users\hahy\Miniconda3\envs\ml\Lib\site-packages\xgboost\callback.py", line 139, in __init__
    raise TypeError("callback must be an instance of `TrainingCallback`.")
TypeError: callback must be an instance of `TrainingCallback`.

Steps to reproduce

  1. code downloaded at https://github.com/optuna/optuna-examples/blob/main/xgboost/xgboost_integration.py

Reproducible examples (optional)

Additional context (optional)

@anhailing anhailing added the bug Issue/PR about behavior that is broken. Not for typos/CI but for example itself. label Sep 15, 2023
@anhailing anhailing changed the title error occurred running xgboost_integration.py optuna.integration.XGBoostPruningCallback is not xgboost TrainingCallback Sep 15, 2023
@johnchoiniere
Copy link

I'm experiencing the same error, and update somewhere seems to have broken the xgb integration

@toshihikoyanase
Copy link
Member

I guess optuna/optuna#4921 resolved this issue, and it will be included in the next release (v3.4).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue/PR about behavior that is broken. Not for typos/CI but for example itself.
Projects
None yet
Development

No branches or pull requests

3 participants