Best practices for accessing DataModule setup() info (e.g. n_classes, label encodings) from the lightning model __init__ #19208
Unanswered
turian
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.
Uh oh!
There was an error while loading. Please reload this page.
-
What are best practices for retrieving info from the DataModule setup in my LightningModule?
Use case: My LightningModule wants the label encoding in
__init__
. Okay, it doesn't really need it in__init__
, it needs it in its training/val steps. For metrics, etc. But I can't get it and my workaround is gnarly.Background Just started a new pipeline, wrote a DataModule. I put the dataset loading in my
setup()
, as directed. That step determines the number of classes and the label encoding in a deterministic way, so it should be the same across all nodes.didn't work, neither did
(!? maybe I should file a bug), so I'm back to:
But as I iterate on my code, and discover new features mean that my lightning module wants datamodule setup information, I'm stumped. What are the best practices?
I shouldn't put state in
prepare_data()
, the docs warn against that. Butsetup()
is designed in a way to be stateless and run on individual nodes, not the master.I do this but it's pretty gross:
Is there a better pattern?
Beta Was this translation helpful? Give feedback.
All reactions