Exact behaviour of .prepare_data() and .setup() in LightningDataModule when passing DM or dataloaders to Trainer in respect to internal hooks. #20375
Unanswered
tiefenthaler
asked this question in
Lightning Trainer API: Trainer, LightningModule, LightningDataModule
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
What is the exact behaviour of .
prepare_data()
and.setup()
in LightningDataModule when passing DM or dataloaders to Trainer.Which internal hooks are getting triggered in both scenarios?
What is given
Let´s assume the following is implemented:
.prepare_data()
and.setup()
and train, val, test, predict dataloaders)Lightning Docs - Hooks:
.prepare_data
.setup
Trainer.fit/val/test/predict
When passing dataloaders to Trainer
dm.prepare_data()
anddm.setup(stage='fit')
to get information from the dataset to build the model.trainer.fit(model=lightningmodel, train_dataloaders=dm.train_dataloader(), val_dataloaders=dm.val_dataloader())
.prepare_data
and.setup
are called two times respectively fordm.train_dataloader()
anddm.val_dataloader()
? Since two dataloaders are requested separately..prepare_data
or.prepare_data
+.setup
were executed manually, they will be executed again (a 2. and 3. time), since two dataloaders are requested separately?Trainer.fit()
it also triggers the.prepare_data
and.setup
hooks?Trainer.test(dataloaders=dm.test_dataloader())
,.prepare_data
and.setup
are called again?.prepare_data
and.setup
in hooks?When passing LightningDataModule to Trainer
dm.prepare_data()
anddm.setup(stage='fit')
to get information from the dataset to build the model.trainer.fit(datamodule=dm)
.prepare_data
or.prepare_data
+.setup
were executed manually, they will be executed again, since dataloaders are requested?Trainer.fit()
it also triggers the.prepare_data
and.setup
hooks?Trainer.test(datamodule=dm)
,.prepare_data
and.setup
are called again?.prepare_data
and.setup
in hooks?Beta Was this translation helpful? Give feedback.
All reactions