I’m afraid it’s not possible. This notation with matrix multiply and 2D Jacobian works if you consider 1D inputs and 1D outputs.
AD only performs vector jacobian product. You need special function if you want to be able to do this.
If you are using the latest version of pytorch, you can find such function here 8.