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

Add support for multiple output functions to gradient.verify_grad #644

Open
jessegrabowski opened this issue Feb 12, 2024 · 1 comment
Open
Labels

Comments

@jessegrabowski
Copy link
Member

jessegrabowski commented Feb 12, 2024

Description

This is marked as a to-do in the code, along with a suggestion of how to handle it.

The whole function could probably be cleaned up while we're at it. It's not easy to read because it's doing so much all in a single function. It would be better to split up the construction of the tests from their execution. This would make extending to multiple outputs very straightforward -- just add one more outer loop.

I don't know how we feel about another dependency, but farming out the actual numerical gradients to a specialized package like numdifftools might be good too.

@ricardoV94
Copy link
Member

ricardoV94 commented Feb 14, 2024

Multiple outputs can be tested with this utility by using a callable instead of a single Op, as illustrated here: #614 (comment)

I think it's reasonable to fail, because Ops may have odd outputs that can't be safely combined by default (and OTOH testing each output separately may mask bugs when an Op has to mix gradients wrt to multiple outputs). Perhaps the error message should just nudge users to the possibility of testing Ops with a callable as in that example?

This is also useful for only testing gradients wrt to some inputs. For instance in the new pymc-example: pymc-devs/pymc-examples#631 we only implement grads wrt to some inputs and the utility would fail if you passed the Op and a pt for all inputs because it would test them all.

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

No branches or pull requests

2 participants