If you want to preload the complete dataset, you could pass it to a TensorDataset.
On the other hand, if you are dealing with image data, which is stored as separate image files in folders corresponding to the classes, you could use ImageFolder.
Depending on the dataset and how each sample is stored, you might write a custom Dataset as described here 19.