Equivalence Pattern Rewriter to integrate expansion of Softmax into equality saturation#5655
Equivalence Pattern Rewriter to integrate expansion of Softmax into equality saturation#5655szerdick wants to merge 73 commits intoxdslproject:jumerckx/interp_ematchfrom
Conversation
With the foreach approach, I believe part of this logic can be simplified/omitted, but this is a good first step.
We need to be more careful with the bindings selected by matchers. Right now, values are sometimes passed as their class result to a rewriter: ``` x = … y = … c = class x, y rewrite “myrewrite”(c) ``` This is problematic in MLIR as other rewrites can invalidate c. While we are guaranteed to not erase any operation in the “program domain”, this is not true for the operations of the “e-graph domain”. The solution is to ensure in the pdl lowering that only values from the program domain are passed to rewriters and the conversion to e-graph domain happens at the latest possible point, in the rewriter itself. (This is not an issue in xDSL because erasing an e-class does not discard of the object)
non-eqsat lowering should stay the same
(not entirely done) Co-authored-by: Sasha Lopoukhine <superlopuh@gmail.com>
to show how it should be done, the change would also need to be made to apply_eqsat_pdl.
repair detects when two parent operations have become equal due to their children having been merged. At this point, there are two identical operations, but the hashcons (`known_ops`) only tracks one: there is a collision. One of the two operations is replaced by the other. If the hashcons happened to store the operation that was replaced, instead of the (identical) replacement, the hashcons is corrupt. This is fixed by explicitly updating the hashcons to point to the operation that is not replaced.
often it doesn't seem to do anything on top of the sorted list, but better safe than sorry?
498cd20 to
57886d2
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## jumerckx/interp_ematch #5655 +/- ##
=========================================================
Coverage ? 85.55%
=========================================================
Files ? 408
Lines ? 57585
Branches ? 6721
=========================================================
Hits ? 49264
Misses ? 6743
Partials ? 1578 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| _worklist: Worklist = field(default_factory=Worklist, init=False) | ||
| """The worklist of operations to walk over.""" | ||
|
|
||
| rewriter_factory: type[PatternRewriter] = PatternRewriter |
There was a problem hiding this comment.
| rewriter_factory: type[PatternRewriter] = PatternRewriter | |
| rewriter_factory: type[PatternRewriter] = PatternRewriter | |
| """Factory method that takes an operation and returns a PatternRewriter""" |
|
This looks mostly correct to me. Would be good to have some tests to see if things actually work.
I think the first two can be tackled separately. But you could already write tests that verify that things are broken and we can mark these as expectedly failing. For now adding tests seems most useful, we can talk about cleaning up afterwards. |
… interp_ematch # Conflicts: # tests/filecheck/transforms/ematch-saturate/binom_prod.mlir # xdsl/dialects/equivalence.py # xdsl/interpreters/ematch.py # xdsl/pattern_rewriter.py
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
to show how it should be done, the change would also need to be made to apply_eqsat_pdl.
repair detects when two parent operations have become equal due to their children having been merged. At this point, there are two identical operations, but the hashcons (`known_ops`) only tracks one: there is a collision. One of the two operations is replaced by the other. If the hashcons happened to store the operation that was replaced, instead of the (identical) replacement, the hashcons is corrupt. This is fixed by explicitly updating the hashcons to point to the operation that is not replaced.
42006ed to
e64571a
Compare
e64571a to
ba97362
Compare
No description provided.