Solved by ptrblck in post #2 
              
              
                You could randomly permute the indices and then slice the batch: 
batch = torch.arange(10).view(10, 1)
# select 5 samples randomly
idx = torch.randperm(10)[:5]
mini_batch = batch[idx]