From 8e7c4e9f726e589612eb9baaa623f64eff5c92e8 Mon Sep 17 00:00:00 2001 From: Matthew Brookhart Date: Fri, 19 Jun 2020 13:51:02 -0700 Subject: [PATCH 1/2] fail early before running invalid dynamic graphs --- python/tvm/relay/backend/vm.py | 7 +++++++ python/tvm/relay/build_module.py | 3 +++ 2 files changed, 10 insertions(+) diff --git a/python/tvm/relay/backend/vm.py b/python/tvm/relay/backend/vm.py index 6929be0726f2..216bec56f55e 100644 --- a/python/tvm/relay/backend/vm.py +++ b/python/tvm/relay/backend/vm.py @@ -27,6 +27,7 @@ import tvm.runtime.vm as vm_rt from tvm import autotvm from tvm.relay import expr as _expr +from tvm.relay.ty import type_has_any from tvm.relay.backend.interpreter import Executor from . import _vm @@ -253,6 +254,12 @@ def _make_executor(self, expr=None): def _vm_wrapper(*args, **kwargs): args = self._convert_args(main, args, kwargs) + ret_type = self.mod["main"].checked_type.ret_type + if type_has_any(ret_type) and "llvm" not in str(self.target) and "arm" not in str( + self.target): + raise ValueError( + "Virtual Machine only supports static graphs on CPU, got output type", + ret_type, "on target", self.target) return self.vm.run(*args) return _vm_wrapper diff --git a/python/tvm/relay/build_module.py b/python/tvm/relay/build_module.py index 30c5971e32b9..a28ab853dd9d 100644 --- a/python/tvm/relay/build_module.py +++ b/python/tvm/relay/build_module.py @@ -354,6 +354,9 @@ def _make_executor(self, expr=None): if expr: self.mod["main"] = expr ret_type = self.mod["main"].checked_type.ret_type + if _ty.type_has_any(ret_type): + raise ValueError("Graph Runtime only supports static graphs, got output type", + ret_type) num_outputs = len(ret_type.fields) if isinstance(ret_type, _ty.TupleType) else 1 graph_json, mod, params = build(self.mod, target=self.target) gmodule = _graph_rt.create(graph_json, mod, self.ctx) From c968827588057dd4a30bd485f409134ccfb67d67 Mon Sep 17 00:00:00 2001 From: Matthew Brookhart Date: Sat, 20 Jun 2020 19:57:05 -0700 Subject: [PATCH 2/2] fix an issue with the VM comment --- python/tvm/relay/backend/vm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tvm/relay/backend/vm.py b/python/tvm/relay/backend/vm.py index 216bec56f55e..e470540dceda 100644 --- a/python/tvm/relay/backend/vm.py +++ b/python/tvm/relay/backend/vm.py @@ -258,7 +258,7 @@ def _vm_wrapper(*args, **kwargs): if type_has_any(ret_type) and "llvm" not in str(self.target) and "arm" not in str( self.target): raise ValueError( - "Virtual Machine only supports static graphs on CPU, got output type", + "Virtual Machine only supports dynamic graphs on CPU, got output type", ret_type, "on target", self.target) return self.vm.run(*args)