I’m not familiar with your code, but it seems the shape changes for some batches.
Could the last batch be smaller (e.g. single sample) than the other ones?
What dimension should squeeze() get rid of?
If you just want to squeeze dim1, you could call .squeeze(1). Otherwise if dim0 and dim1 are both 1, both dimension will be squeezed which might yield this error.