Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions onnxscript/utils/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

from typing import Sequence

import onnx
import onnx_ir as ir
import onnx_ir.passes.common as common_passes


def replace_functions(
model: onnx.ModelProto, functions: Sequence[onnx.FunctionProto]
) -> onnx.ModelProto:
def replace_functions(irmodel: ir.Model, irfunctions: Sequence[ir.Function]) -> None:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest two functions: create a new one replace_functions_inplace, which is like this one (with IR inputs updated in-place), and update the existing replace_functions to call the inplace one in the middle ... some might need one or the other

"""A utility function to replace custom operations in a model with their expansions:
Args:
model: An ONNX ModelProto possibly containing calls to custom operations.
Expand All @@ -20,8 +17,6 @@ def replace_functions(
Returns:
An updated ModelProto with custom operations replaced by their expansions.
"""
irmodel = ir.from_proto(model)
irfunctions = [ir.from_proto(func) for func in functions]
model_functions = irmodel.functions
if len(model_functions) != 0:
# Since we use inlining, check that there are no model-local functions.
Expand All @@ -32,4 +27,3 @@ def replace_functions(
# TODO (rama): Ideally, we should provide users more control over renaming strategy for inlined values.
common_passes.InlinePass()(irmodel)
common_passes.RemoveUnusedOpsetsPass()(irmodel)
return ir.to_proto(irmodel)
Loading