Solved by Valerio_Biscione in post #2 
              
              
                something like this  
tot_iter = 0
max_iterations = 100

while True:   # if you want to iterate for inf epochs, use this endless loop
    for batch_index, data in enumerate(data_loader, 0):
        ...training, backpropr, etc...
        tot_iter += 1  
        if tot_iter >= max_iterations:
        …