Thanks for the code and debugging.
If the length of your Dataset is not divisible by the batch size without a remainder, the last batch might be smaller than the rest.
Try to set drop_last=True in your DataLoader and run the code again.