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 rough version of an autodiff refactor #788

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aseyboldt
Copy link
Member

Completely redo the implementation of the Rop/Lop/grad functions and replace them by pull_back, push_forward. grad can just call pull_back then. They are currently not really working, but only a sketch of how they could look like.

Add new alternative methods pull_back and push_forward and linear_transpose to Op. In the long-term they should replace the grad, Rop and Lop methods, and give more control and context to the Op when implementing those operations.

Invesigate a bit more how we can derive Rop from Lop and the other way round. We can go both ways: Given an implementation of push_forward we can use the fact that the mapping between the tangents is linear, and if all involved linear ops implement linear_transpose, we can use that to derive pull_back. Given pull_back we can use the fact that pull_back is a push_forward and transpose. And since the push_forward of a linear function is itself, we can apply it twice to effectively remove the transpose. (see pull_back_through_transpose and push_forward_through_pull_back).

We can possibly provide hints to the graph optimizer that the values can sometimes be computed in a smarter way if we also want gradients. Ricardo convinced me that we probably don't want to produce new output values in the push_forward and pull_back functions, but maybe if the gradients are computed lazily we could collect those possible
rewrites and apply them during the rewrite that computes the gradients?

Hopefully delete 2000 lines of complicated gradient code once the new stuff is working well.

cc @ricardoV94

from pytensor.tensor.basic import zeros_like

tangents_filled = [
# TODO do the R_op methods also accept a disconnected_grad?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but we should

@ricardoV94
Copy link
Member

@aseyboldt let's try to replace the L_op / R_op to see what needs to be added. I would also like a non-trivial example of "alternative outputs" to test ways we can achieve that.

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

Successfully merging this pull request may close these issues.

2 participants