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

When I called Trainer.test, some hooks fit are also called #6376

Closed
dalek-who opened this issue Mar 6, 2021 · 3 comments · Fixed by #6386
Closed

When I called Trainer.test, some hooks fit are also called #6376

dalek-who opened this issue Mar 6, 2021 · 3 comments · Fixed by #6386
Labels
bug Something isn't working help wanted Open to be worked on

Comments

@dalek-who
Copy link
Contributor

🐛 Bug

When I called Trainer.test, some hooks fit are also called, which including: on_fit_start, on_fit_end, and teardown(stage=fit)
I found a similar issue of setup(stage=fit), that bug has been fixed, but seems these hooks also have this bug
#2715 (comment)

Please reproduce using the BoringModel

https://colab.research.google.com/drive/1GA2Uo8cBaziqoBUI5K2r5x5BjjaZQRJe?usp=sharing

Expected behavior

during trainer.test, on_fit_start, on_fit_end, teardown(stage=fit) should not be called
(also could you please check if other hooks have this bug?)

Environment

  • CUDA:
    • GPU:
      • Tesla T4
    • available: True
    • version: 10.1
  • Packages:
    • numpy: 1.19.5
    • pyTorch_debug: False
    • pyTorch_version: 1.7.1+cu101
    • pytorch-lightning: 1.2.2
    • tqdm: 4.41.1
  • System:
    • OS: Linux
    • architecture:
      • 64bit
    • processor: x86_64
    • python: 3.7.10
    • version: Proposal for help #1 SMP Thu Jul 23 08:00:38 PDT 2020

Additional context

@dalek-who dalek-who added bug Something isn't working help wanted Open to be worked on labels Mar 6, 2021
@awaelchli
Copy link
Contributor

awaelchli commented Mar 6, 2021

While it is an undesired behavior, it is indeed expected given the current flow in Trainer.
We test these cases here:
https://github.com/PyTorchLightning/pytorch-lightning/blob/85c8074beefd81cce12823c5bca7e5f6e93f237d/tests/callbacks/test_callbacks.py#L109

and because Trainer.test calls Trainer.fit internally, then it makes sense that these hooks get called.

To overcome this, a larger refactor/redesign is required.
We currently have to use the stage name in the hooks to avoid repeated execution.

@dalek-who
Copy link
Contributor Author

dalek-who commented Mar 7, 2021

@awaelchli However,if we run fit and test, teardown would be called three times:

  • teardown("fit") in trainer.fit
  • teardown("fit") in trainer.test
  • teardown("test") in trainer.test

using stage, operations in teardown("fit") will still be called twice, because we can't recognize who call teardown("fit")

@awaelchli
Copy link
Contributor

Well, turns out @carmocca is already working on that #6386

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Open to be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants