Skip to content

Commit

Permalink
Fix grad test
Browse files Browse the repository at this point in the history
  • Loading branch information
tkonolige committed Nov 6, 2020
1 parent eb40a5e commit d51a206
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions python/tvm/relay/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def check_grad(
break
grads = tmp

assert len(grads) > 0, "You must test at least one gradient."

# Get numeric gradients for each dimension of each param, using two-sided approximation.
approx_grads = []
for x in test_inputs:
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/topi/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def gen_ir(data_ptr, indices_ptr, out_ptr):
)
)
offset *= shape[l]
out[index] = data[i * fused_data_dimension + j]
out[index] += data[i * fused_data_dimension + j]

return ib.get()

Expand Down
4 changes: 2 additions & 2 deletions tests/python/relay/test_op_grad_level3.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def test_gather_nd_grad():
indices = relay.var("indices", relay.TensorType((2, 4), "int64"))
fwd = relay.Function([data, indices], relay.gather_nd(data, indices))
data_np = np.random.rand(2, 3).astype("float64")
indices_np = np.array([[0, 1, 1, 0], [0, 1, 2, 1]]).astype("int64")
check_grad(fwd, inputs=[data_np, indices_np], test_inputs=indices_np)
indices_np = np.array([[0, 1, 1, 0], [0, 1, 0, 0]], dtype="int64")
check_grad(fwd, inputs=[data_np, indices_np], test_inputs=[data_np])


if __name__ == "__main__":
Expand Down

0 comments on commit d51a206

Please sign in to comment.