-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
AttributeError: Can\'t pickle local object \'_objective_function_wrapper.<locals>.inner #2189
Comments
@pseudotensor Thank you very much for the bug catch! And special thanks for the solutions! |
Ya just change
to
in 2 places in python-package/lightgbm/sklearn.py Can add the above code as test. |
Unfortunately, that doesn't work, still get:
|
But this still works, so it's still some kind of problem inside LightGBM. |
Maybe the use of decorators needs to be avoided entirely. |
@pseudotensor Got it work locally by converting to a new class as mentioned in http://gael-varoquaux.info/programming/decoration-in-python-done-right-decorating-and-pickling.html. Will submit a PR with tests tomorrow. |
Thanks, would be great to get this fixed soon :) |
I'm having this same issue with version 2.2.3 of LightGBM in Python 3.5.7. Running the example code above raises the AttributeError exception. However if I install from sources version 2.2.4 the issue is gone. Indeed it seems the fix is not merged in version 2.2.3 sources here, https://pypi.org/project/lightgbm/#history since sklearn.py still has the inner and wrapper declarations instead of the wrapper class. Would it be possible to release a new PyPi version of the packages with the fix merged in? I can't install the sources version in my production environment because of the CMake dependency. |
LightGBM models are normally picklable, but when using a custom objective (and I assume eval_function etc.) they are not picklable.
Leads to:
The problem is the def inside def way of defining the function:
https://github.com/microsoft/LightGBM/blob/master/python-package/lightgbm/sklearn.py#L18-L78
The solution is to either:
functools.wraps
http://gael-varoquaux.info/programming/decoration-in-python-done-right-decorating-and-pickling.html
The text was updated successfully, but these errors were encountered: