It depends how you would like to print the running loss value.
In the first example the current loss average of the batch will be added to running_loss, printed after 2000 iterations and reset.
The second example prints the loss for the complete epoch and is a bit more accurate.
Depending on the batch size and the length of your dataset, the last batch might be smaller than the specified batch size. If that’s the case, you could multiply the loss by the current batch size (loss.item() * inputs.size(0)) and divide by the total length of the dataset running_loss / dataset_sizes[phase].