Skip to content

Commit

Permalink
Add pass descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhambhokare1 committed May 2, 2024
1 parent 1195701 commit 7443920
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/optimizer/optimize.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The `onnxscript.optimizer.optimize` call takes in several optional parameters th
```

## Description of pattern rewrite rules applied by `onnxscript.optimizer.optimize`
## List of pattern rewrite rules applied by `onnxscript.optimizer.optimize`

```{eval-rst}
.. autosummary::
Expand Down
5 changes: 4 additions & 1 deletion onnxscript/optimizer/constant_folding.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ def fold_constants(
*,
onnx_shape_inference: bool = False,
) -> bool:
"""Returns true iff the model was modified."""
"""
Applies constant folding optimization to the model.
Returns true iff the model was modified.
"""
folder = ConstantFolder(
evaluator.registry,
external_data_folder,
Expand Down
2 changes: 2 additions & 0 deletions onnxscript/optimizer/copy_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ def visit_node(self, node: onnx.NodeProto) -> None:


def do_copy_propagation(model: onnx.ModelProto, *, remove_unused: bool = True) -> None:
"""Applies copy propagation optimization to the model."""
transformer = CopyPropagator()
transformer.visit_model(model)
if remove_unused:
onnxscript.optimizer.remove_unused_nodes(model)


def do_sequence_simplification(model: onnx.ModelProto, *, remove_unused: bool = True) -> None:
"""Simplifies Sequence based ops (SequenceConstruct, ConcatFromSequence) present in the model."""
transformer = SymbolicEvaluator()
transformer.visit_model(model)
if remove_unused:
Expand Down
2 changes: 2 additions & 0 deletions onnxscript/optimizer/simple_function_folding.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def function_with_unused_outputs(self) -> dict[ir.FunctionId, onnx.FunctionProto


def inline_simple_functions(model: onnx.ModelProto, node_count: int = 2) -> bool:
"""Inlines simple functions based on a node count threshold"""
inliner = FunctionInliner(node_count)
inliner.visit_model(model)
logger.info(
Expand All @@ -218,6 +219,7 @@ def inline_simple_functions(model: onnx.ModelProto, node_count: int = 2) -> bool


def inline_functions_with_unused_outputs(model: onnx.ModelProto) -> bool:
"""Inlines function nodes that have unused outputs."""
# TODO: Use onnx.inliner after 1.16.
# This visitor based inliner is used to ensure the function inner value info remains consistent.
visitor = FindFunctionWithUnusedOutputsVisitor()
Expand Down

0 comments on commit 7443920

Please sign in to comment.