Skip to content
This repository has been archived by the owner on Oct 15, 2019. It is now read-only.

gradient for list of variables #133

Open
YingzhenLi opened this issue Jan 21, 2017 · 1 comment
Open

gradient for list of variables #133

YingzhenLi opened this issue Jan 21, 2017 · 1 comment

Comments

@YingzhenLi
Copy link

Is that possible to get gradient for a list of variables? e.g. instead of using
loss_func(w, b, x, y) then gradient = grad(loss_func, [0, 1]),
it might be preferred to use params = [w, b]
loss_func(params, x, y) then gradient = grad(loss_func, [0]).

I ask this because my task is to do MCMC on neural network weights. In the first case I need to specifically define loss_func() with lots of arguments.

As a reference, tensorflow support this simply by tf.gradients(loss, [w1, b1, w2, b2, ...]), and my understanding of pyTorch (which also uses autograd) seems to be that they also support this functionality.

I know in the original autograd package this is solved by lumping all the parameters into a big vector, then partitioning it into weight matrices and bias vectors. This doesn't sound a good solution, especially when using GPU (the original package has no GPU support).

@jermainewang
Copy link
Member

This could be solved by adding a special ParamTuple structure. Let me see if I could quickly implement that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants