Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Updated LightGBM to 4.1 and Optuna to 3.3, and the other packages #29

Merged
merged 7 commits into from
Dec 6, 2023

Conversation

EchoDel
Copy link
Contributor

@EchoDel EchoDel commented Sep 28, 2023

Mainly updated LightGBM to the more recent 4.0 release, although optuna was an easy update as well.
My company expects packages to update to the major version before releasing anything.

I ensured that all the test suite ran before submitting the PR

Copy link
Owner

@StatMixedML StatMixedML 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 PR. Two minor things:

  • can you please silent the lgb output during cv and training in model.py
  • can you please use version 4.1.0 in the setup.py

Thanks

@EchoDel
Copy link
Contributor Author

EchoDel commented Oct 2, 2023

So I've addressed the second comment but I'm not sure its possible to address point 1 for now.

I've dug into the changelog and code and I can't see anyway to suppress the message.
This is the only mention in the changelog and it doesn't even have the commit message.
[python-package] remove 'fobj' in favor of passing custom objective func...

when you look in the parameters its not really mentioned that you can use a custom objective function, although in the python API its mentioned in the notes that you can do that, but nothing about how to suppress the message.

Finally in the source code the message is created when the objective function isn't the base one with no statement for overriding it.
https://github.com/microsoft/LightGBM/blob/63a882b7400a19485727cc808e4715897e63635a/src/c_api.cpp#L322

@StatMixedML
Copy link
Owner

Thanks for your changes. Can you please open an issue on the LightGBM repo asking how to silence the output. Thanks.

@EchoDel
Copy link
Contributor Author

EchoDel commented Oct 3, 2023

So I've just seen this issue already exists in the lightgbm repo.

microsoft/LightGBM#6014

I'm not sure if you want the temporary work around of the custom logger class implemented?

@StatMixedML
Copy link
Owner

Does the custom logger verbose output for both .cv and .train?

@StatMixedML
Copy link
Owner

@EchoDel To keep the PR open, can you please check the open issues on the verbosity, thanks.

@EchoDel
Copy link
Contributor Author

EchoDel commented Nov 15, 2023

Sorry for the delay. Yeh this would fix both since we register it with lgbm at the start

@StatMixedML
Copy link
Owner

StatMixedML commented Nov 24, 2023

@EchoDel Using the suggestion from the lightgbm-issue does not work.

I am using

import lightgbm as lgb
class CustomLogger:
    def init(self):
        self.logger = logging.getLogger('lightgbm_custom')
        self.logger.setLevel(logging.ERROR)

    def info(self, message):
        self.logger.info(message)
    
    def warning(self, message):
        # Suppress warnings by not doing anything
        pass
    
    def error(self, message):
        self.logger.error(message)

lgb.register_logger(CustomLogger())

and this gives the following. Can you please look into this.

Exception ignored on calling ctypes callback function: <function _log_callback at 0x0000026D45999760>
Traceback (most recent call last):
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 205, in _log_callback
    _log_native(str(msg.decode('utf-8')))
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 183, in wrapper
    return func(msg)
           ^^^^^^^^^
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 200, in _log_native
    getattr(_LOGGER, _INFO_METHOD_NAME)(msg)
  File "C:\Users\maerzale\AppData\Local\Temp\ipykernel_14620\1534461007.py", line 7, in info
AttributeError: 'CustomLogger' object has no attribute 'logger'
Exception ignored on calling ctypes callback function: <function _log_callback at 0x0000026D45999760>
Traceback (most recent call last):
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 205, in _log_callback
    _log_native(str(msg.decode('utf-8')))
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 183, in wrapper
    return func(msg)
           ^^^^^^^^^
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 200, in _log_native
    getattr(_LOGGER, _INFO_METHOD_NAME)(msg)
  File "C:\Users\maerzale\AppData\Local\Temp\ipykernel_14620\1534461007.py", line 7, in info
AttributeError: 'CustomLogger' object has no attribute 'logger'
Exception ignored on calling ctypes callback function: <function _log_callback at 0x0000026D45999760>
Traceback (most recent call last):
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 205, in _log_callback
    _log_native(str(msg.decode('utf-8')))
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 183, in wrapper
    return func(msg)
           ^^^^^^^^^
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 200, in _log_native
    getattr(_LOGGER, _INFO_METHOD_NAME)(msg)
  File "C:\Users\maerzale\AppData\Local\Temp\ipykernel_14620\1534461007.py", line 7, in info
AttributeError: 'CustomLogger' object has no attribute 'logger'
Exception ignored on calling ctypes callback function: <function _log_callback at 0x0000026D45999760>
Traceback (most recent call last):
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 205, in _log_callback
    _log_native(str(msg.decode('utf-8')))
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 183, in wrapper
    return func(msg)
           ^^^^^^^^^
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 200, in _log_native
    getattr(_LOGGER, _INFO_METHOD_NAME)(msg)
  File "C:\Users\maerzale\AppData\Local\Temp\ipykernel_14620\1534461007.py", line 7, in info
AttributeError: 'CustomLogger' object has no attribute 'logger'
Exception ignored on calling ctypes callback function: <function _log_callback at 0x0000026D45999760>
Traceback (most recent call last):
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 205, in _log_callback
    _log_native(str(msg.decode('utf-8')))
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 183, in wrapper
    return func(msg)
           ^^^^^^^^^
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 200, in _log_native
    getattr(_LOGGER, _INFO_METHOD_NAME)(msg)
  File "C:\Users\maerzale\AppData\Local\Temp\ipykernel_14620\1534461007.py", line 7, in info
AttributeError: 'CustomLogger' object has no attribute 'logger'
Exception ignored on calling ctypes callback function: <function _log_callback at 0x0000026D45999760>
Traceback (most recent call last):
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 205, in _log_callback
    _log_native(str(msg.decode('utf-8')))
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 183, in wrapper
    return func(msg)
           ^^^^^^^^^
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 200, in _log_native
    getattr(_LOGGER, _INFO_METHOD_NAME)(msg)
  File "C:\Users\maerzale\AppData\Local\Temp\ipykernel_14620\1534461007.py", line 7, in info
AttributeError: 'CustomLogger' object has no attribute 'logger'
Exception ignored on calling ctypes callback function: <function _log_callback at 0x0000026D45999760>
Traceback (most recent call last):
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 205, in _log_callback
    _log_native(str(msg.decode('utf-8')))
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 183, in wrapper
    return func(msg)
           ^^^^^^^^^
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 200, in _log_native
    getattr(_LOGGER, _INFO_METHOD_NAME)(msg)
  File "C:\Users\maerzale\AppData\Local\Temp\ipykernel_14620\1534461007.py", line 7, in info
AttributeError: 'CustomLogger' object has no attribute 'logger'
Exception ignored on calling ctypes callback function: <function _log_callback at 0x0000026D45999760>
Traceback (most recent call last):
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 205, in _log_callback
    _log_native(str(msg.decode('utf-8')))
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 183, in wrapper
    return func(msg)
           ^^^^^^^^^
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 200, in _log_native
    getattr(_LOGGER, _INFO_METHOD_NAME)(msg)
  File "C:\Users\maerzale\AppData\Local\Temp\ipykernel_14620\1534461007.py", line 7, in info
AttributeError: 'CustomLogger' object has no attribute 'logger'
Exception ignored on calling ctypes callback function: <function _log_callback at 0x0000026D45999760>
Traceback (most recent call last):
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 205, in _log_callback
    _log_native(str(msg.decode('utf-8')))
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 183, in wrapper
    return func(msg)
           ^^^^^^^^^
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 200, in _log_native
    getattr(_LOGGER, _INFO_METHOD_NAME)(msg)
  File "C:\Users\maerzale\AppData\Local\Temp\ipykernel_14620\1534461007.py", line 7, in info
AttributeError: 'CustomLogger' object has no attribute 'logger'
Exception ignored on calling ctypes callback function: <function _log_callback at 0x0000026D45999760>
Traceback (most recent call last):
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 205, in _log_callback
    _log_native(str(msg.decode('utf-8')))
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 183, in wrapper
    return func(msg)
           ^^^^^^^^^
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 200, in _log_native
    getattr(_LOGGER, _INFO_METHOD_NAME)(msg)
  File "C:\Users\maerzale\AppData\Local\Temp\ipykernel_14620\1534461007.py", line 7, in info
AttributeError: 'CustomLogger' object has no attribute 'logger'
Exception ignored on calling ctypes callback function: <function _log_callback at 0x0000026D45999760>
Traceback (most recent call last):
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 205, in _log_callback
    _log_native(str(msg.decode('utf-8')))
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 183, in wrapper
    return func(msg)
           ^^^^^^^^^
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 200, in _log_native
    getattr(_LOGGER, _INFO_METHOD_NAME)(msg)
  File "C:\Users\maerzale\AppData\Local\Temp\ipykernel_14620\1534461007.py", line 7, in info
AttributeError: 'CustomLogger' object has no attribute 'logger'
Exception ignored on calling ctypes callback function: <function _log_callback at 0x0000026D45999760>
Traceback (most recent call last):
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 205, in _log_callback
    _log_native(str(msg.decode('utf-8')))
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 183, in wrapper
    return func(msg)
           ^^^^^^^^^
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 200, in _log_native
    getattr(_LOGGER, _INFO_METHOD_NAME)(msg)
  File "C:\Users\maerzale\AppData\Local\Temp\ipykernel_14620\1534461007.py", line 7, in info
AttributeError: 'CustomLogger' object has no attribute 'logger'
Exception ignored on calling ctypes callback function: <function _log_callback at 0x0000026D45999760>
Traceback (most recent call last):
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 205, in _log_callback
    _log_native(str(msg.decode('utf-8')))
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 183, in wrapper
    return func(msg)
           ^^^^^^^^^
  File "C:\Users\maerzale\.virtualenvs\LightGBMLSS-8W0JA8W6\Lib\site-packages\lightgbm\basic.py", line 200, in _log_native
    getattr(_LOGGER, _INFO_METHOD_NAME)(msg)
  File "C:\Users\maerzale\AppData\Local\Temp\ipykernel_14620\1534461007.py", line 7, in info
AttributeError: 'CustomLogger' object has no attribute 'logger'

This suppresses the messages for lightgbm version 4.1
@EchoDel
Copy link
Contributor Author

EchoDel commented Nov 25, 2023

I think this push has got the custom logger working.

There are alot of other packages which have been updated, particularly torch which had an issues in 2.1.0 and 2.0.1 which I could wrap into this PR is you want.

@StatMixedML
Copy link
Owner

@EchoDel Is the custom logger working now? Haven't tested it yet

@EchoDel
Copy link
Contributor Author

EchoDel commented Nov 28, 2023

Yep, the logger suppresses all the warning messages

lightgbmlss/model.py Outdated Show resolved Hide resolved
@StatMixedML
Copy link
Owner

I think this push has got the custom logger working.

There are alot of other packages which have been updated, particularly torch which had an issues in 2.1.0 and 2.0.1 which I could wrap into this PR is you want.

Yes please, thanks. The updated packages are

"lightgbm~=4.1.0",
"torch~=2.1.1",
"pyro-ppl~=1.8.6",
"optuna~=3.4.0",
"properscoring~=0.1",
"scikit-learn~=1.3.2",
"numpy~=1.26.2",
"pandas~=2.1.3",
"plotnine~=0.12.4",
"scipy~=1.11.4",
"seaborn~=0.13.0",
"tqdm~=4.66.1",
"matplotlib~=3.8.2",
"ipython~=8.18.1",

@EchoDel EchoDel changed the title Updated LightGBM to 4.1 and Optuna to 3.3 and made the test work Updated LightGBM to 4.1 and Optuna to 3.3, and the other packages Nov 29, 2023
@StatMixedML
Copy link
Owner

@EchoDel Thanks for updating the dependencies. Can you please fix the remaining comments so that I can merge the PR. Thanks

@EchoDel
Copy link
Contributor Author

EchoDel commented Dec 5, 2023

The outstanding requests should be done.

@codecov-commenter
Copy link

Welcome to Codecov 🎉

Once merged to your default branch, Codecov will compare your coverage reports and display the results in this comment.

Thanks for integrating Codecov - We've got you covered ☂️

@@ -263,9 +265,9 @@ def cv(self,
self.set_params(params)
self.set_init_score(train_set)

params['objective'] = self.dist.objective_fn
Copy link
Owner

Choose a reason for hiding this comment

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

this is not needed if moved to set_params

@@ -389,13 +391,13 @@ def objective(trial):
callbacks=[pruning_callback, early_stopping_callback],
seed=seed,
)

print(lgblss_param_tuning)
Copy link
Owner

Choose a reason for hiding this comment

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

Why do we need it?

@StatMixedML StatMixedML merged commit 5f31fc2 into StatMixedML:master Dec 6, 2023
3 of 4 checks passed
@EchoDel EchoDel deleted the feature/package_updates branch December 19, 2023 10:51
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants