-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[optimizer][docs] Add Tutorial for Optimizer API (#1482)
Add Tutorial for Optimizer API
- Loading branch information
1 parent
a722e60
commit 7e9c9e6
Showing
10 changed files
with
77 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Optimizer Tutorials | ||
|
||
```{toctree} | ||
optimize | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Optimizing a Model using the Optimizer | ||
|
||
## Introduction | ||
|
||
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. | ||
|
||
## Usage | ||
|
||
In order to utilize the optimizer tool, | ||
|
||
```python | ||
import onnxscript | ||
|
||
onnxscript.optimizer.optimize(model) | ||
``` | ||
|
||
### optimize API | ||
The `onnxscript.optimizer.optimize` call takes in several optional parameters that allows the caller to further fine-tune the process of optimization. | ||
|
||
```{eval-rst} | ||
.. autofunction:: onnxscript.optimizer.optimize | ||
:noindex: | ||
``` | ||
|
||
## Description of optimizations applied by `onnxscript.optimizer.optimize` | ||
|
||
:::{table} | ||
:widths: auto | ||
:align: center | ||
|
||
| Optimization 'onnxscript.optimizer.` + .. | Description | | ||
| - | - | | ||
| **Constant folding** <br>`constant_folding.fold_constants` | Applies constant folding optimization to the model. | | ||
| **Constant propagation** <br>`constant_folding.fold_constants` | Applies constant propagation optimization to the model. Applied as part of the constant folding optimization. | | ||
| **Sequence simplification** <br>`constant_folding.fold_constants` | Simplifies Sequence based ops (SequenceConstruct, ConcatFromSequence) present in the model. Applied as part of the constant folding optimization. | | ||
| **Remove unused nodes** <br>`remove_unused.remove_unused_nodes` | Removes unused nodes from the model. | | ||
| **Remove unused functions** <br>`remove_unused_function.remove_unused_functions` | Removes unused function protos from the model. | | ||
| **Inline functions with unused outputs** <br>`simple_function_folding.inline_functions_with_unused_outputs` | Inlines function nodes that have unused outputs. | | ||
| **Inline simple functions** <br>`simple_function_folding.inline_simple_functions` | Inlines simple functions based on a node count threshold. | | ||
::: | ||
|
||
## List of pattern rewrite rules applied by `onnxscript.optimizer.optimize` | ||
|
||
```{eval-rst} | ||
.. autosummary:: | ||
:nosignatures: | ||
onnxscript.rewriter.broadcast_to_matmul | ||
onnxscript.rewriter.cast_constant_of_shape | ||
onnxscript.rewriter.gemm_to_matmul_add | ||
onnxscript.rewriter.no_op | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters