Solved by Oli in post #2 
              
              
                I wrote this piece of code for another topic. It does use a loop to collect a batch from a dataset so I’m not sure if it could be useful to you. If it’s not, have you taken a look at pytorch’s batch sampler? 
Edit: What datastructures are X_train & y_train? Numpy arrays? Tensors? 
import numpy as np…