Skip to content

Do not duplicate outer inputs when inlining OFG#2147

Merged
ricardoV94 merged 6 commits into
pymc-devs:mainfrom
ricardoV94:ofg_inline_duplication
May 20, 2026
Merged

Do not duplicate outer inputs when inlining OFG#2147
ricardoV94 merged 6 commits into
pymc-devs:mainfrom
ricardoV94:ofg_inline_duplication

Conversation

@ricardoV94
Copy link
Copy Markdown
Member

@ricardoV94 ricardoV94 commented May 19, 2026

Closes #2142

Address several points from #2033 (I've check marked them now)

This showed up in pymc-devs/pymc-extras#680 where we were duplicating Scans because of the bad (and useless) clone_replace when inlining OFGs

This was not a correctness issue (confirm by late regression test from #2143) but is wasteful / can blowup the graph for no reason.

@ricardoV94 ricardoV94 force-pushed the ofg_inline_duplication branch 2 times, most recently from 76c7738 to cd0b0a2 Compare May 19, 2026 17:40
@ricardoV94 ricardoV94 requested a review from jessegrabowski May 19, 2026 19:55
@ricardoV94 ricardoV94 marked this pull request as ready for review May 19, 2026 19:55
Comment thread pytensor/sparse/basic.py
"""Convert a dense matrix to a sparse matrix."""

__props__ = ()
__props__ = ("format",)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This showed up during node.op deduplication in rebuild_collect_shared. We were mixing distinct SparseFromDense

@ricardoV94 ricardoV94 force-pushed the ofg_inline_duplication branch from cd0b0a2 to 362404f Compare May 20, 2026 10:27
Copy link
Copy Markdown
Member

@jessegrabowski jessegrabowski left a comment

Choose a reason for hiding this comment

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

love it, big improvement from what we had. Looks like the only Op that's still doing the "dual graph" hack is scan?

@ricardoV94
Copy link
Copy Markdown
Member Author

I think OFG Scan and Minimize still on the list

@ricardoV94 ricardoV94 merged commit 6458acc into pymc-devs:main May 20, 2026
65 of 66 checks passed
@ricardoV94 ricardoV94 deleted the ofg_inline_duplication branch May 20, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inline_ofg_expansion clones upstream graph wastefully

2 participants