Commit fc28f7ab by Wei Chen Committed by Zhi

[Test][TF][Relay] Fix argument preparation for vm test mode (#4296)

parent 801cf0e8
...@@ -112,7 +112,15 @@ def run_tvm_graph(graph_def, input_data, input_node, num_output=1, ...@@ -112,7 +112,15 @@ def run_tvm_graph(graph_def, input_data, input_node, num_output=1,
ex = relay.create_executor(mode, mod=mod, ctx=tvm.cpu(), target="llvm") ex = relay.create_executor(mode, mod=mod, ctx=tvm.cpu(), target="llvm")
inputs = [] inputs = []
for param in mod['main'].params: for param in mod['main'].params:
inputs.append(tvm.nd.array(params[param.name_hint])) found = False
for i, n in enumerate(input_node):
if n == param.name_hint:
found = True
inputs.append(tvm.nd.array(input_data[i]))
break
# Interpreter doesn't bind constants, so still need to find in params
if not found:
inputs.append(tvm.nd.array(params[param.name_hint]))
result = ex.evaluate()(*inputs) result = ex.evaluate()(*inputs)
return vmobj_to_list(result) return vmobj_to_list(result)
else: else:
...@@ -2099,19 +2107,20 @@ def test_forward_floor(): ...@@ -2099,19 +2107,20 @@ def test_forward_floor():
def test_forward_relu(): def test_forward_relu():
ishape = (1, 3, 10, 10) ishape = (1, 3, 10, 10)
inp_array = np.random.uniform(-5, 5, size=ishape).astype(np.float32) inp_array = np.random.uniform(-5, 5, size=ishape).astype(np.float32)
with tf.Graph().as_default(): for mode in ['graph_runtime', 'vm']:
in1 = tf.placeholder(shape=inp_array.shape, dtype=inp_array.dtype) with tf.Graph().as_default():
tf.nn.relu(in1) in1 = tf.placeholder(shape=inp_array.shape, dtype=inp_array.dtype)
compare_tf_with_tvm(inp_array, 'Placeholder:0', 'Relu:0') tf.nn.relu(in1)
compare_tf_with_tvm(inp_array, 'Placeholder:0', 'Relu:0', mode=mode)
def test_forward_leaky_relu(): def test_forward_leaky_relu():
ishape = (1, 3, 10, 10) ishape = (1, 3, 10, 10)
inp_array = np.random.uniform(-5, 5, size=ishape).astype(np.float32) inp_array = np.random.uniform(-5, 5, size=ishape).astype(np.float32)
with tf.Graph().as_default(): for mode in ['graph_runtime', 'vm']:
in1 = tf.placeholder(shape=inp_array.shape, dtype=inp_array.dtype) with tf.Graph().as_default():
tf.nn.leaky_relu(in1, alpha=0.4) in1 = tf.placeholder(shape=inp_array.shape, dtype=inp_array.dtype)
compare_tf_with_tvm(inp_array, 'Placeholder:0', 'LeakyRelu:0') tf.nn.leaky_relu(in1, alpha=0.4)
compare_tf_with_tvm(inp_array, 'Placeholder:0', 'LeakyRelu:0', mode=mode)
def test_forward_elu(): def test_forward_elu():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment