Solved by dpernes in post #8 
              
              
                That’s a bit tricky, I think. But it’s doable, of course. 
It is tricky because PyTorch only allows you to compute derivatives of scalars with respect to multidimensional Tensors. Thus, you have to iterate through every single scalar parameter in your model (i.e., every entry in every parameter matr…