This error is raised, if an operation cannot be applied to tensors having a different shape.
In this case dim2 seems to be different, so you would need to check the shape of both tensors and make sure they are in the expected shape (depends on the operation).
Feel free to add more information to this thread in case you get stuck.