You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/12/27 14:41:51 UTC
[GitHub] [tvm] leeexyz opened a new pull request #9807: [Target][BugFix] Convert dict and str to TVM object
leeexyz opened a new pull request #9807:
URL: https://github.com/apache/tvm/pull/9807
Hi All,
This PR tries to fix the Target constructing issue. I just found an error when invoking `relay.backend._backend.build` from the python side. After `build_target_by_device_type_map`, we got a dict target and it will be converted to Map when calling `relay.backend._backend.build`, because it is a global function. Then, the error occurred due to we cannot construct Target by type Map or String.
https://github.com/apache/tvm/blob/main/python/tvm/relay/build_module.py#L273-L280
Reproduce case
```python
import tvm
from tvm import relay
from tvm.relay.backend import graph_executor_codegen
def test_add():
def build_graph(mod, target):
target = tvm.relay.build_module.build_target_by_device_type_map(target)
target, target_host = tvm.target.Target.check_and_update_host_consist(target)
mod, _ = relay.optimize(mod, target, None)
grc = graph_executor_codegen.GraphExecutorCodegen(None, target)
graph_json, lowered_funcs, params = grc.codegen(mod, mod["main"])
built_mod = relay.backend._backend.build(lowered_funcs, target, target_host)
def add(shape, dtype):
A = relay.var("A", shape=shape, dtype=dtype)
B = relay.var("B", shape=shape, dtype=dtype)
C = relay.add(A, B)
expr = relay.Function((A, B), C)
mod = tvm.IRModule.from_expr(expr)
return mod
mod = build_graph(add((1, 8), "float32"), tvm.target.Target("llvm"))
test_add()
```
Trace log
```bash
Traceback (most recent call last):
File "test_build_graph.py", line 27, in <module>
test_add()
File "test_build_graph.py", line 24, in test_add
mod = build_graph(add((1, 8), "float32"), tvm.target.Target("llvm"))
File "test_build_graph.py", line 14, in build_graph
built_mod = relay.backend._backend.build(lowered_funcs, target, target_host)
File "/home/tuisku/project/apache/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
raise get_last_ffi_error()
ValueError: Traceback (most recent call last):
4: TVMFuncCall
at ../src/runtime/c_runtime_api.cc:475
3: tvm::runtime::PackedFunc::CallPacked(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) const
at ../include/tvm/runtime/packed_func.h:1151
2: std::function<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)>::operator()(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) const
at /usr/include/c++/7/bits/std_function.h:706
1: _M_invoke
at /usr/include/c++/7/bits/std_function.h:316
0: operator()
at ../src/runtime/c_runtime_api.cc:526
File "~/apache/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 81, in cfun
rv = local_pyfunc(*pyargs)
File "/home/tuisku/project/apache/tvm/python/tvm/relay/backend/_backend.py", line 44, in build
target, target_host = Target.check_and_update_host_consist(target, target_host)
File "/home/tuisku/project/apache/tvm/python/tvm/target/target.py", line 239, in check_and_update_host_consist
target = Target(target, host)
File "/home/tuisku/project/apache/tvm/python/tvm/target/target.py", line 111, in __init__
raise ValueError("target has to be a string or dictionary.")
ValueError: target has to be a string or dictionary.
```
I also found there are two container definitions `tvm.runtime.container` and `tvm.ir.container`. Can we merge them?
--
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.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] junrushao1994 merged pull request #9807: [Target][BugFix] Convert dict and str to TVM object
Posted by GitBox <gi...@apache.org>.
junrushao1994 merged pull request #9807:
URL: https://github.com/apache/tvm/pull/9807
--
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.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] junrushao1994 commented on pull request #9807: [Target][BugFix] Convert dict and str to TVM object
Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on pull request #9807:
URL: https://github.com/apache/tvm/pull/9807#issuecomment-1003450105
The existence of tvm.ir.container is just due to legacy reasons :-)
--
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.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] leeexyz commented on pull request #9807: [Target][BugFix] Convert dict and str to TVM object
Posted by GitBox <gi...@apache.org>.
leeexyz commented on pull request #9807:
URL: https://github.com/apache/tvm/pull/9807#issuecomment-1002097416
> Thanks for the fix. Could you add a test case?
@comaniac Cases have been added. By the way, what do you think about merging `tvm.runtime.container` and `tvm.ir.container`?
--
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.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org