Based on the error message you are either using an input and target with a different batch size or the model reshapes the activation in a wrong way.
As mentioned before in related posts, please share an executable code snippet to reproduce this issue, so that we could debug it.