-
Notifications
You must be signed in to change notification settings - Fork 71
Extend optimize_for_ort to cover passes #2274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
322851a
0226ed7
42ecb33
aa1e4a3
fd1a225
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -3,7 +3,7 @@ | |||||||
from __future__ import annotations | ||||||||
|
||||||||
import onnxscript.ir as ir | ||||||||
from onnxscript.ir.passes.common import shape_inference | ||||||||
import onnxscript.ir.passes.common as common_passes | ||||||||
from onnxscript.optimizer import optimize | ||||||||
from onnxscript.rewriter import rewrite | ||||||||
from onnxscript.rewriter.ort_fusions import ( | ||||||||
|
@@ -48,7 +48,7 @@ | |||||||
# TODO: Do we need this dependence on ONNX's partial-data-propagation? There are some | ||||||||
# extra shape-propagation and partial-data-propagation rules in ONNX that are not yet | ||||||||
# incorporated in our optimizer. | ||||||||
shape_inference.infer_shapes(model) | ||||||||
common_passes.ShapeInferencePass()(model) | ||||||||
optimize(model) | ||||||||
return model | ||||||||
|
||||||||
|
@@ -135,4 +135,18 @@ | |||||||
) | ||||||||
# Apply the ORT pattern rewrite rules. | ||||||||
rewrite(model, ORT_PATTERN_REWRITE_RULES) | ||||||||
return model, fusion_count | ||||||||
|
||||||||
passes = [ | ||||||||
# TODO(exporter team): Fold transpose into initializers | ||||||||
# Apply the ORT optimization passes. | ||||||||
# https://github.com/microsoft/onnxruntime/blob/74dcf7e296639095dfa55d31336998b6f719ed76/onnxruntime/python/tools/transformers/dynamo_onnx_helper.py#L172 | ||||||||
common_passes.ClearMetadataAndDocStringPass(), | ||||||||
# https://github.com/microsoft/onnxruntime/blob/74dcf7e296639095dfa55d31336998b6f719ed76/onnxruntime/python/tools/transformers/dynamo_onnx_helper.py#L139 | ||||||||
common_passes.LiftConstantsToInitializersPass(lift_all_constants=False, size_limit=1), | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have another pass called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the pass logic is in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't really produce graphs with subgraph initializers. I think we are ok either way |
||||||||
common_passes.RemoveInitializersFromInputsPass(), | ||||||||
common_passes.ShapeInferencePass(), | ||||||||
common_passes.CheckerPass(), | ||||||||
] | ||||||||
optimize_for_ort_passes = ir.passes.Sequential(*passes) | ||||||||
Comment on lines
+149
to
+150
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
result = optimize_for_ort_passes(model) | ||||||||
return result.model, fusion_count | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.