emijiayw commented on a change in pull request #8426:
URL: https://github.com/apache/tvm/pull/8426#discussion_r668211743
##########
File path: tests/python/frontend/onnx/test_forward.py
##########
@@ -4872,6 +4872,66 @@ def test_qlinearadd():
verify_qlinearadd([5, 1, 7], [2, 7], [5, 2, 7])
+def get_random_uniform(shape, dtype="float32", high=1.0, low=0.0, seed=None,
target="llvm"):
+ ONNX_DTYPE = mapping.NP_TYPE_TO_TENSOR_TYPE[np.dtype(dtype)]
+ node = helper.make_node(
+ "RandomUniform", [], ["out"], shape=shape, dtype=ONNX_DTYPE,
high=high, low=low
+ )
+ if seed is not None:
+ seed_attr = helper.make_attribute("seed", seed)
+ node.attribute.append(seed_attr)
+
+ graph = helper.make_graph(
+ [node],
+ "random_uniform_test",
+ inputs=[],
+ outputs=[helper.make_tensor_value_info("out", ONNX_DTYPE, shape)],
+ )
+ model = helper.make_model(graph, producer_name="random_uniform_test")
+ return get_tvm_output_with_vm(model, [], target=target,
device=tvm.device(target, 0))
+
+
+def test_random_uniform():
+ targets = [tgt for (tgt, _) in tvm.testing.enabled_targets()]
+ for target in targets:
+ # Check that function runs and produces proper shape.
+ vals = get_random_uniform([10], dtype="float32", target=target)
+ assert list(vals.shape) == [10]
+ assert vals.dtype == "float32"
+
+ # Test N-D tensor generation.
+ vals = get_random_uniform([1, 3, 100, 100], dtype="float32",
target=target)
+ assert list(vals.shape) == [1, 3, 100, 100]
+
+ # Check that bounds aren't exceeded.
+ vals = get_random_uniform(shape=[100], high=100, low=-100)
+ assert list(vals.shape) == [100]
+ assert all(vals >= -100) and all(vals <= 100)
+
+ # Check that fixed seed produces the same values.
Review comment:
Check that if fixed seeds will produce the same values.
##########
File path: tests/python/frontend/onnx/test_forward.py
##########
@@ -4872,6 +4872,66 @@ def test_qlinearadd():
verify_qlinearadd([5, 1, 7], [2, 7], [5, 2, 7])
+def get_random_uniform(shape, dtype="float32", high=1.0, low=0.0, seed=None,
target="llvm"):
+ ONNX_DTYPE = mapping.NP_TYPE_TO_TENSOR_TYPE[np.dtype(dtype)]
+ node = helper.make_node(
+ "RandomUniform", [], ["out"], shape=shape, dtype=ONNX_DTYPE,
high=high, low=low
+ )
+ if seed is not None:
+ seed_attr = helper.make_attribute("seed", seed)
+ node.attribute.append(seed_attr)
+
+ graph = helper.make_graph(
+ [node],
+ "random_uniform_test",
+ inputs=[],
+ outputs=[helper.make_tensor_value_info("out", ONNX_DTYPE, shape)],
+ )
+ model = helper.make_model(graph, producer_name="random_uniform_test")
+ return get_tvm_output_with_vm(model, [], target=target,
device=tvm.device(target, 0))
+
+
+def test_random_uniform():
+ targets = [tgt for (tgt, _) in tvm.testing.enabled_targets()]
+ for target in targets:
+ # Check that function runs and produces proper shape.
+ vals = get_random_uniform([10], dtype="float32", target=target)
+ assert list(vals.shape) == [10]
+ assert vals.dtype == "float32"
+
+ # Test N-D tensor generation.
+ vals = get_random_uniform([1, 3, 100, 100], dtype="float32",
target=target)
+ assert list(vals.shape) == [1, 3, 100, 100]
+
+ # Check that bounds aren't exceeded.
+ vals = get_random_uniform(shape=[100], high=100, low=-100)
+ assert list(vals.shape) == [100]
+ assert all(vals >= -100) and all(vals <= 100)
+
+ # Check that fixed seed produces the same values.
Review comment:
Check that if the fixed seed will produce the same values.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]