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

[RFC] Deprecate on_pretrain_routine_start and on_pretrain_routine_end LM/callback hooks #10984

Closed
daniellepintz opened this issue Dec 8, 2021 · 14 comments · Fixed by #11794 or #12122
Closed
Assignees
Labels
deprecation Includes a deprecation discussion In a discussion stage good first issue Good for newcomers help wanted Open to be worked on hooks Related to the hooks API
Milestone

Comments

@daniellepintz
Copy link
Contributor

daniellepintz commented Dec 8, 2021

Proposed refactor

Deprecate these hooks:
https://github.com/PyTorchLightning/pytorch-lightning/blob/6369e3b77fa3f38613b661517f6361f842f611c9/pytorch_lightning/trainer/trainer.py#L1261-L1269

Motivation

Users can use on_train_start, on_fit_start, or setup for the same purpose.

Additional Context

These hooks were originally added in #2850

I see about 30 usages of each hook using grep.app:
https://www.grep.app/search?q=on_pretrain_routine_start
https://www.grep.app/search?q=on_pretrain_routine_end

Part of #7740
Carries forward discussion #9043 on these hooks

cc @Borda @tchaton @rohitgr7 @carmocca @awaelchli @ninginthecloud @daniellepintz

@daniellepintz daniellepintz added deprecation Includes a deprecation hooks Related to the hooks API labels Dec 8, 2021
@daniellepintz daniellepintz self-assigned this Dec 8, 2021
@rohitgr7
Copy link
Contributor

rohitgr7 commented Dec 8, 2021

I have suggested some users over slack #questions to use these hooks for their use-case because on_train_start wasn't working for them. I can't remember what their use-case was.

Users can use on_train_start and on_train_end for the same purpose.

not sure if on_train_end is an alternative here for these hooks?

@ananthsub
Copy link
Contributor

ananthsub commented Dec 8, 2021

not sure if on_train_end is an alternative here for these hooks?

good catch. it should just be on_train_start

another weird thing with these hooks now is that there is nothing that happens between on_pretrain_routine_start and on_pretrain_routine_end, meaning at the very least, these hooks could be collapsed into one, if not fully deprecated. before, the model summary used to be printed here, but that was since refactored out to a callback. that callback could also run in on_train_start

similarly, this could be run in setup: https://github.com/PyTorchLightning/pytorch-lightning/blob/aeb0b5595fd73d086f4ae0f99d3f1f112f6a4c29/pytorch_lightning/callbacks/model_checkpoint.py#L257

@daniellepintz
Copy link
Contributor Author

not sure if on_train_end is an alternative here for these hooks?

yeah good call, updated the description.

meaning at the very least, these hooks could be collapsed into one, if not fully deprecated.

yeah agreed. I think between on_train_start and setup we should be able to give users the same functionality. I searched in the slack #questions channel but was unable to find the users @rohitgr7 was referring to. Rohit, do you think setup would also have worked for the users who were having trouble with on_train_start?

@rohitgr7
Copy link
Contributor

rohitgr7 commented Dec 8, 2021

yeah agreed. I think between on_train_start and setup we should be able to give users the same functionality. I searched in the slack #questions channel but was unable to find the users @rohitgr7 was referring to. Rohit, do you think setup would also have worked for the users who were having trouble with on_train_start?

tbh I don't recall the actual use-case, I can't find them either since we have 10K limit for messages on slack. I am ok if these could be collapsed into one. I don't use this hook often. If everyone else agrees, I am ok with deprecation too.

@daniellepintz
Copy link
Contributor Author

Ok, let's see what other people think about deprecation

@daniellepintz daniellepintz added this to To be approved in Lightning Sprint Dec 10, 2021
@carmocca
Copy link
Member

Looking at their position here

https://github.com/PyTorchLightning/pytorch-lightning/blob/6369e3b77fa3f38613b661517f6361f842f611c9/tests/models/test_hooks.py#L525-L528

I'd say on_fit_start is a more natural replacement.

I'm not sure at the moment whether they should be removed (after a deprecation ofc), but they sure could be collapsed into one hook.

This proposal is also missing links for

(1): The issue/PR that added them. You can use git blame to find it.
(2): Examples of public usage (or the lack of public usage). You can use www.grep.app for this

@carmocca carmocca added the discussion In a discussion stage label Dec 14, 2021
@daniellepintz
Copy link
Contributor Author

This proposal is also missing links for
(1): The issue/PR that added them. You can use git blame to find it.
(2): Examples of public usage (or the lack of public usage). You can use www.grep.app for this

Added both to the issue. From the grep.app search, it does seem to me that these usages could be replaced by on_fit_start or setup.

@daniellepintz
Copy link
Contributor Author

@tchaton what do you think about deprecating these hooks?

@tchaton
Copy link
Contributor

tchaton commented Jan 21, 2022

Hey @daniellepintz. Great question. I can see Bolt and other repos use it, but we should incentivize for cleaner code. So I am in favor of the depreciation.

@carmocca
Copy link
Member

Me too

@daniellepintz daniellepintz added good first issue Good for newcomers help wanted Open to be worked on labels Jan 21, 2022
@daniellepintz daniellepintz removed their assignment Jan 21, 2022
@daniellepintz
Copy link
Contributor Author

daniellepintz commented Jan 21, 2022

For anyone who wants to pick up this issue, here is an example PR to follow: #10940

@krishnakalyan3
Copy link
Contributor

I would like to work on this

@daniellepintz
Copy link
Contributor Author

@krishnakalyan3 Assigned to you, thanks!!

@daniellepintz
Copy link
Contributor Author

Reopening since we still need to do the LM hooks

pangyuteng pushed a commit to pangyuteng/latent-diffusion that referenced this issue Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation Includes a deprecation discussion In a discussion stage good first issue Good for newcomers help wanted Open to be worked on hooks Related to the hooks API
Projects
No open projects
Status: Done
Lightning Sprint
To be approved
6 participants