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

Flaml: fix lgbm reproducibility #1369

Merged
merged 12 commits into from
Nov 1, 2024

Conversation

dannycg1996
Copy link
Collaborator

@dannycg1996 dannycg1996 commented Oct 24, 2024

Why are these changes needed?

In some cases, FLAML LGBM results are not reproducible, using the best model provided by FLAML. I can split the problem, and the solution, into two:

1. n_estimators on automl.model.model always = 1

As described in the title, the code self._model.set_params(n_estimators=best_iteration + 1) on LGBMEstimator.fit() causes the the n_estimators value to always be 1. I'm not sure why self._model.best_iteration_ is always 0 - I think it's due to using EarlyStopping? Regardless, we have no need to overwrite a correct n_estimators value, so I've removed this code (and my unit tests now pass!)

2. When a time_budget is set, LGBMEstimator sometimes is not reproducible, if the deadline is running out when the estimator is trained

This is a very similar issue to the one we recently resolved for the CatBoost model. Basically the callback causes the training of a model to differ, when the time budget is running out - thus making the loss impossible to reproduce. I've fixed this by simply deleting the if statement responsible - I think this is a clean solution.

Like with the CatBoost fix, I've also added a unit test, which fails when the if statement above is re-added to the codebase. This will help us identify if the issue is ever reimplemented somehow. It also allows others to test this issue, should they wish.

Also, am I okay to open an issue sometime to refactor this LGBMEstimator? There's a lot of defunct code, and it could be made both more readable and possibly more efficient.

Anyway, please let me know what you think!

Related issue number

Closes #1368

Checks

Copy link
Collaborator

@thinkall thinkall left a comment

Choose a reason for hiding this comment

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

Thank you so much for the PR, @dannycg1996 !

flaml/automl/model.py Outdated Show resolved Hide resolved
test/automl/test_regression.py Outdated Show resolved Hide resolved
flaml/automl/model.py Outdated Show resolved Hide resolved
@dannycg1996
Copy link
Collaborator Author

Hi @thinkall, thanks for taking the time to explain - I understand why you wish to keep the early stopping!
I've added the early stopping back in as you requested - once tests pass, please feel free to merge.

flaml/automl/model.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@thinkall thinkall left a comment

Choose a reason for hiding this comment

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

Thank you sooooooooo much, @dannycg1996 ! LGTM!

@dannycg1996
Copy link
Collaborator Author

dannycg1996 commented Oct 31, 2024

Ah, it seems I have an issue with this test which I added. That's fine - we know it isn't always possible to reproduce scores when EarlyStopping is concerned! I'll tweak the test to ensure that our reproduced loss is at least as good as the loss reported by FLAML, and then it should be re-approvable/mergeable!

…AML results, when LGBM earlystopping is involved
@dannycg1996
Copy link
Collaborator Author

Sorry about that @thinkall, I think it should be approvable and mergeable now!

@thinkall thinkall merged commit 5a74227 into microsoft:main Nov 1, 2024
16 checks passed
@dannycg1996 dannycg1996 deleted the flaml-fix-lgbm-reproducibility branch November 1, 2024 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: LGBM Results Not Reproducible
2 participants