pymc-devs / pymc-devs/pytensor

Add option to disable OpFromGraph.L_Op/R_Op from being wrapped in their own OpFromGraph

Open
#1,174 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement gradients OpFromGraph
Dominant language
Python
Stars
644
Forks
208
Avg merge
2d 14h
Merged PRs (30d)
16

Description

The fact that we wrap a graph in OpFromGraph, doesn't mean we also want to wrap it's gradient. It can also lead to troubles as in https://github.com/pymc-devs/pymc/issues/7657

I suggest adding a wrap_grad_in_ofg: bool kwarg that toggles this behavior. The easiest way to get this change is to keep the behavior as is, but call the inline_ofg rewrite manually after calling it here:

https://github.com/pymc-devs/pytensor/blob/2f1d25a96e100380e87aebcf5f2ea7b678493ebd/pytensor/compile/builders.py#L612-L614

And here:
https://github.com/pymc-devs/pytensor/blob/2f1d25a96e100380e87aebcf5f2ea7b678493ebd/pytensor/compile/builders.py#L689

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pytensor/compile/builders.py at the referenced locations around lines 612-614 and 689. Read how OpFromGraph currently wraps gradients and inspect the inline_ofg rewrite mentioned in the issue. Done means adding the wrap_grad_in_ofg option and ensuring it controls whether L_Op/R_Op are wrapped in their own OpFromGraph.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.