How did you solve your first error?
Did you drop the last batch (which was too small)?
As far as I understand you need mX for your loss function. Would it be possible to just return them in the forward method and calculate the loss?