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 2022/02/01 17:19:42 UTC

[GitHub] [tvm] michalpiszczek commented on a change in pull request #10087: [Relay][VM] Fix loading late bound consts when none exist

michalpiszczek commented on a change in pull request #10087:
URL: https://github.com/apache/tvm/pull/10087#discussion_r796824570



##########
File path: tests/python/relay/test_vm.py
##########
@@ -1174,6 +1174,68 @@ def test_large_constants():
     tvm.testing.assert_allclose(expected, actual.numpy())
 
 
+def test_load_late_bound_consts_with_no_late_bound_consts():
+    """Check that load_late_bound_consts handles a model with no late bound consts."""
+    target = tvm.target.Target("llvm")
+    dev = tvm.cpu()
+
+    const_data = np.random.rand(1).astype("float64")
+    x = relay.var("x", shape=(1,), dtype="float64")
+    const = relay.const(const_data, dtype="float64")
+
+    func = relay.Function([x], relay.op.add(x, const))
+    mod = tvm.IRModule.from_expr(func)
+
+    vm_exec = vm.compile(mod, target=target)
+
+    temp = utils.tempdir()
+    path_consts = temp.relpath("consts")
+    path_dso = temp.relpath("lib.so")
+
+    # Ensure const_data is below the byte threshold for a late-bound const.
+    byte_limit = len(const_data.tobytes()) + 1
+    vm_exec.move_late_bound_consts(path_consts, byte_limit=byte_limit)
+    vm_exec.mod.export_library(path_dso)
+
+    mod = runtime.load_module(path_dso)
+    mod["load_late_bound_consts"](path_consts)
+
+    x_data = np.random.rand(1).astype("float64")
+    loaded_vm = runtime.vm.VirtualMachine(mod, dev)
+    actual = loaded_vm.invoke("main", x_data)
+    expected = x_data + const_data
+    tvm.testing.assert_allclose(expected, actual.numpy())
+
+
+def test_vm_save_and_load_without_designating_late_bound_consts():
+    """Check that a VM can be saved and loaded without late-bound consts in play.
+
+    Specifically, this test ensures that the machinery behind late-bound const
+    loading does not assume the need to load late-bound consts (and cause an error)
+    when the user did not choose to designate any consts as such.

Review comment:
       This behavior was being implicitly tested by a test in `tests/python/contrib/test_verilator/test_verilator_ops.py`. I've added a case here to catch it as well, since it' a VM thing, and `tests/python/contrib/test_verilator/test_verilator_ops.py` does not run on all platforms anyways.




-- 
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