Skip to content

[fix] lgbm 4.6.0 compatibility#207

Merged
HideakiImamura merged 7 commits intooptuna:mainfrom
ffineis:fix/lgbm-4.6.0-compatibility
Feb 20, 2025
Merged

[fix] lgbm 4.6.0 compatibility#207
HideakiImamura merged 7 commits intooptuna:mainfrom
ffineis:fix/lgbm-4.6.0-compatibility

Conversation

@ffineis
Copy link
Copy Markdown
Contributor

@ffineis ffineis commented Feb 19, 2025

Motivation

Makes two changes to let optuna-integration[lightgbm] be compatible with the latest release of lightgbm, 4.6.0.

Attempts to resolve issue 204

Here is a link to the diff between lightgbm 4.5.0 (works with optuna-integration[lightgbm]) and 4.6.0 (does not work).

The breaking changes are in these two PRs:

  • #6706. The fix for this is straightforard.
  • #6761. I'm less sure about my fix to address this change.

Description of the changes

  1. The feature_name and categorical_feature arguments to lgb.train and lgb.cv were removed in LightGBM #6706. So, makes those arguments default to None and only adds them to lgbm_kwargs in _LightGBMBaseTuner (and subsequent child classes) when they are explicitly provided. Adds a warning to the user that they should... not set these arguments. These should be removed in the future, but it's best to support backwards compatibility for folks still using lightgbm < 4.6.0.
  2. In LightGBM #6761 the structure of _agg_cv_result was changed and the literal cv_agg was removed. Therefore, we need to stop trying to match on cv_agg in LightGBMPruningCallback._find_evaluation_result to back out the correct cross validation metric set for early stopping callbacks.
  • I am admittedly not sure my changes are the right approach to fix LightGBMPruningCallback here and could use help from maintainers (of this repo or LightGBM).

@c-bata
Copy link
Copy Markdown
Member

c-bata commented Feb 19, 2025

@HideakiImamura Could you review this PR?

Copy link
Copy Markdown
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I have a minor comment. PTAL.

Comment on lines +387 to +390
deprecated_arg_warning = (
"Support for lgb.cv with argument {deprecated_arg} was removed from lightgbm 4.6.0 "
"and will not be supported by optuna in the future."
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to add explanations in the docstring. Could you add them like this? The removed version will be v6.0.0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup!

Copy link
Copy Markdown
Contributor Author

@ffineis ffineis Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see 7a69be9. I'm assuming v4.2.2 will be the first release with the deprecation notice? Then removal slotted for v6.0.0

Copy link
Copy Markdown
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your swift actions! LGTM!

@HideakiImamura HideakiImamura merged commit ac033ac into optuna:main Feb 20, 2025
30 checks passed
@ffineis ffineis deleted the fix/lgbm-4.6.0-compatibility branch February 20, 2025 04:18
@y0z y0z added this to the v4.3.0 milestone Apr 10, 2025
@y0z y0z added the compatibility Change that breaks compatibility. label Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compatibility Change that breaks compatibility.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants