Skip to content

Fix fusion replacement ordering#2150

Open
ricardoV94 wants to merge 1 commit into
pymc-devs:mainfrom
ricardoV94:fusion_bug
Open

Fix fusion replacement ordering#2150
ricardoV94 wants to merge 1 commit into
pymc-devs:mainfrom
ricardoV94:fusion_bug

Conversation

@ricardoV94
Copy link
Copy Markdown
Member

@ricardoV94 ricardoV94 commented May 19, 2026

Apparently sequential toposort is not as trivial as I hoped for (even knowing there is some specialized literature out there on it). Should have LEAN-proofed my algorithm hehe

On the positive side I learned that to correctly replace in topological order in PyTensor it's enough to sort directly connected nodes, no need to perform an absolute toposort of all replaced nodes, because indirect nodes will hold the right replacements due to how inplace replacement works.

Closes #2145

@ricardoV94 ricardoV94 changed the title Fix Fusion replacement ordering Fix fusion replacement ordering May 20, 2026
@ricardoV94 ricardoV94 added bug Something isn't working graph rewriting labels May 20, 2026
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.

Is there anything in here that should be generalized to toposort in general, not just the elemwise fusion logic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working graph rewriting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: FusionOptimizer planner orders producer before consumer, KeyError in elemwise_to_scalar

2 participants