Dataset Inheritance does not require super?

I have seen in the Dataset pytorch tutorial (Writing Custom Datasets, DataLoaders and Transforms — PyTorch Tutorials 2.2.0+cu121 documentation) that super is not called when inheriting from Dataset.

Does anyone know why this has not been done?

1 Like

torch.utils.data.Dataset doesn’t define its own __init__ so by calling super().__init__() you are not performing any meaningful actions. In comparison, calling super().__init__() when subclassing torch.nn.Module is required to initialize the internal data structures for storing buffers, modules, etc.

2 Likes

So when extending the Dataset class we should not use super().__init__() in our init function of the new class that extends Dataset?

You can, but it’s not necessary. The end-result is the same.