Thanks for the code.
Given that the error is a mismatch between at dimension 2 where one is 25 and the other is 4. I guess one is batch size and the other N.
I think you can try and add a bunch of print for the sizes of the Tensors in this block: CustomDeterminant/pytorch_custom_determinant_example.py at d1926d4572d0ddcfb0b1b915c2000b9a393652c6 · AlphaBetaGamma96/CustomDeterminant · GitHub
To make sure they have the size you expect. And in particular, the inputs for each multiplication op.