Skip to content

Commit 31af28f

Browse files
authored
[pass] Create check to ensure in-place passes are actually inplace (#2192)
This pull request introduces validation to ensure the in-place property of a pass is respected. Validation of in-place property: * [`onnxscript/ir/passes/_pass_infra.py`](diffhunk://#diff-70c7e5b3422f4daaf1611d4f76578c96e4c5894cced3d51718efa0290219f7f5R139-R152): Added checks to ensure that if a pass is declared in-place, the returned model must be the same object as the input model, and if not in-place, the returned model must be a different object. Raises `PassError` if these conditions are not met.
1 parent 2e89a2c commit 31af28f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

onnxscript/ir/passes/_pass_infra.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ def __call__(self, model: ir.Model) -> PassResult:
136136
f"The result of the pass '{self.__class__.__name__}' should be type PassResult. "
137137
"Please create one with ir.passes.PassResult()."
138138
)
139+
140+
# Checks that the declared in-place property is respected
141+
if self.in_place and result.model is not model:
142+
raise PassError(
143+
f"The pass '{self.__class__.__name__}' is declared in-place, "
144+
"but the model returned is *not* the same object as the input model. "
145+
"Pass developer: Pass should return the same model object or the in_place property should return False."
146+
)
147+
if not self.in_place and result.model is model:
148+
raise PassError(
149+
f"The pass '{self.__class__.__name__}' is declared not in-place, "
150+
"but the model returned *is* the same object as the input model. "
151+
"Pass developer: Pass should return a new model object or the in_place property should return True."
152+
)
139153
return result
140154

141155
@abc.abstractmethod

0 commit comments

Comments
 (0)