In the doc, it is mentioned that “teardown can be used to clean up the state. It is also called from every process across all the nodes.” and “setup is called from every process across all the nodes. Setting state here is recommended.”
I write an example based on the example according to the document:
def setup(self, stage):
assert isinstance(stage, str) and stage in ('fit', 'validate', 'test') # , 'predict'
if stage == 'fit':
self.traset = MyDataset(stage='train')
self.valset = MyDataset(stage='val')
elif stage == 'validate':
self.valset = MyDataset(stage='val')
else: # 'test'
self.tstset = MyDataset(stage='tst')
Does that mean my teardown() should be as follows?
def teardown(self, stage):
assert isinstance(stage, str) and stage in ('fit', 'validate', 'test') # , 'predict'
if stage == 'fit':
del self.traset
del self.valset
elif stage == 'validate':
del self.valset
else: # 'test'
del self.tstset
But what is the practical significance of doing so? Is it necessary? Without teardown(), won’t the objects pointed to by self.traset, self.valset, and self.tstset be destroyed together with the MYDataModule() object?