How can I write a custom batch sampler in Pytorch for stochastic gradient descent? That is, if my dataset has keys {1, ..., n} I want to be able to return batches {1, 5, 6}, {2, 3, 8}, so on, without replacement, until I've used all the data and begin the next epoch of my training loop.
How can this be done? For example, let's suppose I wanted to write a really basic batch sampler which uniformly chose batches of size batch_size from {1, .., n} without replacement, how could I implement that? (note that I know this is already done in Pytorch since the default batch sampler batches up the keys as ordered by a sampler object. I want to create a custom batch sampler, but this special case would be enough for me to generalise off of).