[python] make early_stopping callback pickleable#5012
[python] make early_stopping callback pickleable#5012jameslamb merged 25 commits intomicrosoft:masterfrom
early_stopping callback pickleable#5012Conversation
|
@Yard1 Hey, thank you very much for the interest in LightGBM and this contribution! As an early opinion I would say I support conversion complex functions with closures into classes. I think this will make callbacks usage more user friendly and LightGBM codebase simpler. Just a note: we have received a feedback about the need in flexibility of callbacks serializability from Neptune maintainers recently #4719. Also, XGBoost migrated to callback classes: dmlc/xgboost#6199. So I believe this is the right direction. |
|
I agree with @StrikerRUS , I definitely support the proposed direction. I'll mark this PR as "in-progress" for now. Please get the unit tests working again, and then we'll be able to provide a review. Let us know if you need help with the tests. |
early_stopping into a Callable classearly_stopping into a Callable class
|
@Yard1 since you're a new contributor, we'll have to manually approve CI runs on each commit This is something GitHub added last year (I think?) to combat abuse of GitHub Actions. Sorry for the inconvenience! |
|
@jameslamb All's good, was on the approving side myself many times 😂 The tests pass locally for me now, so it should be good! |
|
@jameslamb @StrikerRUS The CI is all green now! |
jameslamb
left a comment
There was a problem hiding this comment.
Thanks for this! The fact that tests are passing without needing any modification is a very good sign 🙌
Please see my first round of suggestions. I think it would be easier to review this PR if some of the style changes you've propose were reverted.
This reverts commit 7ca8b55.
early_stopping into a Callable classearly_stopping into a Callable class
|
@jameslamb I've applied your feedback, please take a look. Thanks! |
jmoralez
left a comment
There was a problem hiding this comment.
Thank you for this! LGTM
|
The tests are failing due to a scheduled Windows brownout in CI. |
jameslamb
left a comment
There was a problem hiding this comment.
Great test! Thanks very much for adding that, and for moving the pickling / unpickling helper functions into utils.py.
Please see one question I have about related changes in callback.py.
|
@jameslamb Had to merge with master, please rerun tests |
StrikerRUS
left a comment
There was a problem hiding this comment.
Thank you very much for your work! Please consider checking some very minor suggestions below from me.
StrikerRUS
left a comment
There was a problem hiding this comment.
Awesome work! Thank you very much for this PR!
|
@jameslamb Gentle ping :) |
|
Let me merge master again, maybe that will fix the CI |
|
@StrikerRUS @jameslamb CI is green now 🙏 |
|
@jameslamb Could you please take another look before merging? |
jameslamb
left a comment
There was a problem hiding this comment.
Looks great!
Thanks so much for your work on this, and for adding tests. 🚀
early_stopping into a Callable classearly_stopping callback pickleable
|
Thanks again for this! I changed the title to "make I've also added #5080 documenting the work to ensure that all other callbacks are pickleable. Thanks for bringing the issue to our attention. Good luck with |
|
Thanks! |
|
This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |

Hey, I'm a maintainer of LightGBM-Ray. I was working on early stopping support for that library, however the early stopping callback on LightGBM's master branch raises exceptions in our tests (see
test_linux_cutting_edge (3.7)).I assumed this is due to the
nonlocalvariables present in the callback and them not interacting well with Ray serialization using cloudpickle. I would imagine there would be similar issues with other distributed computing or serialization libraries.In order to solve that issue, I took the liberty of rewriting that callback into a callable class, with the
nonlocalvariables becoming attributes. This solved the issues with serialization. No functionality has been affected.Please let me know if this approach is suitable, and if not, I would love to discuss other potential solutions to the problem I am facing.