Usually this error is a shape mismatch. In my case, I used a wrong embedding layer (with different output size), so again a shape mismatch. Try to break your code in simple steps and figure out which step triggers the error. For example unit test your code, or run it interactively. I have not much time to help you out. Maybe the pytorch experts of the forum can provide some better ideas.
@albanD any idea?