PyTorch batch Size suddenly reduced after n epochs

Viewed 250

I have a pytorch nn model running on win 10 cpu. batch size is 42 After 67 iterations, a strange thing happens: batch size is suddenly reduced to 28, and I get

RuntimeError: Expected hidden[0] size (1, 28, 256), got (1, 42, 256)
1 Answers

Is it possible the number of training examples in the dataset is not divisible by 42? Could it be that the reminder is 28?

If your model cannot handle online change of batch size, you should consider setting drop_last=True in your torch.utils.data.DataLoader, thus only full batches will be processed during training.

Related