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

fix: (issue #32689) AttributeError raised when using Trainer with eval_on_start=True in Jupyter Notebook. #32849

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

fshp971
Copy link
Contributor

@fshp971 fshp971 commented Aug 16, 2024

What does this PR do?

Fixes #32689 (issue)

The cause of issue #32689 is that in Jupyter Notebook, for a transformers.Trainer, when its argument eval_on_start is set to True, running Trainer.train() will lead to the following function execution order:

  1. NotebookProgressCallback.on_train_begin()
  2. NotebookProgressCallback.on_prediction_step()
  3. NotebookProgressCallback.on_train_end()

Running NotebookProgressCallback.on_prediction_step() directly after NotebookProgressCallback.on_train_begin() will result in two attributes of NotebookProgressBar, i.e., value and label, being used before assigned (see methods update(), update_bar() and display() of NotebookProgressBar in transformers/utils/notebook.py for details).

A very simple solution is to initialize both attributes value and label to None during the creation of NotebookProgressBar.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@amyeroberts @ArthurZucker

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@fshp971 fshp971 closed this Aug 17, 2024
@fshp971 fshp971 reopened this Aug 17, 2024
@ArthurZucker ArthurZucker requested review from muellerzr and removed request for muellerzr August 19, 2024 14:00
Copy link
Contributor

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

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

Nice and simple solution!

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

🤗

@ArthurZucker ArthurZucker merged commit f1d822b into huggingface:main Aug 22, 2024
21 checks passed
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request Aug 30, 2024
…ainer` with `eval_on_start=True` in Jupyter Notebook. (huggingface#32849)

fix: `AttributeError` raised when using `Trainer` with `eval_on_start=True` in Jupyter Notebook.
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request Aug 30, 2024
…ainer` with `eval_on_start=True` in Jupyter Notebook. (huggingface#32849)

fix: `AttributeError` raised when using `Trainer` with `eval_on_start=True` in Jupyter Notebook.
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.

eval_on_start triggers AttributeError in JupyterLab
4 participants