How to define a model as a function of its parameters and get its Jacobian?

Given a model (inherited from nn.Module), calculate Jacobian of parameters of this model with respect to output vector.
This looks like a hack to do this,