This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch unity
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/unity by this push:
new bcad5a9abe [Unity][VM] LibComparator using dtype from input (#14623)
bcad5a9abe is described below
commit bcad5a9abe789d40ddcd4c8b434600726c2d4a00
Author: Ruihang Lai <[email protected]>
AuthorDate: Fri Apr 14 07:51:01 2023 -0400
[Unity][VM] LibComparator using dtype from input (#14623)
Previously the LibComparator omitted the dtype argument when creating
a NDArray, which leads to the dtype always float32. This PR fixes this
behavior.
---
python/tvm/relax/testing/lib_comparator.py | 2 +-
tests/python/relax/test_vm_instrument.py | 19 +++++++++++++++++--
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/python/tvm/relax/testing/lib_comparator.py
b/python/tvm/relax/testing/lib_comparator.py
index a9cecc69dc..af21ef7a7c 100644
--- a/python/tvm/relax/testing/lib_comparator.py
+++ b/python/tvm/relax/testing/lib_comparator.py
@@ -119,7 +119,7 @@ class LibCompareVMInstrument:
# not always true, true for most ops.
ret_indices = (len(args) - 1,)
for i, arg in enumerate(args):
- arr = tvm.nd.empty(arg.shape, device=self.device)
+ arr = tvm.nd.empty(arg.shape, arg.dtype, device=self.device)
# copy from cpu since we look at different device
if i not in ret_indices:
arr.copyfrom(arg.copyto(tvm.cpu()))
diff --git a/tests/python/relax/test_vm_instrument.py
b/tests/python/relax/test_vm_instrument.py
index 8297da1b74..6158542644 100644
--- a/tests/python/relax/test_vm_instrument.py
+++ b/tests/python/relax/test_vm_instrument.py
@@ -49,6 +49,21 @@ def get_exec(data_shape):
return relax.build(mod, target)
+def get_exec_int32(data_shape):
+ builder = relax.BlockBuilder()
+
+ with builder.function("main"):
+ model = nn.ReLU()
+ data = nn.Placeholder(data_shape, dtype="int32", name="data")
+ output = model(data)
+ params = [data] + model.parameters()
+ builder.emit_func_output(output, params=params)
+
+ mod = builder.get()
+ target = "llvm"
+ return relax.build(mod, target)
+
+
def test_conv2d_cpu():
data_np = np.random.randn(1, 64).astype("float32")
ex = get_exec(data_np.shape)
@@ -74,8 +89,8 @@ def test_conv2d_cpu():
def test_lib_comparator():
- data_np = np.random.randn(1, 64).astype("float32")
- ex = get_exec(data_np.shape)
+ data_np = np.random.randn(1, 64).astype("int32")
+ ex = get_exec_int32(data_np.shape)
vm = relax.VirtualMachine(ex, tvm.cpu())
# compare against library module
cmp = LibCompareVMInstrument(vm.module.imported_modules[0], tvm.cpu(),
verbose=False)