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/05/12 23:45:50 UTC

[GitHub] [tvm] tqchen commented on a diff in pull request #11303: Fix json serialization for NDArray

tqchen commented on code in PR #11303:
URL: https://github.com/apache/tvm/pull/11303#discussion_r871896368


##########
tests/python/unittest/test_node_reflection.py:
##########
@@ -160,14 +162,35 @@ def test_dict():
     assert set(dir(x.__class__)) <= set(dir(x))
 
 
+def test_ndarray():
+    dev = tvm.cpu(0)
+    tvm_arr = tvm.nd.array(np.random.rand(4), device=dev)
+    tvm_arr2 = tvm.ir.load_json(tvm.ir.save_json(tvm_arr))
+    tvm.ir.assert_structural_equal(tvm_arr, tvm_arr2)
+    np.testing.assert_array_equal(tvm_arr.numpy(), tvm_arr2.numpy())
+
+
+def test_ndarray_dict():
+    dev = tvm.cpu(0)
+    m1 = {
+        "key1": tvm.nd.array(np.random.rand(4), device=dev),
+        "key2": tvm.nd.array(np.random.rand(4), device=dev),
+    }
+    m2 = tvm.ir.load_json(tvm.ir.save_json(m1))
+    tvm.ir.assert_structural_equal(m1, m2)
+
+
+def test_alloc_const():
+    dev = tvm.cpu(0)
+    dtype = "float32"
+    shape = (16,)
+    buf = tvm.tir.decl_buffer(shape, dtype)
+    data = tvm.nd.array(np.random.rand(*shape).astype(dtype), device=dev)
+    body = tvm.tir.Evaluate(0)
+    stmt = tvm.tir.AllocateConst(buf.data, dtype, shape, data, body)
+    stmt2 = tvm.ir.load_json(tvm.ir.save_json(stmt))

Review Comment:
   My read is that it does not go through `b64ndarray` mechanism, but instead goes through `repr_bytes` mechanism as @vinx13 commented. The old  `b64ndarray` mechanism should still continue to work. At some time pt perhaps we can move to  `repr_bytes`  mechanism for all cases while keeping  `b64ndarray`  for one cycle



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