I guess get_batches might not return anything, so that the complete training and thus the loss calculation will be skipped and will later raise this error in:
train_history['loss'].append(loss.item())