Skip to content

Commit ea8cb3e

Browse files
authored
Add option to clear metadata in ort fusion (#2685)
Add option to clear metadata in ort fusion. Otherwise, we lose all metadata after running ORT fusion --------- Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
1 parent 478acf7 commit ea8cb3e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

onnxscript/rewriter/ort_fusions/_core.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def optimize_for_ort(
115115
config_name: str | None = None,
116116
*,
117117
debug: bool = False,
118+
clear_metadata: bool = False,
118119
) -> tuple[ir.Model, dict[str, int]]:
119120
"""
120121
Optimize the model for ORT backend.
@@ -128,6 +129,7 @@ def optimize_for_ort(
128129
Typically it identifies the Execution Provider (EP) to optimize for.
129130
If None, the default configuration will be used.
130131
debug: If debug is True, enable pattern matching tracer for debugging.
132+
clear_metadata: If True, clear metadata and doc strings from the model.
131133
132134
Returns:
133135
A tuple containing:
@@ -145,7 +147,6 @@ def optimize_for_ort(
145147
passes = ir.passes.Sequential(
146148
# Apply the ORT optimization passes.
147149
# https://github.com/microsoft/onnxruntime/blob/74dcf7e296639095dfa55d31336998b6f719ed76/onnxruntime/python/tools/transformers/dynamo_onnx_helper.py#L172
148-
common_passes.ClearMetadataAndDocStringPass(),
149150
# https://github.com/microsoft/onnxruntime/blob/74dcf7e296639095dfa55d31336998b6f719ed76/onnxruntime/python/tools/transformers/dynamo_onnx_helper.py#L139
150151
common_passes.LiftConstantsToInitializersPass(lift_all_constants=False, size_limit=1),
151152
common_passes.RemoveInitializersFromInputsPass(),
@@ -154,4 +155,8 @@ def optimize_for_ort(
154155
assert passes.in_place
155156
result = passes(model)
156157
assert result.model is model
158+
159+
if clear_metadata:
160+
common_passes.ClearMetadataAndDocStringPass()(model)
161+
157162
return model, fusion_count

0 commit comments

Comments
 (0)