By default, loss functions such as crossentrophy(or log_softmax + nllloss) use mean reduction on the batch losses.
Given
N = No of datapoints
bs = batch_size
len(loader) = N/bs
Loss = (l1 + l2 + l3 + …)/bs + (l1 + l2 + l3 + …)/bs + …
Then Loss/len(loader) = Loss*bs/N = (Sum of all l)/N
So you can see that the batch size you use for test case doesn’t matter(there will be change in value if the last batch is not full)
You can keep the default mean reduction in your loss function, sum up all your losses, divide it by len(loader) for both train and val regardless of different batch sizes. One other way for train is to append all your batch losses and return it, this gives better loss fluctuation information though your plots may get messy.