Skip to content
Discussion options

You must be logged in to vote

Hi, could you explain what you mean by

I realized I can attach the data-related methods ([train|val]_dataloader, prepare_data) directly to LightningModule

Do you mean dynamically bind the dataloader method of datamodule to lightning module?
I would not personally recommend that because it can be harder to read and debug, especially if your LightningModule also defines dataloader methods that you may expect to run in a different context.

I recommend passing the datamodule/dataloader into the fit function like so:

trainer.fit(model, datamodule=datamodule)
# or
trainer.fit(model, train_dataloader=...)

Then it will be clear to any reader that the datamodule loaders are used for training.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@jhrmnn
Comment options

@awaelchli
Comment options

@jhrmnn
Comment options

@awaelchli
Comment options

@jhrmnn
Comment options

Answer selected by jhrmnn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment