Skip to content

Updated docs for rewrite-patterns #2196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/tutorial/rewriter/rewrite_patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@
:pyobject: erf_gelu_pattern_2
```

:::{note}
:name: rule-application-order-matters

### Order of Rewrite Rules Matters

When you pass multiple rules in `pattern_rewrite_rules`, the **order in which they appear is important**.

This is because some rules may depend on patterns created or modified by earlier rules. For example, if `rule1` can only match after `rule2` has made a specific change in the model, then `rule2` must come **before** `rule1` in the list.

If you're not seeing expected results, try adjusting the order or applying the rule set in a loop until no more changes occur.

:::


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.

```{literalinclude} examples/erfgelu.py
Expand Down
Loading