Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MarisaKirisame committed Sep 18, 2019
1 parent b54b798 commit 096a3ba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/tvm/relay/testing/py_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ def visit_global_var(self, gvar: Expr):
return (Name(gvar.name_hint, Load()), [])


def visit_fatal(self, fatal: Expr):
thunk_name = self.generate_function_name('_fatal_thunk')
thunk = self.create_def(thunk_name, [], [
ast.Raise(ast.Call(Name("Exception", Load()), [ast.Str(fatal.msg)], []), None)])
return (self.create_call(thunk_name, []), [thunk])


def visit_let(self, letexp: Expr):
# To properly account for scoping and ensure that the entire node produces an expression,
# we translate the let binding as a function that we call with the value we intend to bind.
Expand Down
1 change: 1 addition & 0 deletions tests/python/relay/test_backend_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,6 @@ def test_fatal():
f = exec.evaluate(relay.Fatal("msg", relay.TupleType([])))
f()


if __name__ == "__main__":
pytest.main([__file__])
6 changes: 6 additions & 0 deletions tests/python/relay/test_py_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
import numpy as np
import pytest
import tvm
from tvm import relay
from tvm.relay.testing import to_python, run_as_python
Expand Down Expand Up @@ -553,3 +554,8 @@ def reference(x, gamma, beta, moving_mean, moving_var):
verify_batch_norm([(20, 10), (10,), (10,), (10,), (10,)])
verify_batch_norm([(10, 50), (50,), (50,), (50,), (50,)])
verify_batch_norm([(30, 40), (40,), (40,), (40,), (40,)])


def test_fatal():
with pytest.raises(Exception, match="msg"):
run_as_python(relay.Fatal("msg", relay.TupleType([])))

0 comments on commit 096a3ba

Please sign in to comment.