Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Jacobian which understands Params #414

Closed
wants to merge 1 commit into from

Conversation

mcabbott
Copy link
Member

@mcabbott mcabbott commented Dec 5, 2019

Closes #413, and #51, and half of #98.

Questions:

  • Should jacobian(f, ps::Params) return something other than an IdDict()?

  • Should matrix=true be the default? Needs to be added to Params method.

Needs tests obviously.

@Roger-luo
Copy link
Contributor

Roger-luo commented Dec 5, 2019

XRef: I implemented one in #235 as well but I didn't do anything on Params

@mcabbott
Copy link
Member Author

mcabbott commented Dec 5, 2019

Oh I completely missed that, sorry. Perhaps something to handle Params should just be bolted onto that.

@mcabbott mcabbott closed this Dec 7, 2019
@theogf
Copy link

theogf commented Dec 9, 2019

@mcabbott I am trying to use your solution until #235 is merged and has a Params option, but I am confused by what you refer to when using Zygote.forward, is it Zygote.forwarddiff?

@mcabbott
Copy link
Member Author

mcabbott commented Dec 9, 2019

Ah no, sorry, it's now called Zygote.pullback. The name changed in v0.4 I think.

@theogf
Copy link

theogf commented Dec 9, 2019

Thanks! It's working perfectly now!

@jessebett jessebett mentioned this pull request Dec 23, 2019
@mcabbott mcabbott mentioned this pull request Jan 27, 2021
bors bot added a commit that referenced this pull request Feb 2, 2021
890: Add `jacobian`, at last? r=CarloLucibello a=mcabbott

This adds a Jacobian function. 

Compared to #747 this one:
* has tests
* accepts multiple arguments
* shouldn't fail if `back` returns `nothing`
* inserts `vec` a few more places
* has a method which accepts implicit `Params`, and returns `Grads`. (This was the only part I actually needed in real life.)
* now works on the GPU too!

Compared to #414 this one:
* always inserts `vec`, never makes higher-dimensional arrays
* runs on current Zygote
* has tests.

Compared to #235 this one:
* doesn't try to provide numerical jacobian
* doesn't alter testing infrastructure
* doesn't provide `jacobian!`, nor any code for structured matrices.

This does not address #564's concerns about functions which return a tuple of arrays. Only functions returning an array (or a scalar) are permitted. Similar considerations might give sensible jacobians when the argument of a function is a tuple, or some other struct, but for now these are handled by putting up a giant warning sign.

Nothing in the file `utils.jl` seems to have any tests at all. So I also added tests for `hessian`. 

And, while I was there, made `hessian` actually accept a real number like its docstring promises. (Hence this closes #891.) And, made a version that is reverse-over-reverse, using this `jacobian`, which works less well of course but may as well exist to test things. (See for example #865.) Ideally there would be a pure-Zygote version using its own forward mode, but I didn't write that.

Fixes #51, fixes #98, fixes #413. Closes #747.

Co-authored-by: Michael Abbott <me@escbook>
Co-authored-by: Michael Abbott <32575566+mcabbott@users.noreply.github.com>
@mcabbott mcabbott deleted the jacobian branch July 6, 2022 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jacobian in Zygote with Params
3 participants