You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+89Lines changed: 89 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,16 @@ models using a subset of Python. ONNX Script is:
15
15
***Debuggable:** allows for eager-mode evaluation that provides for a
16
16
more delightful ONNX model debugging experience.
17
17
18
+
This repo also covers:
19
+
20
+
***ONNX IR:** an in-memory IR that supports the full ONNX spec, designed
21
+
for graph construction, analysis and transformation.
22
+
***ONNX Script Optimizer:** provides functionality to optimize an ONNX
23
+
model by performing optimizations and clean-ups such as constant folding,
24
+
dead code elimination, etc.
25
+
***ONNX Rewriter:** provides functionality to replace certain patterns in
26
+
an ONNX graph with replacement patterns based on user-defined rewrite rules.
27
+
18
28
Note however that ONNX Script does **not** intend to support the entirety
19
29
of the Python language.
20
30
@@ -142,6 +152,85 @@ result = Hardmax(v)
142
152
143
153
More examples can be found in the [docs/examples](docs/examples) directory.
144
154
155
+
## ONNX IR
156
+
157
+
An in-memory IR that supports the full ONNX spec, designed for graph construction, analysis and transformation.
158
+
159
+
### Features
160
+
161
+
***Full ONNX spec support:** all valid models representable by ONNX protobuf,
162
+
and a subset of invalid models (so you can load and fix them).
163
+
***Low memory footprint:** mmap'ed external tensors; unified interface for
164
+
ONNX TensorProto, Numpy arrays and PyTorch Tensors etc. No tensor size
165
+
limitation. Zero copies.
166
+
***Straightforward access patterns:** Access value information and traverse the
167
+
graph topology at ease.
168
+
***Robust mutation:** Create as many iterators as you like on the graph while mutating it.
169
+
***Speed:** Performant graph manipulation, serialization/deserialization to Protobuf.
170
+
***Pythonic and familiar APIs:** Classes define Pythonic apis and still map to
171
+
ONNX protobuf concepts in an intuitive way.
172
+
173
+
## ONNX Script Tools
174
+
175
+
### ONNX Optimizer
176
+
177
+
The ONNX Script Optimizer tool provides the user with the functionality to optimize an ONNX model by performing optimizations and clean-ups such as constant folding, dead code elimination, etc. In order to utilize the optimizer tool:
178
+
179
+
```python
180
+
import onnxscript
181
+
182
+
onnxscript.optimizer.optimize(onnx_model)
183
+
```
184
+
185
+
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)
186
+
187
+
### ONNX Rewriter
188
+
189
+
The ONNX Rewriter tool provides the user with the functionality to replace certain patterns in an ONNX graph with another pattern based on user-defined rewrite rules. The rewriter tools allows two different methods in which patterns in the graph can be rewritten.
190
+
191
+
### Pattern-based rewriting
192
+
193
+
For this style of rewriting, the user provides a `target_pattern` that is to be replaced, a `replacement_pattern` and a `match_condition` (pattern rewrite will occur only if the match condition is satisfied). A simple example on how to use the pattern-based rewriting tool is as follows:
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)
229
+
230
+
### Function-based rewriting
231
+
232
+
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.
233
+
145
234
## Development Guidelines
146
235
147
236
Every change impacting the converter or the eager evaluation must be
0 commit comments