-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[DataModule] prepare_data()
and setup()
not called
#2742
Comments
TL;DR: you can update your code to look like this: # Init a datamodule
dm = MyDataModule()
# Manually call prepare_data and setup. You could put this at end of __init__ if you want
dm.prepare_data()
dm.setup()
model = MyLightningModule()
trainer = Trainer(gpus=1)
trainer.fit(model, datamodule=dm) That being said, we're open to any ideas on making this more intuitive, so feel free to throw out some alternatives. 😄 |
Anyway thank you for the clear answer ^^ |
@remisphere I totally didn't notice! You were completely right on the dm arg. things move fast haha. Reopening actually, as I think your intended use is more user friendly. |
🐛 Bug
It seems that when using DataModule to separate training logic and data loading,
of the five methods that should be called that are
prepare_data()
,setup()
,train_dataloader()
,val_dataloader()
andtest_dataloader()
,only the last three are actually used, witch is problematic since the datasets used by the data-loaders should be assigned in the
setup()
.To Reproduce
Steps to reproduce the behavior:
Run this:
Code sample
this gives
AttributeError: 'MyDataModule' object has no attribute 'train_dataset'
.Expected behavior
When entering
train_dataloader()
,prepare_data()
andsetup()
should already have been executed, and thus thetrain_dataset
attribute should exist.Additional context
IMHO, it comes from here
Environment
The text was updated successfully, but these errors were encountered: