Skip to content

Commit af452c7

Browse files
authored
docs: cleanup documentation for function-based rewrites📄 (#2359)
With https://github.com/microsoft/onnxscript/pull/2039/files support for `function-based` rewriting was dropped. Some tutorials and the the readme were still referencing function-based rewrites. @justinchuby / @gramalingam Could you please review? Any feedback is appreciated.
1 parent 1df9290 commit af452c7

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ import onnxscript
162162
onnxscript.optimizer.optimize(onnx_model)
163163
```
164164

165-
For a detailed summary of all the optimizations applied by the optimizer call, refer to the tutorial [Optimizing a Model using the Optimizer](https://onnxscript.ai/tutorial/optimizer/optimize.html)
165+
For a detailed summary of all the optimizations applied by the optimizer call, refer to the tutorial [Optimizing a Model using the Optimizer](https://microsoft.github.io/onnxscript/tutorial/optimizer/optimize.html)
166166

167167
### ONNX Rewriter
168168

@@ -205,11 +205,7 @@ model_with_rewrite_applied = onnxscript.rewriter.rewrite(
205205
return model_with_rewrite_applied
206206
```
207207

208-
For a detailed tutorial on how to create target_pattern, replacement_pattern and match_condition blocks in order to utilize the pattern-based rewriter, refer to the tutorial [Pattern-based Rewrite Using Rules](https://onnxscript.ai/tutorial/rewriter/rewrite_patterns.html)
209-
210-
### Function-based rewriting
211-
212-
This style of rewriting matches a `FUNCTION_KEYWORD` and `PACKAGE_NAME` provided by the user to an existing function within the graph and replaces it with a new function provided by the user.
208+
For a detailed tutorial on how to create target_pattern, replacement_pattern and match_condition blocks in order to utilize the pattern-based rewriter, refer to the tutorial [Pattern-based Rewrite Using Rules](https://microsoft.github.io/onnxscript/tutorial/rewriter/rewrite_patterns.html)
213209

214210
## Development Guidelines
215211

docs/tutorial/rewriter/simple_example.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ rule = pattern.RewriteRule(
4949
Now that the rewrite rule has been created, the next step is to apply these pattern-based rewrite rules. The `rewriter.rewrite` call consists of three main components:
5050

5151
1. `model` : The original model on which the pattern rewrite rules are to be applied. This is of type `onnx.ModelProto`.
52-
2. `function_rewrite_rules` : `(Optional)` This parameter is used to pass rewrite rules based on function names. Steps on how to use this parameter will be covered in a different tutorial. This parameter is of type `Sequence[type[FunctionRewriteRule]]`
53-
3. `pattern_rewrite_rules` : `(Optional)` This parameter is used to pass rewrite rules based on a provided replacement pattern. For the purpose of this tutorial, we will be using only this parameter in conjunction with `model`. This parameter is of either one of these types:
52+
53+
2. `pattern_rewrite_rules` : `(Optional)` This parameter is used to pass rewrite rules based on a provided replacement pattern. This parameter is of either one of these types:
5454
- `Sequence[PatternRewriteRule]`
5555
- `RewriteRuleSet`
5656

onnxscript/rewriter/onnxruntime/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from __future__ import annotations
77

8-
from typing import Any
8+
from typing import Any, Sequence
99

1010
import onnx
1111

@@ -25,15 +25,12 @@
2525
def rewrite(
2626
model_proto: onnx.ModelProto,
2727
/,
28-
function_rules=None,
29-
pattern_rules: list[pattern.RewriteRule] | None = None,
28+
pattern_rules: Sequence[pattern.RewriteRule] | None = None,
3029
) -> onnx.ModelProto:
3130
"""Rewrite the model using the given rules.
3231
3332
Args:
3433
model_proto: The model to rewrite.
35-
function_rules: The function rewrite rules to apply. If None, the default rules
36-
for onnxruntime are used.
3734
pattern_rules: The pattern rewrite rules to apply. If None, the default rules
3835
for onnxruntime are used.
3936

tools/ort_rewriter_profiling/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,13 @@
127127
5. Develop optimization code.
128128
- `onnx-script/onnxscript/optimizer`: Optimizations such as constant folding, inlining, dead code elimination etc.
129129
- `onnx-script/onnxscript/rewriter`: Pattern based fusions.
130-
- `onnx-script/onnxscript/rewriter/onnxruntime`: Onnxruntime specific pattern based fusions.
131-
- `onnx-script/onnxscript/rewriter/onnxruntime/transformers`: Onnxruntime specific function based fusions.
130+
- `onnx-script/onnxscript/rewriter/ort_fusions`: Onnxruntime specific pattern based fusions.
132131
- Use function unittest producer tool to create function fusion unittest. Example command to distill 4 unittests for function `LlamaSdpaAttention` from `llama_v2_7b` `dynamo` model. The unittest models are named with prefix `sdpa_llama2`:
133132
```
134-
# Under onnx-script/onnxscript/rewriter/transformers
135-
CUDA_VISIBLE_DEVICES="3" python tools/function_unittest_producer.py --model-path ../../../tools/onnx_models/llama_v2_7b_16h/dynamo_ort_rewritten/llama_v2_7b_16h_dynamo_ort_rewritten.onnx --function LlamaSdpaAttention --output-dir ../../testing/rewriter/transformers/unittest_models/ --max-outputs 4 --name sdpa_llama2
133+
# Under onnx-script/onnxscript/rewriter
134+
CUDA_VISIBLE_DEVICES="3" python tools/function_unittest_producer.py --model-path ../../../tools/onnx_models/llama_v2_7b_16h/dynamo_ort_rewritten/llama_v2_7b_16h_dynamo_ort_rewritten.onnx --function LlamaSdpaAttention --output-dir ../../testing/rewriter/unittest_models/ --max-outputs 4 --name sdpa_llama2
136135
```
137-
- Create new testcase under `onnx-script/onnxscript/rewriter/transformers` with the generated unittest models.
136+
- Create new testcase under `onnx-script/onnxscript/rewriter/ort_fusions` with the generated unittest models.
138137
```python
139138
def test_sdpa_llama2(self):
140139
common.test_function_rewrite("sdpa_llama2", 4)

0 commit comments

Comments
 (0)