Skip to content

Commit cebb0f1

Browse files
committed
docs: cleanup documentation for function-based rewriting
1 parent 4e526f7 commit cebb0f1

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ return model_with_rewrite_applied
207207

208208
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)
209209

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.
213-
214210
## Development Guidelines
215211

216212
Every change impacting the converter or the eager evaluation must be

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: 3 additions & 4 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

@@ -26,14 +26,13 @@ def rewrite(
2626
model_proto: onnx.ModelProto,
2727
/,
2828
function_rules=None,
29-
pattern_rules: list[pattern.RewriteRule] | None = None,
29+
pattern_rules: Sequence[pattern.RewriteRule] | None = None,
3030
) -> onnx.ModelProto:
3131
"""Rewrite the model using the given rules.
3232
3333
Args:
3434
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.
35+
function_rules: The function rewrite rules to apply. Deprecated.
3736
pattern_rules: The pattern rewrite rules to apply. If None, the default rules
3837
for onnxruntime are used.
3938

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)