fix: LightGBM 4.0+ compatibility for early_stopping_rounds=None#2227
Closed
Olcmyk wants to merge 1 commit into
Closed
fix: LightGBM 4.0+ compatibility for early_stopping_rounds=None#2227Olcmyk wants to merge 1 commit into
Olcmyk wants to merge 1 commit into
Conversation
- Only create early_stopping callback when rounds is not None - LightGBM 4.0+ requires stopping_rounds to be an integer, not None - Apply fix to gbdt.py, ddgda.py, and highfreq_gdbt_model.py - Follow the pattern already used in double_ensemble.py This fixes the TypeError that occurs when early_stopping_rounds=None is passed to lgb.early_stopping() in LightGBM 4.0+. Affected files: - qlib/contrib/model/gbdt.py: Core LGBModel fix - qlib/contrib/rolling/ddgda.py: Remove explicit None assignment - qlib/contrib/model/highfreq_gdbt_model.py: Add robustness check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a compatibility issue with LightGBM 4.0+ where passing
early_stopping_rounds=Nonecauses aTypeError.Changes:
Affected files:
qlib/contrib/model/gbdt.py: Core LGBModel fixqlib/contrib/rolling/ddgda.py: Remove explicit None assignmentqlib/contrib/model/highfreq_gdbt_model.py: Add robustness checkMotivation and Context
Fixes #2226
Problem: Starting from LightGBM 4.0, the
lgb.early_stopping()function requiresstopping_roundsto be an integer and no longer acceptsNone. This breaks qlib's code that attempts to disable early stopping by passingNone.Error:
Root cause:
qlib/contrib/model/gbdt.py:71-73directly passesearly_stopping_roundstolgb.early_stopping()without checking for Noneqlib/contrib/rolling/ddgda.py:244explicitly setsearly_stopping_rounds: NoneSolution: Only create the early_stopping callback when the value is not None, following the pattern already correctly implemented in
double_ensemble.py.How Has This Been Tested?
Testing environment:
Test method:
cd examples/benchmarks_dynamic/DDG-DA rm -rf mlruns python workflow.py runTypeError: early_stopping_round should be an integerno longer occursNote: The standard
pytest qlib/tests/test_all_pipeline.pydoes not cover this specific scenario as it requires:early_stopping_rounds=NoneusageScreenshots of Test Results (if appropriate):
Before fix:
After fix:
Training completes successfully without TypeError.
Types of changes
Additional Notes
Known issue discovered during testing:
After fixing this LightGBM bug, the DDG-DA workflow encounters another bug:
This is a separate issue in the DDG-DA code itself (not related to LightGBM) where a slice object is being used as a dictionary key. This should be tracked and fixed in a separate issue/PR.
References