-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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] Create explicit setup and teardown hooks for each stage on the Lightning and DataModules #6420
Comments
One tricky issue about this is that So implementing this change would need to consider this case. This also is problematic given the current direction the model parallel hook is taking: #6679 (comment) cc: @SeanNaren |
This issue has been automatically marked as stale because it hasn't had any recent activity. This issue will be closed in 7 days if no further activity occurs. Thank you for your contributions, Pytorch Lightning Team! |
This issue has been automatically marked as stale because it hasn't had any recent activity. This issue will be closed in 7 days if no further activity occurs. Thank you for your contributions, Pytorch Lightning Team! |
🚀 Feature
LightningModules and DataModules currently support a setup API which takes an optional
stage
argument.#6386 addresses some issues in the setup/teardown lifecycle, so I was wondering if we should take this further (#6401)
Motivation
Pros of making the separate hooks for each stage:
stage
that user code might not handle. With the explicit hooks, new stages becomes opt-in for users, as users must implement the corresponding hook in their lightning/data modulehas_setup_{stage}
attributes since it'll be obvious when the hooks are calledCons:
Pitch
We add the following hooks to the
DataHooks
base:on_{stage}_prepare_data
on_{stage}_setup
on_{stage}_teardown
for the existing values of
stage
: fit, test, validate, predictSimilarly, we add corresponding hooks to the Callback base:
on_{stage}_setup
on_{stage}_teardown
During the migration, in the trainer, if the Lightning(Data)Module has this hook implemented, then we call it. Otherwise, we fallback to calling the existing setup/teardown hooks. We do the same for the callback hooks.
We could set a longer deprecation timeline for this given how prevalent these hooks are. For example, we don't deprecate
prepare_data
,setup
, orteardown
until version 1.7+.Additionally, we should move the trainer argument
prepare_data_per_node
to the DataHooks base, similar to howautomatic_optimization
is a property of the LightningModule. This point is separate from the overall hooks discussion and could happen faster to slightly simplify the trainer API.Alternatives
Keep the existing hooks
Additional context
The text was updated successfully, but these errors were encountered: