Skip to content

Commit

Permalink
add optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
titaiwangms committed Jan 8, 2025
1 parent f372b89 commit ca557af
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions olive/passes/onnx/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ def _default_config(cls, accelerator_spec: AcceleratorSpec) -> Dict[str, PassCon
"dynamic": PassConfigParam(
type_=bool, default_value=True, description=("Whether to export the model with dynamic axes/shapes.")
),
"optimization": PassConfigParam(
type_=bool,
default_value=True,
description=(
"Whether to optimize the model with constant folding and "
"elimination of redundant operators after conversion."
),
),
}

def _run_for_config(
Expand Down Expand Up @@ -266,6 +274,8 @@ def _export_pytorch_model(
report=logger.isEnabledFor(logging.DEBUG),
)
assert onnx_program is not None
if config["optimization"]:
onnx_program.optimize()
onnx_model = onnx_program.model_proto
else:
# there might be multiple files created during export, so we need to track the dir
Expand Down

0 comments on commit ca557af

Please sign in to comment.