Fail early before running invalid dynamic graphs (#5856)
authorMatthew Brookhart <mbrookhart@octoml.ai>
Mon, 22 Jun 2020 05:55:16 +0000 (22:55 -0700)
committerGitHub <noreply@github.com>
Mon, 22 Jun 2020 05:55:16 +0000 (22:55 -0700)
* fail early before running invalid dynamic graphs

* fix an issue with the VM comment

python/tvm/relay/backend/vm.py
python/tvm/relay/build_module.py

index 6929be0..e470540 100644 (file)
@@ -27,6 +27,7 @@ import tvm.runtime.ndarray as _nd
 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 @@ class VMExecutor(Executor):
 
         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 dynamic graphs on CPU, got output type",
+                    ret_type, "on target", self.target)
             return self.vm.run(*args)
 
         return _vm_wrapper
index 30c5971..a28ab85 100644 (file)
@@ -354,6 +354,9 @@ class GraphExecutor(_interpreter.Executor):
         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)