Skip to content

Commit e404922

Browse files
authored
Updated docs for rewrite-patterns (#2196)
Description Added a note to the rewrite patterns tutorial clarifying that the order of rules in `pattern_rewrite_rules` matters. Some rules depend on others being applied first, so incorrect order may lead to unexpected results. Fixes #2169
1 parent 8c0c906 commit e404922

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

docs/tutorial/rewriter/rewrite_patterns.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ In order to apply this method to the example above, first create the two separat
152152
:pyobject: erf_gelu_pattern_2
153153
```
154154

155+
:::{note}
156+
:name: rule-application-order-matters
157+
158+
When you pass multiple rules in `pattern_rewrite_rules`, the **order in which they appear is important**.
159+
This is because some rules may depend on patterns created or modified by earlier rules. For example, if `rule2` can only match after `rule1` has made a specific change in the model, then `rule1` must come **before** `rule2` in the list.
160+
If you're not seeing expected results, try adjusting the order or applying the rule set in a loop until no more changes occur.
161+
:::
162+
163+
155164
Then, create two separate `PatternRewriteRule`s, one for each target pattern. Pack these rules into a `RewriteRuleSet` object and apply rewrites by passing the created `RewriteRuleSet` for the `pattern_rewrite_rules` parameter.
156165

157166
```{literalinclude} examples/erfgelu.py

0 commit comments

Comments
 (0)