How does one create a data set in pytorch and save it into a file to later be used?

Using Artur’s solution:

Just sort the indices according to the criteron I have, save those indices and recover them from a file whenever I need them. Then use the data sampler!