How to efficiently compute the jacobian matrix of a model with respect to it's parameters #8538
Unanswered
VirgileUniv
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone.
I'm trying to implement Neural Galerkin scheme in taichi (https://arxiv.org/pdf/2203.01360).
Hence my goal is to compute (efficiently) the Jacobian matrix of a model with respect to it's parameters.
Let's take the simple example of a single (unbiased) linear unit with$1$ input and $n$ output. If we denote the model as a function $U$ of it's parameters $w_0,...,w_n$ and input $x$ , we have $U(w_0,...,w_n, x) = (w_0 \times x,...,w_n \times x)$ . Hence the jacobian will be :
My solution for the moment is to set i-th component of the
output.grad
to 1, the rest to 0 and hence retrieve the i-th line of the jacobian matrix inweight.grad
after runninglinear.grad()
(where linear is the kernel computing the linear unit). I'll put the code down bellow.However this seems pretty unefficient to me, and i wonder if there isn't a way to do it much faster. Indeed even though i have no idea on how does
kernel.grad
works internally, i'm pretty confident that it does compute the jacobian matrix at some point, before doing a vector-matrix mutiplication (with theoutput.grad
most certainly). If I'm not mistaken on that point, i'll just need to retrieve that matrix before the vector multiplication, but I have no idea on how to do it (or even certain that i'm not mistaken on that point).If anyone can help me on that, or just have some info on the interal of
kernel.grad
it would be much appreciated.Here is the code on the example of a (unbiased) linear unit :
Beta Was this translation helpful? Give feedback.
All reactions