Skip to content

Commit

Permalink
Fail early before running invalid dynamic graphs (apache#5856)
Browse files Browse the repository at this point in the history
* fail early before running invalid dynamic graphs

* fix an issue with the VM comment
  • Loading branch information
Matthew Brookhart authored and zhiics committed Jul 2, 2020
1 parent 2ebd336 commit a97c64f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/tvm/relay/backend/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 dynamic graphs on CPU, got output type",
ret_type, "on target", self.target)
return self.vm.run(*args)

return _vm_wrapper
3 changes: 3 additions & 0 deletions python/tvm/relay/build_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a97c64f

Please sign in to comment.