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

[python-package] Add progress_bar callback using tqdm #5867

Closed
wants to merge 14 commits into from

Conversation

34j
Copy link

@34j 34j commented May 5, 2023

Use tqdm to display training progress and metrics and, if necessary, early_stopping results. tqdm does not need to be installed and is compatible with the existing code.

Example:

X_train, X_test, y_train, y_test = train_test_split(...)
gbm = lgb.LGBMRegressor()
early_stopping_callback = lgb.early_stopping(stopping_rounds=50)
callback = lgb.progress_bar("rich", early_stopping_callback=early_stopping_callback)
gbm.fit(
    X_train,
    y_train,
    eval_set=[(X_test, y_test)],
    callbacks=[early_stopping_callback, callback],
)

image

X_train, X_test, y_train, y_test = train_test_split(...)
gbm = lgb.LGBMRegressor()
early_stopping_callback = lgb.early_stopping(stopping_rounds=50)
callback = lgb.progress_bar(early_stopping_callback=early_stopping_callback)
gbm.fit(
    X_train,
    y_train,
    eval_set=[(X_test, y_test)],
    callbacks=[early_stopping_callback, callback],
)

image
I tried sys.stderr.flush() and so on, but the output was inevitably broken when using tqdm.std.tqdm.

@34j 34j force-pushed the feat/add-tqdm-callback branch from 0065605 to d1f39ea Compare May 5, 2023 06:35
Copy link
Collaborator

@jameslamb jameslamb 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 the suggestion! But I don't support adding this much complexity and maintenance burden to the project in exchange for a progress bar.

I'd welcome the addition of this callback as documentation, like in https://github.com/microsoft/LightGBM/tree/master/examples/python-guide, but not as an addition to the project's public API which needs to be maintained.

@jmoralez what do you think?

@34j
Copy link
Author

34j commented May 5, 2023

Hello, thank you very much for your prompt reply and great project.😀

I understand your sentiments, but I would like to ask you to merge this PR, as there are so many LightGBM extension packages in this world that users get confused. The code may look long, but the Black formatting just adds lines and does not change the existing code. I don't think adding documentation or merging would make any difference in the maintenance burden. Copy-pasting the documentation code every time is a pain.

@jameslamb
Copy link
Collaborator

there are so many LightGBM extension packages in this world that users get confused

What is this a reference to? Can you share some links to what you mean by "LightGBM extension packages"?

@34j 34j force-pushed the feat/add-tqdm-callback branch from ee1daee to 0dfc5f1 Compare May 5, 2023 13:25
@34j 34j force-pushed the feat/add-tqdm-callback branch from 0dfc5f1 to 8f07b5c Compare May 5, 2023 13:27
@jameslamb
Copy link
Collaborator

the Black formatting just adds lines and does not change the existing code

lightgbm does not black. I'm not sure what this comment is referring to.

I don't think adding documentation or merging would make any difference in the maintenance burden

This is not true. Here are some examples of things that could be avoided if this change were only made in examples/:

  • it wouldn't be necessary to make the callback serializable with pickle
  • it wouldn't be necessary to hardcode a list of specific tqdm classes
  • lightgbm would not pick up a new optional dependency on tqdm and need to support a wide range of versions of that library
  • installing types-tqdm in CI wouldn't be necessary

Nothing in lightgbm makes the use of a callback such as the one proposed impossible today.

This PR is proposing going further than "make it possible", instead proposing "please make it a new part of the public API of the package", which comes with the maintenance burden of continuing to guarantee that the code works in the wide range of operating systems and Python versions LightGBM supports.

I am not convinced that the inconvenience of not having such code available via pip install lightgbm is so great that this should be added to the library and maintained here.

If you choose to answer the request in #5867 (review) for some specific examples of the claim "there are so many LightGBM extension packages in this world that users get confused", that might change my opinion.

If another maintainer like @jmoralez makes a convincing case for adding something like this to the library, that might change my opinion.

But as of now, I am -1 on including this code in LightGBM.

I'd consider adding a simpler version of it (for example, without the hard-coded list of tqdm classes) in examples/.

@34j
Copy link
Author

34j commented May 18, 2023

I have given up on PR and created a package that addresses #5867, #4805, #3313 / #5808 at once and would appreciate if you could add it to the examples. https://github.com/34j/lightgbm-callbacks

@jameslamb
Copy link
Collaborator

I have given up on PR and created a package

Alright, I'll close this.

would appreciate if you could add it to the examples. https://github.com/34j/lightgbm-callbacks

At this time, it doesn't look to me like that project is being used by many people (according to https://pypistats.org/packages/lightgbm-callbacks) or that it's doing something so significantly different from what's possible with LightGBM that it should be added to https://github.com/microsoft/LightGBM#external-unofficial-repositories.

If that changes in the future, I'd happily consider a PR to add a mention of it to https://github.com/microsoft/LightGBM#external-unofficial-repositories.

If you'd like to answer the question I posed at #5867 (comment) with several examples, I'd also consider a callbacks-for-the-Python-package-specific section of the project's documentation at https://github.com/microsoft/LightGBM/blob/master/python-package/README.rst.

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants