John1231983:

loss_sum = 0 for i in range(iter_size): loss = criterion(output, target_var) / iter_size loss.backward() loss_sum += loss.item() # Change here optimizer.step()


Got it. Just small thing, Do you think divide the loss by iter_size inside or outside of loop? I mean
for  i in range(iter_size):
    loss = criterion(output, target_var) / iter_size
    loss.backward()
    loss_sum += loss.item() # Change here

or
for  i in range(iter_size):
    loss = criterion(output, target_var) 
    loss.backward()
    loss_sum += loss.item() # Change here
loss_sum = loss_sum / iter_size