If you’re computing a determinant, shouldn’t the output be of a different size? If so the backward sizes will also be different.
The extra Tensor from your custom function is because torchviz is able to see what you saved for backward while it cannot see it for the builtin functions (implemented in c++). So that’s not surprising to me.
Also you can try to set TORCH_SHOW_CPP_STACKTRACES=1 to get more information about where the error hapens in the backward pass.