Skip to content

Commit

Permalink
Don't pass callbacks=None to XGBoostSklearnEstimator._fit (#1322)
Browse files Browse the repository at this point in the history
* Don't pass `callbacks=None` to `XGBoostSklearnEstimator._fit`

The original implmentation would pass `callbacks=None` to `XGBoostSklearnEstimator._fit` and eventually lead to a `TypeError` of `XGBModel.fit() got an unexpected keyword argument 'callbacks'`. This PR instead does not pass the `callbacks=None` parameter to avoid the error.

* Update setup.py to allow for xgboost 2.x

---------

Co-authored-by: Li Jiang <bnujli@gmail.com>
  • Loading branch information
Atry and thinkall committed Aug 6, 2024
1 parent f27f98c commit 8e63dd4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions flaml/automl/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,12 +1418,10 @@ def fit(self, X_train, y_train, budget=None, free_mem_ratio=0, **kwargs):
# since xgboost>=1.6.0, callbacks can't be passed in fit()
self.params["callbacks"] = callbacks
callbacks = None
self._fit(
X_train,
y_train,
callbacks=callbacks,
**kwargs,
)
if callbacks is None:
self._fit(X_train, y_train, **kwargs)
else:
self._fit(X_train, y_train, callbacks=callbacks, **kwargs)
if callbacks is None:
# for xgboost>=1.6.0, pop callbacks to enable pickle
callbacks = self.params.pop("callbacks")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
extras_require={
"automl": [
"lightgbm>=2.3.1",
"xgboost>=0.90,<2.0.0",
"xgboost>=0.90,<3.0.0",
"scipy>=1.4.1",
"pandas>=1.1.4",
"scikit-learn>=1.0.0",
Expand Down

0 comments on commit 8e63dd4

Please sign in to comment.