zackcquic commented on a change in pull request #7952:
URL: https://github.com/apache/tvm/pull/7952#discussion_r639407100
##########
File path: tests/python/relay/test_pass_instrument.py
##########
@@ -168,3 +169,329 @@ def run_after_pass(self, mod, info):
# Out of pass context scope, should be reset
assert passes_counter.run_before_count == 0
assert passes_counter.run_after_count == 0
+
+
+def test_enter_pass_ctx_exception(capsys):
+ @pass_instrument
+ class PI:
+ def __init__(self, id):
+ self.id = id
+
+ def enter_pass_ctx(self):
+ print(self.id + " enter ctx")
+
+ def exit_pass_ctx(self):
+ print(self.id + " exit ctx")
+
+ @pass_instrument
+ class PIBroken(PI):
+ def __init__(self, id):
+ super().__init__(id)
+
+ def enter_pass_ctx(self):
+ print(self.id + " enter ctx")
+ raise RuntimeError("Just a dummy error")
+
+ pass_ctx = tvm.transform.PassContext(instruments=[PI("%1"),
PIBroken("%2"), PI("%3")])
+ with pytest.raises(tvm.error.TVMError):
+ with pass_ctx:
+ pass
+
+ assert "%1 enter ctx\n" "%2 enter ctx\n" == capsys.readouterr().out
Review comment:
I considered to catch all the exceptions in
`InstrumentEnterPassContext` before:
if there is exception, disabling instruments within this context, and
**NO** throw out to higher level.
But I finally throw it out, since I'd like to see the errors, and don't want
to proceed with unstable states.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]